external libraries: yaml-cpp version bump
[supercollider.git] / CMakeLists.txt
blob324b0f9c7d2dcdcfd2186378bbf314a198681730
1 cmake_minimum_required (VERSION 2.8)
2 project (SuperCollider)
4 include("SCVersion.txt")
5 set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH}")
6 message(STATUS "SuperCollider Version: ${PROJECT_VERSION}")
8 include(CTest)
9 enable_testing()
11 include (cmake_modules/FinalFile.cmake)
13 if (NOT CMAKE_BUILD_TYPE)
14         message(STATUS "Build type defaulting to \"RelWithDebInfo\"")
15         set(CMAKE_BUILD_TYPE "RelWithDebInfo")
16 endif()
18 if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
19         message(WARNING "WARNING: IN-PLACE BUILDS ARE NOT RECOMMENDED - PLEASE USE A BUILD DIRECTORY")
20 endif()
23 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
24                       ${CMAKE_MODULE_PATH})
26 CONFIGURE_FILE(
27   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/cmake_uninstall.cmake.in"
28   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
29   IMMEDIATE @ONLY)
31 ADD_CUSTOM_TARGET(uninstall
32   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
34 if(APPLE)
35         STRING(REGEX REPLACE "^.*MacOSX10.([0-9]+).*$" "\\1" MAC_OSX_SDK_VERSION  "${CMAKE_OSX_SYSROOT}")
37         if(CMAKE_OSX_DEPLOYMENT_TARGET)
38                 if (CMAKE_OSX_DEPLOYMENT_TARGET GREATER 10.4)
39                         set(HID_UTIL_DIR "HID_Utilities")
40                 else()
41                         set(HID_UTIL_DIR "HID_Utilities_10_4")
42                 endif()
43         else()
44                 if (${MAC_OSX_SDK_VERSION} GREATER 4)
45                         set(HID_UTIL_DIR "HID_Utilities")
46                 else()
47                         set(HID_UTIL_DIR "HID_Utilities_10_4")
48                 endif()
49         endif()
50         MESSAGE( STATUS "Using HID Utilities from folder '${HID_UTIL_DIR}'")
51 endif()
53 if (CMAKE_SYSTEM_NAME MATCHES "Linux")
54         set(LINUX 1)
55 endif()
57 #############################################
58 # Compiler flags etc
60 add_definitions(-DWIN32_LEAN_AND_MEAN)
62 if (${CMAKE_COMPILER_IS_GNUCXX})
63         exec_program(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE _gcc_version)
65         add_definitions("-fschedule-insns2" "-fomit-frame-pointer")
67         add_definitions("-Wreturn-type")
69 #       disabled for now: -ffast-math breaks avx intrinsics and -fsigned-zeros/-fno-associative-math are not available in some versions
70 #       if (${_gcc_version} VERSION_GREATER 4.0.99)
71 #               add_definitions("-ffast-math -fsigned-zeros -fno-associative-math")
72 #       endif()
74         option(DSO_VISIBILITY "DSO visibility support for gcc" OFF)
76         if (DSO_VISIBILITY)
77                 add_definitions(-fvisibility=hidden)
78         endif()
80         if(APPLE)
81                 exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
82                 if ("${_gcc_version_info}" MATCHES "Apple")
83                         add_definitions("-fpascal-strings")
84                 endif()
85                 add_definitions("-D_REENTRANT")
86         elseif(NOT (WIN32 AND NOT CYGWIN))
87                 add_definitions("-pthread")
88         endif()
89 endif ()
91 if (${CMAKE_CXX_COMPILER} MATCHES icpc)
92         set(CMAKE_COMPILER_IS_INTEL 1)
93         add_definitions(-Wno-unknown-pragmas)
94         add_definitions(-simd)
95 endif()
97 if (${CMAKE_CXX_COMPILER} MATCHES clang)
98         option(DSO_VISIBILITY "DSO visibility support for clang" OFF)
100         if (DSO_VISIBILITY)
101                 add_definitions(-fvisibility=hidden)
102         endif()
104         set(CMAKE_COMPILER_IS_CLANG 1)
105 endif()
107 if(APPLE)
108         set_property(DIRECTORY
109                 APPEND
110                 PROPERTY COMPILE_DEFINITIONS SC_DARWIN)
111 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
112         add_definitions("-DSC_LINUX")
113         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
114 elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
115         add_definitions("-DSC_FREEBSD")
116         add_definitions(-DSC_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/SuperCollider")
117 endif()
119 if(WIN32)
120     set_property(DIRECTORY
121                  APPEND
122                  PROPERTY COMPILE_DEFINITIONS SC_WIN32 NOMINMAX _WIN32_WINNT=0x0500)
124     if(MSVC)
125         SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} /MTd")
126         SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} /MT")
127     endif()
128 endif()
131 #############################################
132 # some default libraries
134 find_package(Pthreads)
136 if (NOT PTHREADS_FOUND)
137     message(SEND_ERROR "cannot find libpthreads")
138 endif()
139 include_directories(${PTHREADS_INCLUDE_DIR})
141 if (MSVC OR MINGW)
142     set(MATH_LIBRARY "")
143 else()
144     find_library(MATH_LIBRARY m)
145 endif()
147 if(CURL)
148         find_package(CURL)
149         if(CURL_FOUND)
150                 add_definitions("-DHAVE_LIBCURL")
151                 include_directories(${CURL_INCLUDE_DIRS})
152         endif()
153 endif()
155 #############################################
156 # Options
157 option(NOVA_SIMD "Build with nova-simd support." ON)
158 option(FINAL_BUILD "Build as single source file." OFF)
160 option(CURL "Build with curl for remote file download." ON)
162 option(FFT_GREEN "Use internal 'Green' FFT lib rather than FFTW. (Not recommended.)" OFF)
164 option(SSE "Compile with support for SSE instructions.")
165 option(SSE41 "Compile with support for SSE4.1 instructions.")
166 option(SSE42 "Compile with support for SSE4.2 instructions.")
169 option(INSTALL_HELP "Install help docs and examples along with the software" ON)
170 option(INSTALL_OLD_HELP "Install old and deprecated help files" ON)
171 option(SC_DOC_RENDER "Pre-render SCDoc documentation. (For putting online, etc)" OFF)
173 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
174     option(SUPERNOVA "Build with supernova as optional audio synthesis server" ON)
175 elseif()
176     option(SUPERNOVA "Build with supernova as optional audio synthesis server" OFF)
177 endif()
179 option(SN_MEMORY_DEBUGGING "Build supernova for memory debugging (disable memory pools).")
180 option(SC_MEMORY_DEBUGGING "Build sclang&scsynth for memory debugging (disable memory pools).")
181 option(GC_SANITYCHECK "Enable sanity checks in the sclang garbage collector.")
183 option(NO_LIBSNDFILE "Disable soundfile functionality. (Not recommended.)" OFF)
185 option(NO_AVAHI "Disable Avahi support. (Not recommended.)" OFF)
187 option(SCLANG_SERVER "Build with internal server." ON)
189 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
190         option(SC_WII "Build sclang with WII support" ON)
191 endif()
193 option(SC_QT "Build SuperCollider with Qt GUI" ON)
194 if (SC_QT)
195   message( STATUS "Compiling with Qt GUI" )
196 endif (SC_QT)
198 if(WIN32)
199         option(SC_PSYCOLLIDER "Build PsyCollider" ON)
200 else()
201         option(SC_PSYCOLLIDER "Build PsyCollider" OFF)
202 endif()
204 if(WIN32)
205     option(SC_WIN_DEP_DIRS
206         "A list of directories where dependencies will be searched for when packaging.")
207 endif()
209 if(CMAKE_COMPILER_IS_GNUCXX)
210     option(NATIVE "Optimize binary for this architecture (binaries may not run on other machines, requires gcc-4.3 or higher).")
211     option(LTO "Use GCC's link time optimizer' (experimental).")
212 endif()
214 option(SC_SYMLINK_CLASSLIB "Place a symlink of SCCLassLibrary instead of copying" OFF)
215 option(SC_OX "Try to compile with support for C++0x (experimental, mainly related to supernova)" OFF)
217 #############################################
218 # some preprocessor flags
219 if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
220         if (SSE)
221                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -mfpmath=sse")
222                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -mfpmath=sse")
223         endif()
224         if (SSE41)
225                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
226                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
227         endif()
228         if (SSE42)
229                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
230                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
231         endif()
232         if (NATIVE)
233                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
234                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
235         endif()
237         if (SC_OX)
238                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
239         endif()
240 endif()
242 if (CMAKE_COMPILER_IS_INTEL AND NOT WIN32)
243         if (SSE42)
244                 add_definitions(-xSSE4.2)
245         elseif (SSE41)
246                 add_definitions(-xSSE4.1)
247         elseif (SSE)
248                 add_definitions(-mia32)
249         endif()
250         if (SC_OX)
251                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
252         endif()
254         # disable warnings
255         add_definitions(-diag-disable 170) # pointer points outside of underlying object ... used heavily in sclang
256         add_definitions(-diag-disable 279) # controlling expression is constant
258 endif()
260 if (SC_MEMORY_DEBUGGING)
261         add_definitions(-DDISABLE_MEMORY_POOLS)
262 endif()
264 #############################################
265 # subdirectories
266 add_subdirectory(external_libraries)
267 add_subdirectory(server)
268 add_subdirectory(lang)
269 add_subdirectory(bindings)
270 add_subdirectory(editors)
271 add_subdirectory(platform)
273 if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
274     install(DIRECTORY include/common include/plugin_interface include/server include/lang
275         DESTINATION ${CMAKE_INSTALL_PREFIX}/include/SuperCollider
276         FILES_MATCHING PATTERN "*.h"
277     )
278 endif()
280 if(APPLE)
281         # determines the app name and app install location (scappbundlename, scappdir):
282         include (cmake_modules/MacAppFolder.cmake)
284         set(auxresourcesdir ${scappauxresourcesdir})
286         # Some aux files which go in the app's folder
287         install(FILES README.txt ChangeLog COPYING AUTHORS platform/mac/MOVED_STUFF.txt
288                 DESTINATION ${scappbundlename}
289         )
290 elseif (WIN32)
291         set(auxresourcesdir "SuperCollider")
292 else()
293         set(auxresourcesdir "share/SuperCollider")
294 endif()
296 set(SCCLASSLIB_EXCLUDE_REGEX "IGNOREME")
298 if(NOT SC_QT)
299         set(SCCLASSLIB_EXCLUDE_REGEX "${SCCLASSLIB_EXCLUDE_REGEX}|QtCollider")
300 endif()
302 if(WIN32)
303         set(SCCLASSLIB_EXCLUDE_REGEX "${SCCLASSLIB_EXCLUDE_REGEX}|PsycolliderDocument")
304 endif()
307 if(APPLE)
309         if(SC_SYMLINK_CLASSLIB)
311                 #if there are folders inside SCCLassLibrary abort cmake.
312                 file(GLOB classlibraryfolders "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary/[^.]*")
313                 foreach(onedirectory ${classlibraryfolders})
314                         message( "${onedirectory}" )
315                         if(NOT IS_SYMLINK "${onedirectory}")
316                                 message(FATAL_ERROR "Symlinking will fail ! SCClassLibrary folder already exists and has directories inside, please delete it first." )
317                         endif()
318                 endforeach(onedirectory)
320                 message(STATUS "Will create symlink of SCClassLibrary to ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary" )
321                 if(NOT EXISTS "{CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary")
322                         install( CODE "EXECUTE_PROCESS(COMMAND mkdir ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary)" )
323                 endif()
324                 #symlink the folders inside SCCLassLibrary. Check if QtCollider folder should be symlinked or not.
325                 file(GLOB classlibraryfolders RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary" "SCClassLibrary/[^.]*")
326                 foreach(onedirectory ${classlibraryfolders})
327                         if(NOT "${onedirectory}" MATCHES "${SCCLASSLIB_EXCLUDE_REGEX}")
328                                 install( CODE
329                                         "EXECUTE_PROCESS(COMMAND ln -shF ${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/${onedirectory} ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary/${onedirectory} )" )
330                         endif()
331                 endforeach(onedirectory)
332         else()
333                 message(STATUS "Will copy SCCLassLibrary to ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}")
335                 #if directory contains symlinks, unlink them.
336                 if(EXISTS "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary")
337                         file(GLOB classlibraryfolders "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/SCClassLibrary/[^.]*")
338                         foreach(onedirectory ${classlibraryfolders})
339                                 if(IS_SYMLINK "${onedirectory}")
340                                         message(STATUS "Unlinking ${onedirectory}")
341                                         install( CODE "EXECUTE_PROCESS(COMMAND unlink ${onedirectory} )" )
342                                 endif()
343                         endforeach(onedirectory)
344                 endif()
346                 install(DIRECTORY SCClassLibrary
347                         DESTINATION ${auxresourcesdir}
348                         REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
349                 )
350         endif()
351 else()
352         install(DIRECTORY SCClassLibrary
353                 DESTINATION ${auxresourcesdir}
354                 REGEX ${SCCLASSLIB_EXCLUDE_REGEX} EXCLUDE
355                 PATTERN "*~" EXCLUDE
356                 PATTERN "*#" EXCLUDE
357         )
358 endif()
360 configure_file(platform/SCVersion.sc.in SCVersion/SCVersion.sc)
361 install(DIRECTORY "${CMAKE_BINARY_DIR}/SCVersion" DESTINATION "${auxresourcesdir}/SCClassLibrary")
363 install(DIRECTORY sounds
364         DESTINATION ${auxresourcesdir}
367 if(APPLE AND ("${standalone}" STREQUAL ""))
368         set(exampledir "${scappbundlename}")
369 else()
370         set(exampledir "${auxresourcesdir}")
371 endif()
373 install(DIRECTORY examples
374         DESTINATION ${exampledir}
375         PATTERN "*~" EXCLUDE
376         PATTERN "*#" EXCLUDE
379 if(INSTALL_OLD_HELP)
380         install(DIRECTORY Help
381                 DESTINATION ${auxresourcesdir}
382         )
383 endif()
385 if(INSTALL_HELP)
386         if(SC_SYMLINK_CLASSLIB AND APPLE)
387                 message(STATUS "Will create symlink of HelpSource to ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource")
388                 if(EXISTS "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource")
389                         message(FATAL_ERROR "Symlinking will fail ! HelpSource folder already exists, please delete it first." )
390                 endif()
391                 install( CODE
392                                         "EXECUTE_PROCESS(COMMAND ln -shF ${CMAKE_CURRENT_SOURCE_DIR}/HelpSource ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource )" )
393         else()
394                 message(STATUS "Will copy HelpSource to ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}")
395                 if(APPLE)
396                         if(EXISTS "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource")
397                                 if(IS_SYMLINK "${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource")
398                                         message(STATUS "Unlinking ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource")
399                                         install( CODE "EXECUTE_PROCESS(COMMAND unlink ${CMAKE_INSTALL_PREFIX}/${auxresourcesdir}/HelpSource )" )
400                                 endif()
401                         endif()
402                 endif()
403                 install(DIRECTORY HelpSource
404                         DESTINATION ${auxresourcesdir}
405                         PATTERN "*~" EXCLUDE
406                         PATTERN "*#" EXCLUDE
407                 )
408         endif()
409 endif()
411 #############################################
413 # build scdoc help files
415 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Common")
416 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/Platform")
417 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/SCDoc")
418 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/DefaultLibrary")
419 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/JITLib")
420 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/SCClassLibrary/backwards_compatibility")
422 # this folder has an extension to Platform that disables the loadStartupFiles method
423 list(APPEND BUILD_CLASSLIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/platform/disable_startup_files")
425 foreach(arg ${BUILD_CLASSLIBRARIES})
426         set(BUILD_CLASSLIBRARYPATH "${BUILD_CLASSLIBRARYPATH}+${arg}\n")
427 endforeach()
429 configure_file(build_sclang.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg)
431 if(SC_DOC_RENDER)
432         file(GLOB_RECURSE SCDocSources RELATIVE HelpSource .*[^~])
433         file(GLOB_RECURSE SCDocClasses RELATIVE SCClassLibrary/SCDoc *.sc)
435         add_custom_target(doc ALL
436                                         COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lang/sclang${CMAKE_EXECUTABLE_SUFFIX}
437                                                         -l ${CMAKE_CURRENT_BINARY_DIR}/build_sclang.cfg
438                                                         platform/renderAllHelp.scd ${CMAKE_CURRENT_SOURCE_DIR}/HelpSource ${CMAKE_CURRENT_BINARY_DIR}/RenderedHelp
439                                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
440                                         DEPENDS sclang ${SCDocSources} ${SCDocClasses})
442 endif()
444 set_directory_properties(
445         PROPERTIES
446         ADDITIONAL_MAKE_CLEAN_FILES "RenderedHelp")
448 #############################################
450 # testsuite
452 add_subdirectory(testsuite)
454 #############################################
455 # CPack support
457 set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
458 set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
459 set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
461 if(APPLE)
462         set(CPACK_GENERATOR "DragNDrop")
463         set(CPACK_DMG_FORMAT "UDBZ")
464         set(CPACK_DMG_VOLUME_NAME "${scappbundlename}")
465         set(CPACK_SYSTEM_NAME "OSX")
466 #       set(CPACK_PACKAGE_FILE_NAME "${scappbundlename}-${PROJECT_VERSION}")
467         set(CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/package/ds_store")
468         set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/package/background.png")
469         set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/platform/mac/Resources/SCcube.icns")
470 endif()
472 if(NOT WIN32) # We define a custom 'package' target in platform/windows/CMakeLists.txt
473     include(CPack)
474 endif()
476 #############################################
477 # hide advanced variables
478 mark_as_advanced(AVAHI_LIBRARIES AVAHI_INCLUDE_DIRS AVAHI_INCLUDE_DIR AVAHI_LIBRARY-COMMON AVAHI_LIBRARY-CLIENT)
479 mark_as_advanced(DL)
480 mark_as_advanced(EMACS_EXECUTABLE)
481 mark_as_advanced(FFTW3F_INCLUDE_DIR FFTW3F_LIBRARY)
482 mark_as_advanced(JACK JACK_INCLUDE_DIR JACK_LIBRARY)
483 mark_as_advanced(MATH_LIBRARY)
484 mark_as_advanced(QT_QMAKE_EXECUTABLE)
485 mark_as_advanced(SNDFILE)