-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCMakeLists.txt
343 lines (302 loc) · 12.1 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
cmake_minimum_required(VERSION 3.5)
project(RTOSC)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 3)
set(VERSION_PATCH 1)
SET(CMAKE_CXX_STANDARD 17)
#Find Packages
find_package(Doxygen)
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(FLTK)
mark_as_advanced(FLTK_CONFIG_SCRIPT FLTK_DIR FLTK_FLUID_EXECUTABLE
FLTK_INCLUDE_DIR FLTK_MATH_LIBRARY)
if(FLTK_FOUND)
execute_process(COMMAND fltk-config --api-version
OUTPUT_VARIABLE FLTK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if((FLTK_VERSION STREQUAL "1.3"))
set(GUI_FOUND TRUE)
else()
set(GUI_FOUND FALSE)
endif()
else()
set(GUI_FOUND FALSE)
endif(FLTK_FOUND)
if(MSVC)
find_package(liblo)
if(liblo_FOUND)
set(LIBLO_FOUND TRUE)
endif()
else()
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBLO liblo>=0.28)
if(NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Windows"))
pkg_check_modules(JACK jack)
endif()
endif()
endif()
find_package(Ruby 1.8)
find_program(RTOSC_IWYU_PATH NAMES include-what-you-use iwyu)
#User Configuration
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
option(RTOSC_INCLUDE_WHAT_YOU_USE "Check for useless includes" OFF)
mark_as_advanced(FORCE RTOSC_INCLUDE_WHAT_YOU_USE)
option(RTOSC_WERROR "Compile with warnings being treated as errors" OFF)
set(BUILD_RTOSC_EXAMPLES FALSE CACHE BOOL
"Build RTOSC Example Programs")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
include(GNUInstallDirs)
endif()
set(POSITION_INDEPENDENT_CODE ON)
#Ignore the type narrowing conversion warnings
set(MSVC_CNV_WARN "/wd4244 /wd4267 /wd4305")
#Ignore the whole non-portable string*_s function recommendations
set(MSVC_SAFE_WARN "/wd4996")
if(RTOSC_WERROR)
if(MSVC)
set(WERROR_FLAG "/WX")
else()
set(WERROR_FLAG "-Werror")
endif(MSVC)
endif()
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSVC_CNV_WARN} ${MSVC_SAFE_WARN} ${WERROR_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_CNV_WARN} ${MSVC_SAFE_WARN} ${WERROR_FLAG}")
else()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wno-vla-cxx-extension HAVE_W_NO_VLA_CXX_EXTENSION)
if(HAVE_W_NO_VLA_CXX_EXTENSION)
set(VLA_DISABLE -Wno-vla-cxx-extension)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra ${WERROR_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ${VLA_DISABLE} ${WERROR_FLAG}")
endif(MSVC)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/version.c.in
${CMAKE_CURRENT_BINARY_DIR}/cpp/version.c)
add_library(rtosc SHARED STATIC
src/rtosc.c
src/dispatch.c
src/rtosc-time.c)
add_library(rtosc-cpp SHARED STATIC
${CMAKE_CURRENT_BINARY_DIR}/cpp/version.c
src/cpp/ports.cpp src/cpp/ports-runtime.cpp
src/cpp/default-value.cpp src/cpp/savefile.cpp src/cpp/port-checker.cpp
src/cpp/pretty-format.c
src/cpp/arg-ext.c
src/cpp/arg-val.c
src/cpp/arg-val-math.c src/cpp/arg-val-cmp.c src/cpp/arg-val-itr.c
src/cpp/util.c
src/cpp/miditable.cpp
src/cpp/automations.cpp
src/cpp/midimapper.cpp
src/cpp/thread-link.cpp
src/cpp/undo-history.cpp
src/cpp/subtree-serialize.cpp)
target_link_libraries(rtosc-cpp PUBLIC rtosc)
target_compile_features(rtosc-cpp PUBLIC cxx_std_11)
target_include_directories(rtosc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_options(rtosc PRIVATE
"$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-std=c99>")
set_target_properties(rtosc PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(rtosc-cpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(RTOSC_IWYU_PATH AND RTOSC_INCLUDE_WHAT_YOU_USE)
set(RTOSC_IWYU_PATH_AND_OPTIONS
${RTOSC_IWYU_PATH}
-Xiwyu
--no_comments)
set_property(TARGET rtosc
PROPERTY C_INCLUDE_WHAT_YOU_USE
${RTOSC_IWYU_PATH_AND_OPTIONS})
set_property(TARGET rtosc-cpp
PROPERTY CXX_INCLUDE_WHAT_YOU_USE
${RTOSC_IWYU_PATH_AND_OPTIONS})
endif()
# Example Code
if(JACK_FOUND AND GUI_FOUND AND BUILD_RTOSC_EXAMPLES)
add_executable(simple-example
example/simple/ui.cpp example/simple/synth.cpp)
target_link_libraries(simple-example PRIVATE
m rtosc ${FLTK_LIBRARIES} ${JACK_LDFLAGS})
add_executable(complex-example example/complex/audio.cpp
example/complex/synth.cpp example/complex/window.cpp
example/complex/Fl_Osc_Dial.cpp example/complex/Fl_Osc_Slider.cpp
example/complex/Fl_Osc_Button.cpp)
target_link_libraries(complex-example PRIVATE
m rtosc-cpp ${FLTK_LIBRARIES} ${JACK_LDFLAGS})
#TODO add complex example (ie klatter (an unplublished project for those reading))
endif()
if(BUILD_RTOSC_EXAMPLES)
add_executable(modular-example
example/modular/Echo.cpp
example/modular/EffectMgr.cpp
example/modular/LFO.cpp
example/modular/main.cpp
example/modular/Oscil.cpp
example/modular/Synth.cpp
example/modular/util.cpp)
target_link_libraries(modular-example m rtosc-cpp)
target_include_directories(modular-example PRIVATE ${JACK_INCLUDE_DIRS})
endif(BUILD_RTOSC_EXAMPLES)
# Testing Code
enable_testing()
macro(maketest fname)
add_executable(${fname} test/${fname}.c)
add_test(${fname} ${fname})
target_link_libraries(${fname} PRIVATE rtosc)
target_compile_options(${fname} PRIVATE
"$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-std=c99>")
#add_test(memcheck_${fname} valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 ./${fname})
endmacro(maketest)
macro(maketestcpp fname)
add_executable(${fname} test/${fname}.cpp)
add_test(${fname} ${fname})
target_link_libraries(${fname} PRIVATE rtosc-cpp rtosc)
#add_test(memcheck_${fname} valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 ./${fname})
endmacro(maketestcpp)
if(PKG_CONFIG_FOUND)
# Typical case on Linux and MacOS
set(RTOSC_LIBLO_LIBRARIES "${LIBLO_LIBRARIES}")
else()
# Currently solely supported on Windows
set(RTOSC_LIBLO_LIBRARIES "liblo::liblo")
endif()
maketest(rtosc-time)
maketest(osc-spec)
maketest(simple-messages)
maketest(null-messages)
maketest(bundles)
maketest(patterns)
maketest(nested-bundles)
maketest(fat-message)
maketest(empty-strings)
maketest(message-alignment)
maketest(test-arg-iter)
if(LIBLO_FOUND)
maketest(liblo)
target_include_directories(liblo PRIVATE ${LIBLO_INCLUDE_DIRS})
target_link_libraries(liblo PRIVATE ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(liblo PRIVATE ${LIBLO_LIBRARY_DIRS})
endif()
maketestcpp(version)
maketestcpp(util)
maketestcpp(arg-val-cmp)
maketestcpp(arg-val-math)
maketestcpp(thread-link-test)
maketestcpp(test-midi-mapper)
maketestcpp(metadata)
maketestcpp(apropos)
maketestcpp(pretty-format)
maketestcpp(default-value)
maketestcpp(headerlib)
maketestcpp(test-walker)
maketestcpp(walk-ports)
maketestcpp(path-search)
maketestcpp(performance)
if(LIBLO_FOUND)
target_include_directories(performance PRIVATE ${LIBLO_INCLUDE_DIRS})
target_compile_definitions(performance PRIVATE HAVE_LIBLO)
target_link_libraries(performance PRIVATE ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(performance PRIVATE ${LIBLO_LIBRARY_DIRS})
endif()
maketestcpp(undo-test)
maketestcpp(sugar)
if(NOT MSVC)
maketestcpp(typed-template-test)
endif()
maketestcpp(path-collapse)
maketestcpp(test-automation)
if(LIBLO_FOUND)
add_library(lo-server test/liblo-server.cpp)
target_include_directories(lo-server PRIVATE ${LIBLO_INCLUDE_DIRS})
target_include_directories(lo-server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(lo-server PRIVATE ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(performance PRIVATE ${LIBLO_LIBRARY_DIRS})
set(RTOSC_TEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test CACHE INTERNAL "")
set(RTOSC_TEST_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
endif()
if(LIBLO_FOUND AND RUBY_FOUND)
add_executable(port-checker test/port-checker-main.cpp)
target_include_directories(port-checker PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(port-checker PRIVATE lo-server rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(port-checker PRIVATE ${LIBLO_LIBRARY_DIRS})
add_executable(port-checker-tester test/port-checker-tester.cpp)
target_include_directories(port-checker-tester PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(port-checker-tester PRIVATE lo-server rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(port-checker-tester PRIVATE ${LIBLO_LIBRARY_DIRS})
add_executable(port-checker-testapp test/port-checker-testapp.cpp)
target_include_directories(port-checker-testapp PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(port-checker-testapp PRIVATE rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES})
target_link_directories(port-checker-testapp PRIVATE ${LIBLO_LIBRARY_DIRS})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/test-port-checker.rb
${CMAKE_CURRENT_BINARY_DIR}/test-port-checker.rb COPYONLY)
add_test(test-port-checker test-port-checker.rb)
endif()
# Documentation
if(DOXYGEN_FOUND)
# configuration variables
set(CMAKE_DOXYGEN_INPUT_LIST ${CMAKE_CURRENT_SOURCE_DIR}/include/rtosc/)
set(DOXYGEN_OUTPUT_DIR html)
configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
add_custom_command(OUTPUT ${DOXYGEN_OUTPUT_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
DEPENDS rtosc-cpp ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
add_custom_target(rtosc-doc DEPENDS html)
endif()
#Installation
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT DEFINED RTOSC_NO_INSTALL)
if(PKG_CONFIG_FOUND)
configure_file(librtosc.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/librtosc.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtosc.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
configure_file(librtosc-cpp.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/librtosc-cpp.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtosc-cpp.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endif()
install(FILES include/rtosc/rtosc.h
include/rtosc/arg-val-cmp.h
include/rtosc/arg-val-math.h
include/rtosc/automations.h
include/rtosc/bundle-foreach.h
include/rtosc/default-value.h
include/rtosc/miditable.h
include/rtosc/port-checker.h
include/rtosc/port-sugar.h
include/rtosc/ports-runtime.h
include/rtosc/ports.h
include/rtosc/pretty-format.h
include/rtosc/rtosc-time.h
include/rtosc/rtosc-version.h
include/rtosc/savefile.h
include/rtosc/subtree-serialize.h
include/rtosc/thread-link.h
include/rtosc/typed-message.h
include/rtosc/typestring.hh
include/rtosc/undo-history.h
DESTINATION include/rtosc)
install(TARGETS rtosc rtosc-cpp
DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
#Describe Overall Configuration
include("cmake/ColorMessage.cmake")
message(STATUS)
message(STATUS "${ColorBold}Rtosc Build Configuration")
message(STATUS "=========================${ColorReset}")
message(STATUS)
package_status(PKG_CONFIG_FOUND "PkgConfig " "found" ${Yellow})
package_status(LIBLO_FOUND "Liblo " "enabled" ${Yellow})
package_status(JACK_FOUND "jack " "enabled" ${Yellow})
package_status(GUI_FOUND "FLTK " "enabled" ${Yellow})
package_status(BUILD_RTOSC_EXAMPLES "Examples " "enabled" ${Yellow})
package_status(RTOSC_IWYU_PATH "IWYU " "found" ${Yellow})
package_status(RTOSC_INCLUDE_WHAT_YOU_USE "IWYU " "enabled" ${Yellow})
message(STATUS "Build C flags: ${CMAKE_C_FLAGS}")
message(STATUS "Build C++ flags: ${CMAKE_CXX_FLAGS}")