fixed: define build_type before package configure, disable cuda by default
[opensg.git] / CMake / ExternalProjectHelper.cmake
blob17904318d03942c2516f64af28c03d93814e63aa
2 ####################
3 # WARNING WARNING
5 # HIGHLY IN PROGRESS
6 ####################
8 INCLUDE(OpenSGVersion)
10 MACRO(OSG_INIT)
12   SET(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
14   MESSAGE(STATUS "ARGS: ${ARGC} | ${ARGV} ")
15   MESSAGE(STATUS "OPT : ${OSG_OPTIONAL_COMPONENTS}")
17   SET(_OSG_COMPONENTS ${ARGV})
19   SET(OSG_PLATFORM_64 0)
20   SET(OSG_PLATFORM_32 0)
21   SET(OSG_LIBDIR_SUFFIX "")
23   IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
24     SET(OSG_PLATFORM_64 1)
25     SET(OSG_LIBDIR_SUFFIX "64")
26     IF(NOT WIN32)
27       SET(OSG_LIBDIR_BASE_SUFFIX "64")
28     ENDIF()
29   ELSE()
30     SET(OSG_PLATFORM_32 1)
31   ENDIF()
33   IF(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
34     OPTION(OSG_DISABLE_MS_ITERATOR_DEBUGGING "" ON)
35   ELSE(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
36     OPTION(OSG_DISABLE_MS_ITERATOR_DEBUGGING "" OFF)
37   ENDIF(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
39   OPTION(OSG_ENABLE_CUDA "Build OpenSG with CUDA support" OFF)
41   IF(NOT WIN32 AND NOT CMAKE_BUILD_TYPE)
42     SET(CMAKE_BUILD_TYPE Debug CACHE STRING
43         "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
44         FORCE)
45   ENDIF(NOT WIN32 AND NOT CMAKE_BUILD_TYPE)
47   INCLUDE(OpenSGExtDep)
49   #############
50   #### OpenSG
52   LIST(FIND _OSG_COMPONENTS OSGFileIO _OSG_USE_FILEIO)
53   LIST(FIND _OSG_COMPONENTS OSGImageFileIO _OSG_USE_IMAGEFILEIO)
54   LIST(FIND _OSG_COMPONENTS OSGContribComputeBase _OSG_USE_CONTRIBCOMPUTE)
55   LIST(FIND _OSG_COMPONENTS OSGContribCSM _OSG_USE_CONTRIBCSM)
56   LIST(FIND _OSG_COMPONENTS OSGCluster _OSG_USE_CLUSTER)
57   LIST(FIND _OSG_COMPONENTS OSGWindowQT4 _OSG_USE_QT)
58   LIST(FIND _OSG_COMPONENTS OSGSystem _OSG_USE_SYSTEM)
60   IF(_OSG_USE_CONTRIBCOMPUTE EQUAL -1 AND NOT _OSG_USE_SYSTEM EQUAL -1)
61     LIST(FIND OSGSystem_DEP_LIB CUDA_CUDART_LIBRARY _OSG_USE_CONTRIBCOMPUTE)
62   ENDIF()
64   IF(NOT _OSG_USE_CONTRIBCSM EQUAL -1)
65     IF(_OSG_USE_FILEIO EQUAL -1)
66       LIST(APPEND _OSG_COMPONENTS OSGFileIO)
67       SET(_OSG_USE_FILEIO 1)
68     ENDIF(_OSG_USE_FILEIO EQUAL -1)
70     IF(_OSG_USE_CLUSTER EQUAL -1)
71       LIST(APPEND _OSG_COMPONENTS OSGCluster)
72       SET(_OSG_USE_CLUSTER 1)
73     ENDIF(_OSG_USE_CLUSTER EQUAL -1)
74   ENDIF(NOT _OSG_USE_CONTRIBCSM EQUAL -1)
76   FIND_PACKAGE(OpenSG REQUIRED COMPONENTS ${_OSG_COMPONENTS})
78   IF(OpenSG_DIR)
79     IF(NOT OSG_COMPILER_DEFAULTS)
80       INCLUDE(SetupCompiler)
81       SET(OSG_COMPILER_DEFAULTS 1 CACHE INTERNAL "Defaults written" FORCE ) #INTERNAL
82     ENDIF(NOT OSG_COMPILER_DEFAULTS)
84     INCLUDE(UpdateCompiler)
86     INCLUDE(BuildFunctions)
87     INCLUDE(ConfigurePackages)
89     INCLUDE_DIRECTORIES(${OpenSG_INCLUDE_DIRS})
91   ENDIF(OpenSG_DIR)
93   #############
94   #### Support
95   #############
97   IF(UNIX)
98     FIND_LIBRARY(OSG_THREAD_LIB NAMES pthread)
99     FIND_LIBRARY(OSG_DL_LIB     NAMES dl)
101     OSG_ADD_OPT(OSG_THREAD_LIB)
102     OSG_ADD_OPT(OSG_DL_LIB)
103   ENDIF(UNIX)
105   IF(APPLE)
106     FIND_LIBRARY(OSG_APPLICATIONSERVICES_FRAMEWORK NAMES ApplicationServices)
107     FIND_LIBRARY(OSG_CARBON_FRAMEWORK NAMES Carbon)
108     FIND_LIBRARY(OSG_COCOA_FRAMEWORK NAMES Cocoa)
109   ENDIF(APPLE)
111   #############
112   #### OpenGL
113   #############
115   FIND_PACKAGE(OpenGL REQUIRED)
117   OSG_ADD_OPT(OPENGL_gl_LIBRARY)
118   OSG_ADD_OPT(OPENGL_glu_LIBRARY)
120   #############
121   #### GLUT
122   #############
124   OSG_CONFIGURE_GLUT()
126   IF(GLUT_FOUND)
127     OSG_SET(OSG_WITH_GLUT 1)
128     OSG_SET(OSG_GLUT_INC_DIR ${GLUT_INCLUDE_DIR})
129     OSG_SET(OSG_GLUT_LIBS ${GLUT_LIBRARIES})
130   ELSE(GLUT_FOUND)
131     OSG_SET(OSG_WITH_GLUT 0)
132     OSG_SET(OSG_GLUT_INC_DIR "")
133     OSG_SET(OSG_GLUT_LIBS "")
134   ENDIF(GLUT_FOUND)
136   #############
137   #### Python
138   #############
140   FIND_PACKAGE(PythonInterp)
142   ##########
143   #### boost
144   ##########
146   OSG_CONFIGURE_BOOST()
147   OSG_CONFIGURE_ZLIB()
149   MESSAGE(STATUS "Need fileio deps    : ${_OSG_USE_FILEIO}")
150   MESSAGE(STATUS "Need imgfileio deps : ${_OSG_USE_IMAGEFILEIO}")
151   MESSAGE(STATUS "Need cuda deps      : ${_OSG_USE_CONTRIBCOMPUTE}")
152   MESSAGE(STATUS "Need cluster        : ${_OSG_USE_CLUSTER}")
153   MESSAGE(STATUS "Need csm            : ${_OSG_USE_CONTRIBCSM}")
154   MESSAGE(STATUS "Need qt             : ${_OSG_USE_QT}")
156   IF(NOT _OSG_USE_IMAGEFILEIO EQUAL -1)
158     MESSAGE(STATUS "Configure image file io")
160     OSG_CONFIGURE_TIFF()
161     OSG_CONFIGURE_PNG()
162     OSG_CONFIGURE_JPEG()
163     OSG_CONFIGURE_OPENEXR()
164   ENDIF(NOT _OSG_USE_IMAGEFILEIO EQUAL -1)
166   IF(NOT _OSG_USE_FILEIO EQUAL -1)
168     MESSAGE(STATUS "Configure file io")
170     OSG_CONFIGURE_COLLADA()
172     IF(COLLADA_FOUND)
174       IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR 
175          CMAKE_BUILD_TYPE STREQUAL "DebugOpt")
177         OSG_SET(OSG_COLLADA_LIBS ${COLLADA_LIBRARY_DEBUG})
179       ELSE()
181         OSG_SET(OSG_COLLADA_LIBS ${COLLADA_LIBRARY_RELEASE})
183       ENDIF()
185       IF(WIN32)
186         SET(OSG_COLLADA_LIBS ${OSG_COLLADA_TARGETS})
187       ENDIF(WIN32)
189     ELSE(COLLADA_FOUND)
191         SET(OSG_COLLADA_LIBS "")
193     ENDIF(COLLADA_FOUND)
194   ENDIF(NOT _OSG_USE_FILEIO EQUAL -1)
196   IF(NOT _OSG_USE_CONTRIBCOMPUTE EQUAL -1) # AND OSG_ENABLE_CUDA)
198     MESSAGE(STATUS "Configure cuda deps")
200     FIND_PACKAGE(CUDA QUIET REQUIRED)
202     INCLUDE(ConfigurePackages.OSGContribComputeBase)
204     IF(NOT OSG_BUILD_DEPENDEND)
205       OSG_CONFIGURE_NVSDKCOMMON()
206       OSG_CONFIGURE_NVOCLUTILS()
207       OSG_CONFIGURE_CUDACOMMON()
208       OSG_CONFIGURE_CUDAUTIL()
209       OSG_CONFIGURE_CUDPP()
210       OSG_CONFIGURE_CUDAPARTSDK()
211     ENDIF(NOT OSG_BUILD_DEPENDEND)
213     MESSAGE(STATUS "NV Status: NV:${OSG_NVSDKCOMMON_FOUND}")
214     MESSAGE(STATUS "Cuda Status: CC:${OSG_CUDACOMMON_FOUND} CU:${OSG_CUDAUTIL_FOUND} CP:${OSG_CUDPP_FOUND}")
215     MESSAGE(STATUS "OCL Status : NV:${OSG_NVOCLUTILS_FOUND}")
217     IF(CUDA_FOUND)
218       SET(OSG_WITH_CUDA 1)
219     ENDIF(CUDA_FOUND)
220     IF(OPENCL_FOUND)
221       SET(OSG_WITH_OPENCL 1)
222     ENDIF(OPENCL_FOUND)
224   ENDIF(NOT _OSG_USE_CONTRIBCOMPUTE EQUAL -1) # AND OSG_ENABLE_CUDA)
226   IF(NOT _OSG_USE_QT EQUAL -1)
228     #############
229     #### QT
230     #############
232     OSG_CONFIGURE_QT()
233   ENDIF()
235   #############
236   #### Python
237   #############
239   FIND_PACKAGE(PythonLibs)
241   OSG_ADD_OPT(PYTHON_INCLUDE_PATH)
242   OSG_ADD_OPT(PYTHON_LIBRARY)
244   IF(Boost_FOUND AND PYTHONLIBS_FOUND)
246     FIND_PACKAGE(Boost COMPONENTS python)
248     IF(Boost_FOUND AND WIN32)
250       SET(OSG_BOOST_PYTHON_TARGETS )
251       OSG_ADD_IMPORT_LIB(OSG_BOOST_PYTHON_TARGETS Boost_PYTHON_LIBRARY)
252       SET(OSG_BOOST_PYTHON_LIBS ${OSG_BOOST_PYTHON_TARGETS})
253       
254     ELSE(Boost_FOUND AND WIN32)
256       IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR 
257          CMAKE_BUILD_TYPE STREQUAL "DebugOpt")
259         SET(OSG_BOOST_PYTHON_LIBS ${Boost_PYTHON_LIBRARY_DEBUG})
261       ELSE()
262         SET(OSG_BOOST_PYTHON_LIBS ${Boost_PYTHON_LIBRARY_RELEASE})
263       ENDIF()
265     ENDIF(Boost_FOUND AND WIN32)
267     # We ignore if boost python fails, we catch that somewhere else
268     # so if we get here Boost_FOUND was true in the first place
269     SET(Boost_FOUND TRUE)
271   ENDIF(Boost_FOUND AND PYTHONLIBS_FOUND)
274   CHECK_BUILD_DIR()
276   SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
277   SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
278   SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
280   ADD_CUSTOM_TARGET(OSGAll)
282   # optional pass for test programs
283 #  IF(OSGBUILD_TESTS)
284     ADD_CUSTOM_TARGET(OSGAllTests)
285     ADD_DEPENDENCIES(OSGAll OSGAllTests)
286 #  ENDIF(OSGBUILD_TESTS)
288   ADD_CUSTOM_TARGET(OSGAllApps)
289   ADD_DEPENDENCIES(OSGAll OSGAllApps)
292   IF(WIN32)
293     OSG_OPTION(OSG_USE_SEPARATE_LIBDIRS "" ON)
294   ENDIF(WIN32)
296   IF(OSGEXCLUDE_TESTS_FROM_ALL)
297     SET(OSGEXCLUDE_TESTS EXCLUDE_FROM_ALL)
298   ELSE()
299     SET(OSGEXCLUDE_TESTS "")
300   ENDIF()
302   IF(OSGEXCLUDE_UNITTESTS_FROM_ALL)
303     SET(OSGEXCLUDE_UNITTESTS EXCLUDE_FROM_ALL)
304   ELSE()
305     SET(OSGEXCLUDE_UNITTESTS "")
306   ENDIF()
308   IF(OSGEXCLUDE_EXAMPLES_SIMPLE_FROM_ALL)
309     SET(OSGEXCLUDE_EXAMPLES_SIMPLE EXCLUDE_FROM_ALL)
310   ELSE()
311     SET(OSGEXCLUDE_EXAMPLES_SIMPLE "")
312   ENDIF()
314   IF(OSGEXCLUDE_EXAMPLES_ADVANCED_FROM_ALL)
315     SET(OSGEXCLUDE_EXAMPLES_ADVANCED EXCLUDE_FROM_ALL)
316   ELSE()
317     SET(OSGEXCLUDE_EXAMPLES_ADVANCED "")
318   ENDIF()
320 ENDMACRO(OSG_INIT)
323 MACRO(_OSG_SETUP_BUILD)
325   # when adding passes, make sure to add a corresponding pass directory variable
326   # OSG_PASSDIR_${PASSNAME} - this variable may not be empty!
327   SET(OSG_CMAKE_PASSES "OSGCOLLECT" "OSGSETUP")
329   SET(OSG_PASSDIR_OSGCOLLECT "Collect")
330   SET(OSG_PASSDIR_OSGSETUP   "Build")
332   ###############
333   # Clean
334   ###############
336   FILE(GLOB OSG_OLD_BUILD_FILES  "${CMAKE_BINARY_DIR}/*.cmake")
338   IF(OSG_OLD_BUILD_FILES)
339     FILE(REMOVE ${OSG_OLD_BUILD_FILES})
340   ENDIF(OSG_OLD_BUILD_FILES)
342 #  FOREACH(_OSG_COMPONENT ${STORED_PROJECTS})
343   FOREACH(_OSG_COMPONENT ${_OSG_COMPONENTS})
344     MESSAGE(STATUS "FAKE : ${CMAKE_BINARY_DIR}/${_OSG_COMPONENT}.cmake")
345     FILE(WRITE ${CMAKE_BINARY_DIR}/${_OSG_COMPONENT}.cmake "#dummy")
347     SET(_OSG_COMPONENT_LI )
349     FOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_OSG_LIB})
350       LIST(APPEND _OSG_COMPONENT_LI ${_OSG_COMPONENT_DEP})
351     ENDFOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_OSG_LIB})
353     FOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_LIB})
354       IF(TARGET ${_OSG_COMPONENT_DEP})
355         LIST(APPEND _OSG_COMPONENT_LI ${_OSG_COMPONENT_DEP})
356       ELSE(TARGET ${_OSG_COMPONENT_DEP})
357         LIST(APPEND _OSG_COMPONENT_LI ${${_OSG_COMPONENT_DEP}})
358       ENDIF(TARGET ${_OSG_COMPONENT_DEP})
359     ENDFOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_LIB})
361     IF(_OSG_COMPONENT_LI AND TARGET ${_OSG_COMPONENT})
362       SET_TARGET_PROPERTIES(${_OSG_COMPONENT} PROPERTIES
363                             IMPORTED_LINK_INTERFACE_LIBRARIES "${_OSG_COMPONENT_LI}")
364     ENDIF(_OSG_COMPONENT_LI AND TARGET ${_OSG_COMPONENT})
366   ENDFOREACH(_OSG_COMPONENT ${STORE_PROJECTS})
368   ###############
369   # Tests
370   ###############
372   # optional pass for test programs
373   LIST(APPEND OSG_CMAKE_PASSES "OSGSETUPTEST")
374   SET(OSG_PASSDIR_OSGSETUPTEST "Test")
376   OSG_OPTION(OSG_ENABLE_FCD2CODE "" ON)
377   OSG_OPTION(OSG_FCD2CODE_WRITE_CLASS "" OFF)
379   ADD_CUSTOM_TARGET(OSGAllLibs)
380   ADD_CUSTOM_TARGET(OSGAllContribLibs)
382   SET(OSG_MAIN_LIB_TARGET OSGAllContribLibs)
384   ADD_DEPENDENCIES(OSGAllLibs OSGAllContribLibs)
385   ADD_DEPENDENCIES(OSGAll OSGAllLibs)
387 ENDMACRO(_OSG_SETUP_BUILD)
389 MACRO(_OSG_RUN_PASSES)
391   FOREACH(LIBCONFIGFILE ${OSG_LIBRARY_CONFIG_FILES})
392     GET_FILENAME_COMPONENT(LIBCONFIGDIR "${LIBCONFIGFILE}" PATH)
393     GET_FILENAME_COMPONENT(LIBFILENAME  "${LIBCONFIGFILE}" NAME)
394     STRING(REPLACE "CMakeLists.Lib." "" LIBFILENAME "${LIBFILENAME}")
395     STRING(REPLACE ".txt"            "" LIBFILENAME "${LIBFILENAME}")
397     IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.Prepare.cmake)
398       INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.Prepare.cmake)
399     ENDIF()
400   ENDFOREACH(LIBCONFIGFILE)
402   # run build passes
403   FOREACH(PASS ${OSG_CMAKE_PASSES})
404     SET(OSG_CMAKE_PASS ${PASS})
406     MESSAGE(STATUS "\nPASS : ${OSG_CMAKE_PASS} in ${OSG_PASSDIR_${PASS}}\n")
408     FOREACH(LIBCONFIGFILE ${OSG_LIBRARY_CONFIG_FILES})
409         GET_FILENAME_COMPONENT(LIBCONFIGDIR "${LIBCONFIGFILE}" PATH)
410         GET_FILENAME_COMPONENT(LIBFILENAME  "${LIBCONFIGFILE}" NAME)
411         STRING(REPLACE "CMakeLists.Lib." "" LIBFILENAME "${LIBFILENAME}")
412         STRING(REPLACE ".txt"            "" LIBFILENAME "${LIBFILENAME}")
414         ADD_SUBDIRECTORY("${LIBCONFIGDIR}" "${OSG_PASSDIR_${PASS}}/${LIBFILENAME}")
416     ENDFOREACH(LIBCONFIGFILE)
417    
418   ENDFOREACH()
420 ENDMACRO(_OSG_RUN_PASSES)
422 MACRO(OSG_COLLECT_LIBS CURRENT_DIR_ONLY)
424   _OSG_SETUP_BUILD()
426   ###############
427   # Passes
428   ###############
430   SET(_OSG_CURRDIR_ONLY ${CURRENT_DIR_ONLY})
432   # Find files describing libraries to build, but make sure base
433   # and system are processed first
435   IF(_OSG_CURRDIR_ONLY)
436     FILE(GLOB OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
437          "./*CMakeLists.Lib.*.txt")
438   ELSE()
439     FILE(GLOB_RECURSE OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
440          "./*CMakeLists.Lib.*.txt")
441   ENDIF()
443   IF(OSG_EXCLUDE_FROM_BUILD)
444     LIST(REMOVE_ITEM OSG_LIBRARY_CONFIG_FILES ${OSG_EXCLUDE_FROM_BUILD})
445   ENDIF()
447   _OSG_RUN_PASSES()
449 ENDMACRO(OSG_COLLECT_LIBS CURRENT_DIR_ONLY)
451 MACRO(OSG_DOCOLLECT_LIBS)
453   _OSG_SETUP_BUILD()
455   ###############
456   # Passes
457   ###############
459   SET(_OSG_CURRDIR_ONLY ${CURRENT_DIR_ONLY})
461   SET(_OSG_TMPLIST ${ARGV})
462   MATH(EXPR _OSG_LISTCOUNT ${ARGC}-1)
464   # Find files describing libraries to build, but make sure base
465   # and system are processed first
467   SET(_OSG_TMPLIST ${ARGV})
468   MATH(EXPR _OSG_LISTCOUNT ${ARGC}-1)
470   FOREACH(_LOOPC RANGE 0 ${_OSG_LISTCOUNT} 2)
472     MATH(EXPR _LOOPN ${_LOOPC}+1)
474     LIST(GET _OSG_TMPLIST ${_LOOPC} OSGLIB_SOURCE_DIR)
475     LIST(GET _OSG_TMPLIST ${_LOOPN} _OSG_CURRDIR_ONLY)
477     IF(_OSG_CURRDIR_ONLY)
478       FILE(GLOB _OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
479            "${${OSGLIB_SOURCE_DIR}}/*CMakeLists.Lib.*.txt")
480     ELSE()
481       FILE(GLOB_RECURSE _OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
482            "${${OSGLIB_SOURCE_DIR}}/*CMakeLists.Lib.*.txt")
483     ENDIF()
485     LIST(APPEND OSG_LIBRARY_CONFIG_FILES ${_OSG_LIBRARY_CONFIG_FILES})
486   ENDFOREACH()
488   IF(OSG_EXCLUDE_FROM_BUILD)
489     LIST(REMOVE_ITEM OSG_LIBRARY_CONFIG_FILES ${OSG_EXCLUDE_FROM_BUILD})
490   ENDIF()
492   _OSG_RUN_PASSES()
494 ENDMACRO(OSG_DOCOLLECT_LIBS)