class library: SynthDesc - gui fix
[supercollider.git] / CMakeLists.txt
blobfe780e95e2f7bb6c2a221d9aa8902ff5bb2c85a1
1 cmake_minimum_required (VERSION 2.8)
2 project (SuperCollider)
4 include(CTest)
5 enable_testing()
7 include (cmake_modules/FinalFile.cmake)
9 if (NOT CMAKE_BUILD_TYPE)
10         message(STATUS "Build type defaulting to \"Release\"")
11         set(CMAKE_BUILD_TYPE "Release")
12 endif()
14 if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
15         message(WARNING "WARNING: IN-PLACE BUILDS ARE NOT RECOMMENDED - PLEASE USE A BUILD DIRECTORY")
16 endif()
19 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
20                       ${CMAKE_MODULE_PATH})
22 CONFIGURE_FILE(
23   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/cmake_uninstall.cmake.in"
24   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
25   IMMEDIATE @ONLY)
27 ADD_CUSTOM_TARGET(uninstall
28   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
30 if(NOT WIN32)
31         ADD_CUSTOM_TARGET(setMainVersion ALL
32                 sh ${CMAKE_CURRENT_SOURCE_DIR}/setMainVersion.sh
33                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34                 VERBATIM
35                 )
36 endif()
38 if(APPLE)
39         STRING(REGEX REPLACE "^.*MacOSX10.([0-9]+).*$" "\\1" MAC_OSX_SDK_VERSION  "${CMAKE_OSX_SYSROOT}")
41         if(CMAKE_OSX_DEPLOYMENT_TARGET)
42                 if (CMAKE_OSX_DEPLOYMENT_TARGET GREATER 10.4)
43                         set(HID_UTIL_DIR "HID_Utilities")
44                 else()
45                         set(HID_UTIL_DIR "HID_Utilities_10_4")
46                 endif()
47         else()
48                 if (${MAC_OSX_SDK_VERSION} GREATER 4)
49                         set(HID_UTIL_DIR "HID_Utilities")
50                 else()
51                         set(HID_UTIL_DIR "HID_Utilities_10_4")
52                 endif()
53         endif()
54         MESSAGE( STATUS "Using HID Utilities from folder '${HID_UTIL_DIR}'")
55 endif()
57 if (CMAKE_SYSTEM_NAME MATCHES "Linux")
58         set(LINUX 1)
59 endif()
61 #############################################
62 # Compiler flags etc
64 if (${CMAKE_COMPILER_IS_GNUCXX})
65         exec_program(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE _gcc_version)
67         add_definitions("-fschedule-insns2" "-fomit-frame-pointer")
69         add_definitions("-Wreturn-type")
71 #       disabled for now: -ffast-math breaks avx intrinsics and -fsigned-zeros/-fno-associative-math are not available in some versions
72 #       if (${_gcc_version} VERSION_GREATER 4.0.99)
73 #               add_definitions("-ffast-math -fsigned-zeros -fno-associative-math")
74 #       endif()
76         option(DSO_VISIBILITY "DSO visibility support for gcc" OFF)
78         if (DSO_VISIBILITY)
79                 add_definitions(-fvisibility=hidden)
80         endif()
82         if(APPLE)
83                 exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
84                 if ("${_gcc_version_info}" MATCHES "Apple")
85                         add_definitions("-fpascal-strings")
86                 endif()
87                 add_definitions("-D_REENTRANT")
88         elseif(NOT (WIN32 AND NOT CYGWIN))
89                 add_definitions("-pthread")
90         endif()
91 endif ()
93 if (${CMAKE_CXX_COMPILER} MATCHES icpc)
94         set(CMAKE_COMPILER_IS_INTEL 1)
95         add_definitions(-Wno-unknown-pragmas)
96         add_definitions(-simd)
97 endif()
99 if (${CMAKE_CXX_COMPILER} MATCHES clang)
100         set(CMAKE_COMPILER_IS_CLANG 1)
101 endif()
103 if(APPLE)
104         set_property(DIRECTORY
105                 APPEND
106                 PROPERTY COMPILE_DEFINITIONS SC_DARWIN)
107 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
108         add_definitions("-DSC_LINUX")
109         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
110 elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
111         add_definitions("-DSC_FREEBSD")
112         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
113 endif()
115 if(WIN32)
116     set_property(DIRECTORY
117                  APPEND
118                  PROPERTY COMPILE_DEFINITIONS SC_WIN32 NOMINMAX _WINSOCKAPI_)
120     if(MSVC)
121         SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} /MTd")
122         SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} /MT")
123     endif()
124 endif()
127 #############################################
128 # some default libraries
130 find_package(Pthreads)
132 if (NOT PTHREADS_FOUND)
133     message(SEND_ERROR "cannot find libpthreads")
134 endif()
135 include_directories(${PTHREADS_INCLUDE_DIR})
137 if (MSVC OR MINGW)
138     set(MATH_LIBRARY "")
139 else()
140     find_library(MATH_LIBRARY m)
141 endif()
143 if(CURL)
144         find_package(CURL)
145         if(CURL_FOUND)
146                 add_definitions("-DHAVE_LIBCURL")
147                 include_directories(${CURL_INCLUDE_DIRS})
148         endif()
149 endif()
151 #############################################
152 # Options
153 option(NOVA_SIMD "Build with nova-simd support." ON)
154 option(FINAL_BUILD "Build as single source file." OFF)
156 option(CURL "Build with curl for remote file download." ON)
158 option(FFT_GREEN "Use internal 'Green' FFT lib rather than FFTW. (Not recommended.)" OFF)
160 option(SSE "Compile with support for SSE instructions.")
161 option(SSE41 "Compile with support for SSE4.1 instructions.")
162 option(SSE42 "Compile with support for SSE4.2 instructions.")
165 option(INSTALL_HELP "Install help docs and examples along with the software" ON)
166 option(INSTALL_OLD_HELP "Install old and deprecated help files" ON)
167 option(SC_DOC_RENDER "Pre-render SCDoc documentation. (For putting online, etc)" OFF)
169 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
170     option(SUPERNOVA "Build with supernova as optional audio synthesis server" ON)
171 elseif()
172     option(SUPERNOVA "Build with supernova as optional audio synthesis server" OFF)
173 endif()
175 option(SN_MEMORY_DEBUGGING "Build supernova for memory debugging (disable memory pools).")
176 option(SC_MEMORY_DEBUGGING "Build sclang&scsynth for memory debugging (disable memory pools).")
177 option(GC_SANITYCHECK "Enable sanity checks in the sclang garbage collector.")
179 option(NO_LIBSNDFILE "Disable soundfile functionality. (Not recommended.)" OFF)
181 option(NO_AVAHI "Disable Avahi support. (Not recommended.)" OFF)
183 if(NOT WIN32)
184         option(SCLANG_SERVER "Build with internal server." ON)
185 endif()
187 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
188         option(SC_WII "Build sclang with WII support" ON)
189 endif()
191 option(SC_QT "Build SuperCollider with Qt GUI" ON)
192 if (SC_QT)
193   message( STATUS "Compiling with Qt GUI" )
194 endif (SC_QT)
196 if(WIN32)
197         option(SC_PSYCOLLIDER "Build PsyCollider" ON)
198 else()
199         option(SC_PSYCOLLIDER "Build PsyCollider" OFF)
200 endif()
202 if(CMAKE_COMPILER_IS_GNUCXX)
203     option(NATIVE "Optimize binary for this architecture (binaries may not run on other machines, requires gcc-4.3 or higher).")
204     option(LTO "Use GCC's link time optimizer' (experimental).")
205 endif()
207 option(SC_SYMLINK_CLASSLIB "Place a symlink of SCCLassLibrary instead of copying" OFF)
208 option(SC_OX "Try to compile with support for C++0x (experimental, mainly related to supernova)" OFF)
210 #############################################
211 # some preprocessor flags
212 if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
213         if (SSE)
214                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -mfpmath=sse")
215                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -mfpmath=sse")
216         endif()
217         if (SSE41)
218                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
219                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
220         endif()
221         if (SSE42)
222                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
223                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
224         endif()
225         if (NATIVE)
226                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
227                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
228         endif()
230         if (SC_OX)
231                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
232         endif()
233 endif()
235 if (CMAKE_COMPILER_IS_INTEL AND NOT WIN32)
236         if (SSE42)
237                 add_definitions(-xSSE4.2)
238         elseif (SSE41)
239                 add_definitions(-xSSE4.1)
240         elseif (SSE)
241                 add_definitions(-mia32)
242         endif()
243         if (SC_OX)
244                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
245         endif()
247         # disable warnings
248         add_definitions(-diag-disable 170) # pointer points outside of underlying object ... used heavily in sclang
249         add_definitions(-diag-disable 279) # controlling expression is constant
251 endif()
253 if (SC_MEMORY_DEBUGGING)
254         add_definitions(-DDISABLE_MEMORY_POOLS)
255 endif()
257 #############################################
258 # subdirectories
259 add_subdirectory(external_libraries)
260 add_subdirectory(server)
261 add_subdirectory(lang)
262 add_subdirectory(bindings)
263 add_subdirectory(platform)
264 add_subdirectory(editors)
266 if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
267     install(DIRECTORY include/common include/plugin_interface include/server include/lang
268         DESTINATION ${CMAKE_INSTALL_PREFIX}/include/SuperCollider
269         FILES_MATCHING PATTERN "*.h"
270     )
271 endif()
273 if(APPLE)
274         # determines the app name and app install location (scappbundlename, scappdir):
275         include (cmake_modules/MacAppFolder.cmake)
277         set(auxresourcesdir ${scappauxresourcesdir})
279         # Some aux files which go in the app's folder
280         install(FILES README.txt ChangeLog
281                 DESTINATION ${auxresourcesdir}
282         )
283         install(FILES COPYING AUTHORS
284                 DESTINATION ${scappdir}
285         )
286 elseif (WIN32)
287         set(auxresourcesdir "SuperCollider")
288 else()
289         set(auxresourcesdir "share/SuperCollider")
290 endif()
292 if(NOT SC_QT)
293         set(SCCLASSLIB_EXCLUDE_REGEX "QtCollider")
294 else()
295         set(SCCLASSLIB_EXCLUDE_REGEX "IGNOREME")
296 endif()
298 if(APPLE)
299         #if directory contains symlinks, unlink them.
300         if(EXISTS "${auxresourcesdir}/SCClassLibrary")
301                 file(GLOB classlibraryfolders "${auxresourcesdir}/SCClassLibrary/[^.]*")
302                 foreach(onedirectory ${classlibraryfolders})
303                         if(IS_SYMLINK "${onedirectory}")
304                                 install( CODE "EXECUTE_PROCESS(COMMAND unlink ${onedirectory} )" )
305                         endif()
306                 endforeach(onedirectory)
307         endif()
309         if(SC_SYMLINK_CLASSLIB)
311                 #if there are folders inside SCCLassLibrary abort cmake.
312                 file(GLOB classlibraryfolders "${auxresourcesdir}/SCClassLibrary/[^.]*")
313                 foreach(onedirectory ${classlibraryfolders})
314                         if(NOT IS_SYMLINK "${onedirectory}")
315                                 message(FATAL_ERROR "Symlinking will fail ! SCClassLibrary folder already exists and has directories inside, please delete it first." )
316                         endif()
317                 endforeach(onedirectory)
319                 message(STATUS "Will create symlink of SCClassLibrary to ${auxresourcesdir}/SCClassLibrary" )
320                 if(NOT EXISTS "${auxresourcesdir}/SCClassLibrary")
321                         install( CODE "EXECUTE_PROCESS(COMMAND mkdir ${auxresourcesdir}/SCClassLibrary)" )
322                 endif()
323                 #symlink the folders inside SCCLassLibrary. Check if QtCollider folder should be symlinked or not.
324                 file(GLOB classlibraryfolders RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary" "SCClassLibrary/[^.]*")
325                 foreach(onedirectory ${classlibraryfolders})
326                         if(NOT "${onedirectory}" MATCHES "${SCCLASSLIB_EXCLUDE_REGEX}")
327                                 install( CODE
328                                         "EXECUTE_PROCESS(COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/${onedirectory} ${auxresourcesdir}/SCClassLibrary/${onedirectory} )" )
329                         endif()
330                 endforeach(onedirectory)
331         else()
332                 message(STATUS "Will copy SCCLassLibrary to ${auxresourcesdir}")
333                 install(DIRECTORY SCClassLibrary
334                         DESTINATION ${auxresourcesdir}
335                         REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
336                 )
337         endif()
338 else()
339         install(DIRECTORY SCClassLibrary
340                 DESTINATION ${auxresourcesdir}
341                 REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
342                 PATTERN "*~" EXCLUDE
343                 PATTERN "*#" EXCLUDE
344         )
345 endif()
348 install(DIRECTORY sounds
349         DESTINATION ${auxresourcesdir}
352 if(INSTALL_OLD_HELP)
353         install(DIRECTORY Help
354                 DESTINATION ${auxresourcesdir}
355         )
356 endif()
358 if(INSTALL_HELP)
359         install(DIRECTORY examples HelpSource
360                 DESTINATION ${auxresourcesdir}
361                 PATTERN "*~" EXCLUDE
362                 PATTERN "*#" EXCLUDE
363         )
364 endif()
366 #############################################
368 # build scdoc help files
370 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Common")
371 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Platform")
372 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/SCDoc")
373 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/DefaultLibrary")
374 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/JITLib")
375 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/backwards_compatibility")
377 # this folder has an extension to Platform that disables the loadStartupFiles method
378 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/platform/disable_startup_files")
380 foreach(arg ${BUILD_CLASSLIBRARIES})
381         set(BUILD_CLASSLIBRARYPATH "${BUILD_CLASSLIBRARYPATH}+${arg}\n")
382 endforeach()
384 configure_file(build_sclang.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg)
386 if(SC_DOC_RENDER)
387         file(GLOB_RECURSE SCDocSources RELATIVE HelpSource .*[^~])
388         file(GLOB_RECURSE SCDocClasses RELATIVE SCClassLibrary/SCDoc *.sc)
390         add_custom_target(doc ALL
391                                         COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lang/sclang${CMAKE_EXECUTABLE_SUFFIX}
392                                                         -l ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg
393                                                         platform/renderAllHelp.scd ${CMAKE_CURRENT_SOURCE_DIR}/HelpSource ${CMAKE_CURRENT_BINARY_DIR}/RenderedHelp
394                                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
395                                         DEPENDS sclang ${SCDocSources} ${SCDocClasses})
397 endif()
399 set_directory_properties(
400         PROPERTIES
401         ADDITIONAL_MAKE_CLEAN_FILES "RenderedHelp")
403 #############################################
405 # testsuite
407 add_subdirectory(testsuite)
409 #############################################
410 # win32 install support
412 if(WIN32)
413         install(FILES ${FFTW3F_LIBRARY} ${SNDFILE_LIBRARY} ${PTHREADS_LIBRARY} ${PORTAUDIO_LIBRARIES}
414                 DESTINATION "SuperCollider"
415                 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
416 endif()
418 #############################################
419 # CPack support
421 set(CPACK_PACKAGE_VERSION_MAJOR 3)
422 set(CPACK_PACKAGE_VERSION_MINOR 5)
423 set(CPACK_PACKAGE_VERSION_PATCH dev)
424 include(CPack)
425 if(WIN32)
426         set(CPACK_MONOLITHIC_INSTALL 1)
427 endif()
429 #############################################
430 # hide advanced variables
431 mark_as_advanced(AVAHI_LIBRARIES AVAHI_INCLUDE_DIRS AVAHI_INCLUDE_DIR AVAHI_LIBRARY-COMMON AVAHI_LIBRARY-CLIENT)
432 mark_as_advanced(DL)
433 mark_as_advanced(EMACS_EXECUTABLE)
434 mark_as_advanced(FFTW3F_INCLUDE_DIR FFTW3F_LIBRARY)
435 mark_as_advanced(JACK JACK_INCLUDE_DIR JACK_LIBRARY)
436 mark_as_advanced(MATH_LIBRARY)
437 mark_as_advanced(QT_QMAKE_EXECUTABLE)
438 mark_as_advanced(SNDFILE)