Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / server / scsynth / CMakeLists.txt
blob5a7a48826fb96862c01cd8157181357a97a63412
1 find_package(Sndfile)
2 if (WIN32)
3         find_package(Portaudio)
4 endif()
6 # here we choose who provides us with the FFT lib
7 if (FFT_GREEN)
8         add_definitions("-DSC_FFT_GREEN")
9 elseif (APPLE)
10         add_definitions("-DSC_FFT_VDSP")
11 else()
12         find_package(FFTW3f 3.3)
14         if (FFTW3F_FOUND)
15                 add_definitions("-DSC_FFT_FFTW")
16         else()
17                 message(SEND_ERROR "Cannot find libfftw3f")
18         endif()
19 endif()
21 if(NOVA_SIMD)
22         add_definitions(-DNOVA_SIMD)
23 endif()
25 if (NO_AVAHI)
27 elseif (APPLE)
28         add_definitions(-DUSE_RENDEZVOUS=1)
29 else()
30         find_package(Avahi)
31         if (AVAHI_FOUND)
32                 add_definitions(-DUSE_RENDEZVOUS=1)
33         endif()
34 endif()
36 # Here we work out which audio API to use, from system type and/or user option.
37 if(AUDIOAPI STREQUAL "default")
38         if(APPLE)
39                 set(AUDIOAPI coreaudio)
40         elseif(WIN32)
41                 set(AUDIOAPI portaudio)
42         else()
43                 set(AUDIOAPI jack)
44         endif(APPLE)
45 endif()
47 if(NOT AUDIOAPI MATCHES "^(jack|coreaudio|portaudio)$")
48         message(WARNING "Unrecognised audio API: ${AUDIOAPI}")
49 endif()
51 if(AUDIOAPI STREQUAL jack)
52         find_package(Jack)
53         if(NOT JACK_FOUND)
54                 message(FATAL_ERROR "Jack selected as audio API, but development files not found")
55         endif()
56 elseif(AUDIOAPI STREQUAL portaudio)
57         find_package(Portaudio)
58         if(NOT PORTAUDIO_FOUND)
59                 message(FATAL_ERROR "Portaudio selected as audio API, but development files not found")
60         endif()
61 endif()
62 message(STATUS "Audio API: ${AUDIOAPI}")
64 set(scsynth_sources
65         Samp.cpp
66         SC_BufGen.cpp
67         SC_Carbon.cpp
69         SC_ComPort.cpp
70         SC_CoreAudio.cpp
71         SC_Errors.cpp
72         SC_Graph.cpp
73         SC_GraphDef.cpp
74         SC_Group.cpp
75         SC_Lib_Cintf.cpp
76         SC_Lib.cpp
77         SC_MiscCmds.cpp
78         SC_Node.cpp
79         SC_Rate.cpp
80         SC_SequencedCommand.cpp
81         SC_Str4.cpp
82         SC_Unit.cpp
83         SC_UnitDef.cpp
84         SC_World.cpp
85         Rendezvous.cpp
87         ${CMAKE_SOURCE_DIR}/common/SC_fftlib.cpp
88         ${CMAKE_SOURCE_DIR}/common/SC_AllocPool.cpp
89         ${CMAKE_SOURCE_DIR}/common/SC_DirUtils.cpp
90         ${CMAKE_SOURCE_DIR}/common/SC_Reply.cpp
91         ${CMAKE_SOURCE_DIR}/common/SC_Sem.cpp
92         ${CMAKE_SOURCE_DIR}/common/SC_StandAloneInfo_Darwin.cpp
93         ${CMAKE_SOURCE_DIR}/common/SC_StringBuffer.cpp
94         ${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
95         ${CMAKE_SOURCE_DIR}/common/scsynthsend.cpp
96         ${CMAKE_SOURCE_DIR}/common/sc_popen.cpp
98         ${CMAKE_SOURCE_DIR}/external_libraries/TLSF-2.4.6/src/tlsf.c
101 if(WIN32)
102     list(APPEND scsynth_sources ${CMAKE_SOURCE_DIR}/common/SC_Win32Utils.cpp)
103 endif()
105 if (FFT_GREEN)
106         list(APPEND scsynth_sources ../../common/fftlib.c)
107 endif()
109 if (FFTW3F_FOUND)
110         include_directories (${FFTW3F_INCLUDE_DIR})
111 endif()
114 include_directories(${CMAKE_SOURCE_DIR}/include/common
115                     ${CMAKE_SOURCE_DIR}/common
116                     ${CMAKE_SOURCE_DIR}/include/server
117                     ${CMAKE_SOURCE_DIR}/include/plugin_interface)
119 include_directories (${CMAKE_SOURCE_DIR}/external_libraries/TLSF-2.4.6/src)
121 set_property(DIRECTORY
122              APPEND
123              PROPERTY COMPILE_DEFINITIONS SC_MEMORY_ALIGNMENT=32)
125 if (AUDIOAPI STREQUAL jack)
126         list(APPEND scsynth_sources SC_Jack.cpp)
127         add_definitions("-DSC_AUDIO_API=SC_AUDIO_API_JACK" ${JACK_DEFINITIONS})
128         include_directories(${JACK_INCLUDE_DIRS})
129 elseif (AUDIOAPI STREQUAL portaudio)
130         add_definitions("-DSC_AUDIO_API=SC_AUDIO_API_PORTAUDIO" ${PORTAUDIO_DEFINITIONS})
131         include_directories(${PORTAUDIO_INCLUDE_DIRS})
132 endif()
134 set (FINAL_BUILD 0) # disable final build for scsynth
136 if (LIBSCSYNTH)
137         set (LIBSCSYNTH_TYPE SHARED)
138 else()
139         set (LIBSCSYNTH_TYPE STATIC)
140 endif()
142 if (FINAL_BUILD)
143         CREATE_FINAL_FILE(libscsynth_final.cpp ${scsynth_sources})
144         add_library(libscsynth ${LIBSCSYNTH_TYPE} libscsynth_final.cpp)
145 else()
146         add_library(libscsynth ${LIBSCSYNTH_TYPE} ${scsynth_sources})
147 endif()
149 set_property(TARGET libscsynth
150         APPEND
151         PROPERTY COMPILE_DEFINITIONS BUILDING_SUPERCOLLIDER)
153 find_library(DL NAMES dl)
154 if (DL)
155     target_link_libraries(libscsynth ${DL})
156 endif()
158 if(AVAHI_FOUND)
159         add_definitions("-DHAVE_AVAHI=1")
160         include_directories(${AVAHI_INCLUDE_DIRS})
161         target_link_libraries(libscsynth ${AVAHI_LIBRARIES})
162 endif()
164 if(SNDFILE_FOUND)
165         include_directories(${SNDFILE_INCLUDE_DIR})
166         target_link_libraries(libscsynth ${SNDFILE_LIBRARIES})
167 elseif(NOT NO_LIBSNDFILE)
168         message(SEND_ERROR "Cannot find libsndfile")
169 endif(SNDFILE_FOUND)
171 if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
172         add_definitions(-DSC_PLUGIN_DIR="${CMAKE_INSTALL_PREFIX}/lib/SuperCollider/plugins")
173 endif()
175 if (AUDIOAPI STREQUAL jack)
176         target_link_libraries(libscsynth ${JACK_LIBRARIES})
177 elseif(AUDIOAPI STREQUAL portaudio)
178         target_link_libraries(libscsynth ${PORTAUDIO_LIBRARIES})
179 elseif(AUDIOAPI STREQUAL coreaudio)
180         target_link_libraries(libscsynth "-framework CoreAudio")
181 endif()
183 if(PTHREADS_FOUND)
184         target_link_libraries(libscsynth ${PTHREADS_LIBRARIES})
185 endif()
188 if (WIN32)
189         target_link_libraries(libscsynth wsock32 ws2_32 winmm)
190 endif()
193 set_property(TARGET libscsynth PROPERTY OUTPUT_NAME scsynth)
195 if (LIBSCSYNTH)
196         # These two properties are ABI version info, not sc version:
197         set_property(TARGET libscsynth PROPERTY VERSION     1.0.0)
198         set_property(TARGET libscsynth PROPERTY SOVERSION   1)
199 endif()
201 if (FFTW3F_FOUND)
202         target_link_libraries(libscsynth ${FFTW3F_LIBRARY})
203 endif()
205 if (APPLE)
206         target_link_libraries(libscsynth "-framework vecLib -framework CoreServices")
207 endif()
209 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
210         target_link_libraries(libscsynth rt)
211 endif()
213 file(GLOB_RECURSE all_headers ../../*hpp)
215 add_executable(scsynth scsynth_main.cpp ${all_headers})
216 target_link_libraries(scsynth libscsynth ${PTHREADS_LIBRARY})
218 if(LTO)
219     set_property(TARGET scsynth libscsynth
220                  APPEND PROPERTY COMPILE_FLAGS "-flto -flto-report")
222     set_property(TARGET scsynth
223                  APPEND PROPERTY LINK_FLAGS "-flto -flto-report -fwhole-program")
225     set_property(TARGET libscsynth
226                  APPEND PROPERTY LINK_FLAGS "-flto -flto-report")
227 endif()
229 if (LIBSCSYNTH)
230         set(INSTALL_TARGETS scsynth libscsynth)
231 else()
232         set(INSTALL_TARGETS scsynth)
233 endif()
235 if(APPLE)
236         # TODO allow apple users to install to fhs-ish path if INSTALL_FHS option is enabled
237         # determines the app name and app install location (scappbundlename, scappdir):
238         include (${CMAKE_SOURCE_DIR}/cmake_modules/MacAppFolder.cmake)
239         install(TARGETS ${INSTALL_TARGETS}
240                         RUNTIME DESTINATION "${scappauxresourcesdir}"
241                         LIBRARY DESTINATION "${scappauxresourcesdir}"
242                         PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE OWNER_WRITE)
243 elseif(WIN32)
244         install(TARGETS ${INSTALL_TARGETS}
245                         DESTINATION "SuperCollider"
246                         PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
247 else()
248         install(TARGETS ${INSTALL_TARGETS}
249                         RUNTIME DESTINATION "bin"
250                         LIBRARY DESTINATION "lib"
251                         PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
252 endif()