-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
144 lines (119 loc) · 3.94 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.1)
if(NOT WIN32)
# do not use clang on Windows,
# will use MSVC anyway with default Visual Studio generator, even if clang is specified
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
endif()
if(NOT WIN32)
# mmap not supported for Windows
set(USE_MMAP TRUE)
endif()
project(AudacityNoiseReduction VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler-specific extensions
if(MSVC)
# for MSVC, only warning level 3, is much too verbose with -Wall
add_compile_options(-W3)
else()
add_compile_options(-Wall)
endif()
if(WIN32)
# default installation dir for libsndfile on Windows
set(LIBSNDFILE_DIR "C:\\Program Files\\Mega-Nerd\\libsndfile")
endif()
# Need to copy dll file to build directory on Windows
if(WIN32)
if(MSVC)
# MSVC creates separate Debug directory, not sure about other compilers on Windows
file(COPY "${LIBSNDFILE_DIR}\\bin\\libsndfile-1.dll" DESTINATION ".\\Debug")
else()
file(COPY "${LIBSNDFILE_DIR}\\bin\\libsndfile-1.dll" DESTINATION ".")
endif()
endif()
################################################################################
# Create core library
set(CORE_SRC_FILES
noisereduction/NoiseReduction.cpp
noisereduction/InputTrack.cpp
noisereduction/OutputTrack.cpp
noisereduction/TrackUtils.cpp
noisereduction/RealFFTf.cpp
noisereduction/Extensions.cpp
)
if(USE_MMAP)
list(APPEND CORE_SRC_FILES noisereduction/SndMmap.cpp)
endif()
# Add headers as well so they are listed in Visual Studio
set(CORE_HEADER_FILES
noisereduction/NoiseReduction.h
noisereduction/InputTrack.h
noisereduction/OutputTrack.h
noisereduction/TrackUtils.h
noisereduction/SndContext.h
noisereduction/RealFFTf.h
noisereduction/Types.h
noisereduction/MemoryX.h
noisereduction/cxxopts.hpp
noisereduction/loguru.hpp
)
if(USE_MMAP)
list(APPEND CORE_HEADER_FILES noisereduction/SndMmap.h)
endif()
add_library(noisereduction_core STATIC ${CORE_SRC_FILES} ${CORE_HEADER_FILES})
if(USE_MMAP)
target_compile_definitions(noisereduction_core PUBLIC USE_MMAP)
endif()
find_package(Threads REQUIRED)
if(WIN32)
# on Windows, need full name of library and path hint to find it
find_library(LIBSNDFILE_LIBRARY libsndfile-1 REQUIRED
HINTS "${LIBSNDFILE_DIR}\\lib"
)
else()
find_library(LIBSNDFILE_LIBRARY sndfile REQUIRED)
endif()
set(CORE_LIBRARIES
Threads::Threads
${LIBSNDFILE_LIBRARY}
)
if(NOT WIN32)
# do not need dl library on Windows
find_library(DL_LIBRARY dl REQUIRED)
list(APPEND CORE_LIBRARIES ${DL_LIBRARY})
endif()
if(WIN32)
# must add include dir on Windows
target_include_directories(noisereduction_core PUBLIC "${LIBSNDFILE_DIR}\\include")
endif()
if (APPLE)
target_include_directories(noisereduction_core PUBLIC /opt/homebrew/include)
target_link_directories(noisereduction_core PUBLIC /opt/homebrew/lib)
endif()
target_link_libraries(noisereduction_core PUBLIC ${CORE_LIBRARIES})
################################################################################
# Create driver executable
add_executable(noisereduction_driver noisereduction/main.cpp)
target_link_libraries(noisereduction_driver PRIVATE noisereduction_core)
################################################################################
# Create test executable
set(TEST_SRC_FILES
noisereduction/tests/test_main.cpp
noisereduction/tests/test_audacity.cpp
)
if(USE_MMAP)
list(APPEND TEST_SRC_FILES noisereduction/tests/test_mmap_snd.cpp)
endif()
# Add headers as well so they are listed in Visual Studio
set(TEST_HEADER_FILES
noisereduction/tests/catch.hpp
)
add_executable(test_runner ${TEST_SRC_FILES} ${TEST_HEADER_FILES})
# Define samples directory relative to executable
if(MSVC)
# two levels up because MSVC puts exe under build/Debug
target_compile_definitions(test_runner PRIVATE SAMPLES_DIR="../../samples")
else()
target_compile_definitions(test_runner PRIVATE SAMPLES_DIR="../samples")
endif()
target_link_libraries(test_runner PRIVATE noisereduction_core)