plugins: VarLag fix
[supercollider.git] / CMakeLists.txt
blob20bd17aeb42111980e6747802bada07da27050bf
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         option(DSO_VISIBILITY "DSO visibility support for clang" OFF)
102         if (DSO_VISIBILITY)
103                 add_definitions(-fvisibility=hidden)
104         endif()
106         set(CMAKE_COMPILER_IS_CLANG 1)
107 endif()
109 if(APPLE)
110         set_property(DIRECTORY
111                 APPEND
112                 PROPERTY COMPILE_DEFINITIONS SC_DARWIN)
113 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
114         add_definitions("-DSC_LINUX")
115         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
116 elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
117         add_definitions("-DSC_FREEBSD")
118         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
119 endif()
121 if(WIN32)
122     set_property(DIRECTORY
123                  APPEND
124                  PROPERTY COMPILE_DEFINITIONS SC_WIN32 NOMINMAX _WINSOCKAPI_)
126     if(MSVC)
127         SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} /MTd")
128         SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} /MT")
129     endif()
130 endif()
133 #############################################
134 # some default libraries
136 find_package(Pthreads)
138 if (NOT PTHREADS_FOUND)
139     message(SEND_ERROR "cannot find libpthreads")
140 endif()
141 include_directories(${PTHREADS_INCLUDE_DIR})
143 if (MSVC OR MINGW)
144     set(MATH_LIBRARY "")
145 else()
146     find_library(MATH_LIBRARY m)
147 endif()
149 if(CURL)
150         find_package(CURL)
151         if(CURL_FOUND)
152                 add_definitions("-DHAVE_LIBCURL")
153                 include_directories(${CURL_INCLUDE_DIRS})
154         endif()
155 endif()
157 #############################################
158 # Options
159 option(NOVA_SIMD "Build with nova-simd support." ON)
160 option(FINAL_BUILD "Build as single source file." OFF)
162 option(CURL "Build with curl for remote file download." ON)
164 option(FFT_GREEN "Use internal 'Green' FFT lib rather than FFTW. (Not recommended.)" OFF)
166 option(SSE "Compile with support for SSE instructions.")
167 option(SSE41 "Compile with support for SSE4.1 instructions.")
168 option(SSE42 "Compile with support for SSE4.2 instructions.")
171 option(INSTALL_HELP "Install help docs and examples along with the software" ON)
172 option(INSTALL_OLD_HELP "Install old and deprecated help files" ON)
173 option(SC_DOC_RENDER "Pre-render SCDoc documentation. (For putting online, etc)" OFF)
175 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
176     option(SUPERNOVA "Build with supernova as optional audio synthesis server" ON)
177 elseif()
178     option(SUPERNOVA "Build with supernova as optional audio synthesis server" OFF)
179 endif()
181 option(SN_MEMORY_DEBUGGING "Build supernova for memory debugging (disable memory pools).")
182 option(SC_MEMORY_DEBUGGING "Build sclang&scsynth for memory debugging (disable memory pools).")
183 option(GC_SANITYCHECK "Enable sanity checks in the sclang garbage collector.")
185 option(NO_LIBSNDFILE "Disable soundfile functionality. (Not recommended.)" OFF)
187 option(NO_AVAHI "Disable Avahi support. (Not recommended.)" OFF)
189 if(NOT WIN32)
190         option(SCLANG_SERVER "Build with internal server." ON)
191 endif()
193 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
194         option(SC_WII "Build sclang with WII support" ON)
195 endif()
197 option(SC_QT "Build SuperCollider with Qt GUI" ON)
198 if (SC_QT)
199   message( STATUS "Compiling with Qt GUI" )
200 endif (SC_QT)
202 if(WIN32)
203         option(SC_PSYCOLLIDER "Build PsyCollider" ON)
204 else()
205         option(SC_PSYCOLLIDER "Build PsyCollider" OFF)
206 endif()
208 if(CMAKE_COMPILER_IS_GNUCXX)
209     option(NATIVE "Optimize binary for this architecture (binaries may not run on other machines, requires gcc-4.3 or higher).")
210     option(LTO "Use GCC's link time optimizer' (experimental).")
211 endif()
213 option(SC_SYMLINK_CLASSLIB "Place a symlink of SCCLassLibrary instead of copying" OFF)
214 option(SC_OX "Try to compile with support for C++0x (experimental, mainly related to supernova)" OFF)
216 #############################################
217 # some preprocessor flags
218 if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
219         if (SSE)
220                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -mfpmath=sse")
221                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -mfpmath=sse")
222         endif()
223         if (SSE41)
224                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
225                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
226         endif()
227         if (SSE42)
228                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
229                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
230         endif()
231         if (NATIVE)
232                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
233                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
234         endif()
236         if (SC_OX)
237                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
238         endif()
239 endif()
241 if (CMAKE_COMPILER_IS_INTEL AND NOT WIN32)
242         if (SSE42)
243                 add_definitions(-xSSE4.2)
244         elseif (SSE41)
245                 add_definitions(-xSSE4.1)
246         elseif (SSE)
247                 add_definitions(-mia32)
248         endif()
249         if (SC_OX)
250                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
251         endif()
253         # disable warnings
254         add_definitions(-diag-disable 170) # pointer points outside of underlying object ... used heavily in sclang
255         add_definitions(-diag-disable 279) # controlling expression is constant
257 endif()
259 if (SC_MEMORY_DEBUGGING)
260         add_definitions(-DDISABLE_MEMORY_POOLS)
261 endif()
263 #############################################
264 # subdirectories
265 add_subdirectory(external_libraries)
266 add_subdirectory(server)
267 add_subdirectory(lang)
268 add_subdirectory(bindings)
269 add_subdirectory(platform)
270 add_subdirectory(editors)
272 if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
273     install(DIRECTORY include/common include/plugin_interface include/server include/lang
274         DESTINATION ${CMAKE_INSTALL_PREFIX}/include/SuperCollider
275         FILES_MATCHING PATTERN "*.h"
276     )
277 endif()
279 if(APPLE)
280         # determines the app name and app install location (scappbundlename, scappdir):
281         include (cmake_modules/MacAppFolder.cmake)
283         set(auxresourcesdir ${scappauxresourcesdir})
285         # Some aux files which go in the app's folder
286         install(FILES README.txt ChangeLog
287                 DESTINATION ${auxresourcesdir}
288         )
289         install(FILES COPYING AUTHORS
290                 DESTINATION ${scappdir}
291         )
292 elseif (WIN32)
293         set(auxresourcesdir "SuperCollider")
294 else()
295         set(auxresourcesdir "share/SuperCollider")
296 endif()
298 if(NOT SC_QT)
299         set(SCCLASSLIB_EXCLUDE_REGEX "QtCollider")
300 else()
301         set(SCCLASSLIB_EXCLUDE_REGEX "IGNOREME")
302 endif()
304 if(APPLE)
305         #if directory contains symlinks, unlink them.
306         if(EXISTS "${auxresourcesdir}/SCClassLibrary")
307                 file(GLOB classlibraryfolders "${auxresourcesdir}/SCClassLibrary/[^.]*")
308                 foreach(onedirectory ${classlibraryfolders})
309                         if(IS_SYMLINK "${onedirectory}")
310                                 install( CODE "EXECUTE_PROCESS(COMMAND unlink ${onedirectory} )" )
311                         endif()
312                 endforeach(onedirectory)
313         endif()
315         if(SC_SYMLINK_CLASSLIB)
317                 #if there are folders inside SCCLassLibrary abort cmake.
318                 file(GLOB classlibraryfolders "${auxresourcesdir}/SCClassLibrary/[^.]*")
319                 foreach(onedirectory ${classlibraryfolders})
320                         if(NOT IS_SYMLINK "${onedirectory}")
321                                 message(FATAL_ERROR "Symlinking will fail ! SCClassLibrary folder already exists and has directories inside, please delete it first." )
322                         endif()
323                 endforeach(onedirectory)
325                 message(STATUS "Will create symlink of SCClassLibrary to ${auxresourcesdir}/SCClassLibrary" )
326                 if(NOT EXISTS "${auxresourcesdir}/SCClassLibrary")
327                         install( CODE "EXECUTE_PROCESS(COMMAND mkdir ${auxresourcesdir}/SCClassLibrary)" )
328                 endif()
329                 #symlink the folders inside SCCLassLibrary. Check if QtCollider folder should be symlinked or not.
330                 file(GLOB classlibraryfolders RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary" "SCClassLibrary/[^.]*")
331                 foreach(onedirectory ${classlibraryfolders})
332                         if(NOT "${onedirectory}" MATCHES "${SCCLASSLIB_EXCLUDE_REGEX}")
333                                 install( CODE
334                                         "EXECUTE_PROCESS(COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/${onedirectory} ${auxresourcesdir}/SCClassLibrary/${onedirectory} )" )
335                         endif()
336                 endforeach(onedirectory)
337         else()
338                 message(STATUS "Will copy SCCLassLibrary to ${auxresourcesdir}")
339                 install(DIRECTORY SCClassLibrary
340                         DESTINATION ${auxresourcesdir}
341                         REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
342                 )
343         endif()
344 else()
345         install(DIRECTORY SCClassLibrary
346                 DESTINATION ${auxresourcesdir}
347                 REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
348                 PATTERN "*~" EXCLUDE
349                 PATTERN "*#" EXCLUDE
350         )
351 endif()
354 install(DIRECTORY sounds
355         DESTINATION ${auxresourcesdir}
358 if(INSTALL_OLD_HELP)
359         install(DIRECTORY Help
360                 DESTINATION ${auxresourcesdir}
361         )
362 endif()
364 if(INSTALL_HELP)
365         install(DIRECTORY examples HelpSource
366                 DESTINATION ${auxresourcesdir}
367                 PATTERN "*~" EXCLUDE
368                 PATTERN "*#" EXCLUDE
369         )
370 endif()
372 #############################################
374 # build scdoc help files
376 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Common")
377 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Platform")
378 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/SCDoc")
379 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/DefaultLibrary")
380 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/JITLib")
381 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/backwards_compatibility")
383 # this folder has an extension to Platform that disables the loadStartupFiles method
384 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/platform/disable_startup_files")
386 foreach(arg ${BUILD_CLASSLIBRARIES})
387         set(BUILD_CLASSLIBRARYPATH "${BUILD_CLASSLIBRARYPATH}+${arg}\n")
388 endforeach()
390 configure_file(build_sclang.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg)
392 if(SC_DOC_RENDER)
393         file(GLOB_RECURSE SCDocSources RELATIVE HelpSource .*[^~])
394         file(GLOB_RECURSE SCDocClasses RELATIVE SCClassLibrary/SCDoc *.sc)
396         add_custom_target(doc ALL
397                                         COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lang/sclang${CMAKE_EXECUTABLE_SUFFIX}
398                                                         -l ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg
399                                                         platform/renderAllHelp.scd ${CMAKE_CURRENT_SOURCE_DIR}/HelpSource ${CMAKE_CURRENT_BINARY_DIR}/RenderedHelp
400                                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
401                                         DEPENDS sclang ${SCDocSources} ${SCDocClasses})
403 endif()
405 set_directory_properties(
406         PROPERTIES
407         ADDITIONAL_MAKE_CLEAN_FILES "RenderedHelp")
409 #############################################
411 # testsuite
413 add_subdirectory(testsuite)
415 #############################################
416 # win32 install support
418 if(WIN32)
419         install(FILES ${FFTW3F_LIBRARY} ${SNDFILE_LIBRARY} ${PTHREADS_LIBRARY} ${PORTAUDIO_LIBRARIES}
420                 DESTINATION "SuperCollider"
421                 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
422 endif()
424 #############################################
425 # CPack support
427 set(CPACK_PACKAGE_VERSION_MAJOR 3)
428 set(CPACK_PACKAGE_VERSION_MINOR 5)
429 set(CPACK_PACKAGE_VERSION_PATCH dev)
430 include(CPack)
431 if(WIN32)
432         set(CPACK_MONOLITHIC_INSTALL 1)
433 endif()
435 #############################################
436 # hide advanced variables
437 mark_as_advanced(AVAHI_LIBRARIES AVAHI_INCLUDE_DIRS AVAHI_INCLUDE_DIR AVAHI_LIBRARY-COMMON AVAHI_LIBRARY-CLIENT)
438 mark_as_advanced(DL)
439 mark_as_advanced(EMACS_EXECUTABLE)
440 mark_as_advanced(FFTW3F_INCLUDE_DIR FFTW3F_LIBRARY)
441 mark_as_advanced(JACK JACK_INCLUDE_DIR JACK_LIBRARY)
442 mark_as_advanced(MATH_LIBRARY)
443 mark_as_advanced(QT_QMAKE_EXECUTABLE)
444 mark_as_advanced(SNDFILE)