Use pkg-config to find NTK.
[zynaddsubfx.git] / src / CMakeLists.txt
blobc648be20c2c6de6e1f663736561dd367a40932ed
1 #checking include/library paths
2 message(STATUS "Checking Include Path" $ENV{CMAKE_INCLUDE_PATH} ${CMAKE_INCLUDE_PATH})
3 message(STATUS "Checking Library Path" $ENV{CMAKE_LIBRARY_PATH} ${CMAKE_LIBRARY_PATH})
5 #Dependency check
6 find_package(PkgConfig REQUIRED)
7 find_package(zlib REQUIRED)
8 pkg_check_modules(FFTW REQUIRED fftw3)
9 pkg_check_modules(MXML REQUIRED mxml)
10 find_package(Threads   REQUIRED)
11 find_package(OSS)
12 find_package(Alsa)
13 pkg_check_modules(JACK jack)
14 pkg_check_modules(PORTAUDIO portaudio-2.0>=19)
15 set(FLTK_SKIP_OPENGL true)
16 pkg_check_modules(NTK ntk)
17 pkg_check_modules(NTK_IMAGES ntk_images)
18 find_package(FLTK)
19 find_package(OpenGL) #for FLTK
20 find_package(CxxTest)
21 if(CXXTEST_FOUND)
22     set(CXXTEST_USE_PYTHON TRUE)
23 endif()
24 # lash
25 pkg_search_module(LASH lash-1.0)
26 mark_as_advanced(LASH_LIBRARIES)
27 pkg_search_module(DSSI dssi>=0.9.0)
28 mark_as_advanced(DSSI_LIBRARIES)
29 pkg_search_module(LIBLO liblo>=0.26)
30 mark_as_advanced(LIBLO_LIBRARIES)
32 ######### Settings ###########
33 # NOTE: These cache variables should normally not be changed in this
34 # file, but either in in CMakeCache.txt before compile, or by passing
35 # parameters directly into cmake using the -D flag.
36 SET (GuiModule fltk CACHE STRING "GUI module, either fltk, ntk or off")
37 SET (CompileTests ${CXXTEST_FOUND} CACHE BOOL "whether tests should be compiled in or not")
38 SET (AlsaEnable ${ALSA_FOUND} CACHE BOOL
39     "Enable support for Advanced Linux Sound Architecture")
40 SET (JackEnable ${JACK_FOUND} CACHE BOOL
41     "Enable support for JACK Audio Connection toolKit")
42 SET (OssEnable ${OSS_FOUND} CACHE BOOL
43     "Enable support for Open Sound System")
44 SET (PaEnable ${PORTAUDIO_FOUND} CACHE BOOL
45     "Enable support for Port Audio System")
46 SET (LashEnable ${LASH_FOUND} CACHE BOOL
47     "Enable LASH Audio Session Handler")
48 SET (DssiEnable ${DSSI_FOUND} CACHE BOOL
49     "Enable DSSI Plugin compilation")
50 SET (LibloEnable ${LIBLO_FOUND} CACHE BOOL
51     "Enable Liblo")
53 # Now, handle the incoming settings and set define flags/variables based
54 # on this
56 # Add version information
57 add_definitions(-DVERSION="${VERSION}")
59 # Give a good guess on the best Input/Output default backends
60 if (JackEnable)
61     SET (DefaultOutput jack CACHE STRING
62         "Default Output module: [null, alsa, oss, jack, portaudio]")
63     # Override with perhaps more helpful midi backends
64     if (AlsaEnable)
65         SET (DefaultInput alsa CACHE STRING
66             "Default Input module: [null, alsa, oss, jack]")
67     elseif (OssEnable)
68         SET (DefaultInput oss CACHE STRING
69             "Default Input module: [null, alsa, oss, jack]")
70     else ()
71         SET (DefaultInput jack CACHE STRING
72             "Default Input module: [null, alsa, oss, jack]")
73     endif ()
74 elseif (AlsaEnable)
75     SET (DefaultOutput alsa CACHE STRING
76         "Default Output module: [null, alsa, oss, jack, portaudio]")
77     SET (DefaultInput alsa CACHE STRING
78         "Default Input module: [null, alsa, oss, jack]")
79 elseif (OssEnable)
80     SET (DefaultOutput oss CACHE STRING
81         "Default Output module: [null, alsa, oss, jack, portaudio]")
82     SET (DefaultInput oss CACHE STRING
83         "Default Input module: [null, alsa, oss, jack]")
84 else()
85     SET (DefaultOutput null CACHE STRING
86         "Default Output module: [null, alsa, oss, jack, portaudio]")
87     SET (DefaultInput null CACHE STRING
88         "Default Input module: [null, alsa, oss, jack]")
89 endif()
93 if (GuiModule STREQUAL qt AND QT_FOUND)
94         set (QtGui TRUE)
95 elseif(GuiModule STREQUAL ntk AND NTK_FOUND)
96         set (NtkGui TRUE)
97 elseif(GuiModule STREQUAL fltk AND FLTK_FOUND)
98         set (FltkGui TRUE)
99 elseif(GuiModule STREQUAL off)
100         add_definitions(-DDISABLE_GUI)
101 else  ()
102         set (GuiModule off CACHE STRING "GUI module, either fltk, qt or off")
103         add_definitions(-DDISABLE_GUI)
104         message(STATUS "GUI module defaulting to off")
105 endif()
108 #Build Flags
109 option (BuildForAMD_X86_64 "Build for AMD x86_64 system" OFF)
110 option (BuildForCore2_X86_64 "Build for Intel Core2 x86_64 system" OFF)
111 option (BuildForDebug "Include gdb debugging support" OFF)
113 set(CMAKE_BUILD_TYPE "Release")
115 set (BuildOptions_x86_64AMD
116     "-O3 -march=athlon64 -m64 -Wall -ffast-math -fno-finite-math-only -fomit-frame-pointer"
117   CACHE STRING "X86_64 compiler options"
120 set (BuildOptions_X86_64Core2
121     "-O3 -march=core2 -m64 -Wall -ffast-math -fno-finite-math-only -fomit-frame-pointer"
122   CACHE STRING "X86_64 compiler options"
125 set (BuildOptionsBasic
126     "-O3 -msse -msse2 -mfpmath=sse -ffast-math -fomit-frame-pointer"
127     CACHE STRING "basic X86 complier options"
130 set (BuildOptionsDebug
131     "-O0 -g3 -ggdb -Wall -Wpointer-arith" CACHE STRING "Debug build flags")
133 ########### Settings dependant code ###########
134 # From here on, the setting variables have  been prepared so concentrate
135 # on the actual compiling.
137 if(AlsaEnable)
138         list(APPEND AUDIO_LIBRARIES ${ASOUND_LIBRARY})
139         list(APPEND AUDIO_LIBRARY_DIRS ${ASOUND_LIBRARY_DIRS})
140         add_definitions(-DALSA=1)
141 endif(AlsaEnable)
143 if(JackEnable)
144         list(APPEND AUDIO_LIBRARIES ${JACK_LIBRARIES})
145         list(APPEND AUDIO_LIBRARY_DIRS ${JACK_LIBRARY_DIRS})
146         add_definitions(-DJACK=1)
147 endif(JackEnable)
149 if(OssEnable)
150         add_definitions(-DOSS=1)
151 endif(OssEnable)
153 if(PaEnable)
154         include_directories(${PORTAUDIO_INCLUDE_DIR})
155         add_definitions(-DPORTAUDIO=1)
156         list(APPEND AUDIO_LIBRARIES ${PORTAUDIO_LIBRARIES})
157         list(APPEND AUDIO_LIBRARY_DIRS ${PORTAUDIO_LIBRARY_DIRS})
158 endif()
160 if (CompileTests)
161         ENABLE_TESTING()
162 endif()
164 if(LashEnable)
165         include_directories(${LASH_INCLUDE_DIRS})
166         add_definitions(-DLASH=1)
167         list(APPEND AUDIO_LIBRARIES ${LASH_LIBRARIES})
168         list(APPEND AUDIO_LIBRARY_DIRS ${LASH_LIBRARY_DIRS})
169         message(STATUS "Compiling with lash")
170 endif()
171 if(LibloEnable)
172         include_directories(${LIBLO_INCLUDE_DIRS})
173         add_definitions(-DUSE_NSM=1)
174         list(APPEND AUDIO_LIBRARIES ${LIBLO_LIBRARIES})
175         list(APPEND AUDIO_LIBRARY_DIRS ${LIBLO_LIBRARY_DIRS})
176         message(STATUS "Compiling with liblo")
177 endif()
179 # other include directories
180 include_directories(${ZLIB_INCLUDE_DIRS} ${MXML_INCLUDE_DIRS})
182 add_definitions(
183          -DASM_F2I_YES
184          -g #TODO #todo put in a better location
185          -Wall
186          -Wextra
187          )
189 if (BuildForDebug)
190         set (CMAKE_BUILD_TYPE "Debug")
191         set (CMAKE_CXX_FLAGS_DEBUG ${BuildOptionsDebug})
192         message (STATUS "Building for ${CMAKE_BUILD_TYPE}, flags: ${CMAKE_CXX_FLAGS_DEBUG}")
193 else (BuildForDebug)
194         set (CMAKE_BUILD_TYPE "Release")
195         if (BuildForAMD_X86_64)
196                 set (CMAKE_CXX_FLAGS_RELEASE ${BuildOptions_x86_64AMD})
197         else (BuildForAMD_X86_64)
198                 if (BuildForCore2_X86_64)
199                         set (CMAKE_CXX_FLAGS_RELEASE ${BuildOptions_X86_64Core2})
200                 else (BuildForCore2_X86_64)
201                         set (CMAKE_CXX_FLAGS_RELEASE ${BuildOptionsBasic})
202                 endif (BuildForCore2_X86_64)
203         endif (BuildForAMD_X86_64)
204         message (STATUS "Building for ${CMAKE_BUILD_TYPE}, flags: ${CMAKE_CXX_FLAGS_RELEASE}")
205 endif (BuildForDebug)
207 add_definitions(-fPIC)
209 if(FLTK_FOUND)
210         mark_as_advanced(FORCE FLTK_BASE_LIBRARY)
211         mark_as_advanced(FORCE FLTK_CONFIG_SCRIPT)
212         mark_as_advanced(FORCE FLTK_DIR)
213         mark_as_advanced(FORCE FLTK_FLUID_EXECUTABLE)
214         mark_as_advanced(FORCE FLTK_FORMS_LIBRARY)
215         mark_as_advanced(FORCE FLTK_GL_LIBRARY)
216         mark_as_advanced(FORCE FLTK_IMAGES_LIBRARY)
217         mark_as_advanced(FORCE FLTK_INCLUDE_DIR)
218         mark_as_advanced(FORCE FLTK_MATH_LIBRARY)
219 endif(FLTK_FOUND)
221 if(NTK_FOUND)
222         mark_as_advanced(FORCE NTK_BASE_LIBRARY)
223         mark_as_advanced(FORCE NTK_CONFIG_SCRIPT)
224         mark_as_advanced(FORCE NTK_DIR)
225         mark_as_advanced(FORCE FLTK_FLUID_EXECUTABLE)
226         mark_as_advanced(FORCE NTK_FORMS_LIBRARY)
227         mark_as_advanced(FORCE NTK_GL_LIBRARY)
228         mark_as_advanced(FORCE NTK_IMAGES_LIBRARY)
229         mark_as_advanced(FORCE NTK_INCLUDE_DIR)
230         mark_as_advanced(FORCE NTK_MATH_LIBRARY)
231 endif(NTK_FOUND)
233 if(FltkGui)
234         #UGLY WORKAROUND
235         find_program (FLTK_CONFIG fltk-config)
236         if (FLTK_CONFIG)
237                 execute_process (COMMAND ${FLTK_CONFIG} --use-images --ldflags OUTPUT_VARIABLE FLTK_LDFLAGS)
238                 string(STRIP ${FLTK_LDFLAGS} FLTK_LIBRARIES)
239         endif()
241         message(STATUS ${FLTK_LDFLAGS})
244         set(GUI_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_LIBRARIES} ${OPENGL_LIBRARIES} zynaddsubfx_gui)
246         add_definitions(-DFLTK_GUI)
247         message(STATUS "Will build FLTK gui")
249         include_directories(
250                         ${FLTK_INCLUDE_DIR}
251                         "${CMAKE_CURRENT_SOURCE_DIR}/UI"
252                         "${CMAKE_CURRENT_BINARY_DIR}/UI"
253                         )
255         add_subdirectory(UI)
256 endif()
258 if(NtkGui)
260         find_program( FLTK_FLUID_EXECUTABLE ntk-fluid)
261         
262         message(STATUS ${NTK_LDFLAGS} ${NTK_IMAGES_LDFLAGS})
264         set(GUI_LIBRARIES ${NTK_LIBRARIES} ${NTK_IMAGES_LIBRARIES} ${OPENGL_LIBRARIES} zynaddsubfx_gui)
266         add_definitions(-DNTK_GUI)
268         message(STATUS "Will build NTK gui")
270         include_directories(
271                         ${NTK_INCLUDE_DIRS}
272                         "${CMAKE_CURRENT_SOURCE_DIR}/UI"
273                         "${CMAKE_CURRENT_BINARY_DIR}/UI"
274                         )
276         add_subdirectory(UI)
277 endif()
279 ########### General section ##############
280 # Following this should be only general compilation code, and no mention
281 # of module-specific variables
283 link_directories(${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS} ${NTK_LIBRARY_DIRS})
285 include_directories(
286         ${CMAKE_CURRENT_SOURCE_DIR}
287         ${CMAKE_CURRENT_BINARY_DIR}
288         )
292 set(NONGUI_LIBRARIES
293         zynaddsubfx_misc
294         zynaddsubfx_synth
295         zynaddsubfx_effect
296         zynaddsubfx_params
297         zynaddsubfx_dsp
298         zynaddsubfx_nio
299         )
301 add_subdirectory(Misc)
302 add_subdirectory(Synth)
303 add_subdirectory(Effects)
304 add_subdirectory(Params)
305 add_subdirectory(DSP)
306 if(CompileTests)
307         add_subdirectory(Tests)
308 endif(CompileTests)
309 add_subdirectory(Nio)
311 add_library(zynaddsubfx_core STATIC
312         ${zynaddsubfx_dsp_SRCS}
313         ${zynaddsubfx_effect_SRCS}
314         ${zynaddsubfx_misc_SRCS}
315         ${zynaddsubfx_params_SRCS}
316         ${zynaddsubfx_synth_SRCS}
317         )
319 target_link_libraries(zynaddsubfx_core
320         ${ZLIB_LIBRARIES}
321         ${FFTW_LIBRARIES}
322         ${MXML_LIBRARIES}
323         ${OS_LIBRARIES}
324         pthread)
326 message(STATUS "using link directories: ${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS}")
329 add_executable(zynaddsubfx main.cpp)
331 target_link_libraries(zynaddsubfx
332         zynaddsubfx_nio
333     zynaddsubfx_core
334         ${GUI_LIBRARIES}
335         ${NIO_LIBRARIES}
336         ${AUDIO_LIBRARIES}
337         )
339 if (DssiEnable)
340         add_library(zynaddsubfx_dssi SHARED
341                 Output/DSSIaudiooutput.cpp
342                 )
344         target_link_libraries(zynaddsubfx_dssi
345         zynaddsubfx_core
346                 ${NIO_LIBRARIES}
347                 ${AUDIO_LIBRARIES}
348                 ${OS_LIBRARIES}
349                 )
350         if (${CMAKE_SIZEOF_VOID_P} EQUAL "8")
351                 install(TARGETS zynaddsubfx_dssi LIBRARY DESTINATION lib64/dssi/)
352         else ()
353                 install(TARGETS zynaddsubfx_dssi LIBRARY DESTINATION lib/dssi/)
354         endif ()
355 endif()
357 message(STATUS "Link libraries: ${ZLIB_LIBRARY} ${FFTW_LIBRARY} ${MXML_LIBRARIES} ${AUDIO_LIBRARIES} ${OS_LIBRARIES}")
358 install(TARGETS zynaddsubfx
359         RUNTIME DESTINATION bin
360         )
362 if(NtkGui)
363 install(DIRECTORY ../pixmaps DESTINATION share/zynaddsubfx)
364 add_definitions(-DPIXMAP_PATH="${CMAKE_INSTALL_PREFIX}/share/zynaddsubfx/pixmaps/")
365 add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
366 endif(NtkGui)
368 include(CTest)