fixed: auto_ptr -> unique_ptr
[opensg.git] / CMake / OSGExternalProjectHelper.cmake
blob4498a3472527deb816855ed9abcaf69d06b76169
2 ####################
3 # WARNING WARNING
5 # HIGHLY IN PROGRESS
6 ####################
8 INCLUDE(OpenSGVersion)
10 INCLUDE(OSGCommonConfig)
12 SET(OSG2_PROJECT TRUE CACHE INTERNAL "" FORCE)
13 SET(OSG_EXTERNAL_PROJECT TRUE CACHE INTERNAL "" FORCE)
15 MACRO(OSG_INIT)
17   INCLUDE(OSGCommonOptions)
19   MESSAGE(STATUS "ARGS: ${ARGC} | ${ARGV} ")
20   MESSAGE(STATUS "OPT : ${OSG_OPTIONAL_COMPONENTS}")
22   SET(_OSG_COMPONENTS ${ARGV})
24   OSG_COMMON_OPTIONS()
25   OSG_COMMON_OPTIONS_CONFIGURED()
27   SET(OSG_PLATFORM_64 0)
28   SET(OSG_PLATFORM_32 0)
29   SET(OSG_LIBDIR_SUFFIX "")
31   IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
32     SET(OSG_PLATFORM_64 1)
33     SET(OSG_LIBDIR_SUFFIX "64")
34     IF(NOT WIN32)
35       SET(OSG_LIBDIR_BASE_SUFFIX "64")
36     ENDIF()
37   ELSE()
38     SET(OSG_PLATFORM_32 1)
39   ENDIF()
41   IF(${CMAKE_CXX_PLATFORM_ID} STREQUAL "Linux")
42     SET(LINUX 1)
43   ENDIF()
45   IF(WIN32)
46     SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugOpt;ReleaseNoOpt"
47                                   CACHE STRING "OpenSG Build Types" FORCE )
48   ELSE()
49     SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugGV"
50                                   CACHE STRING "OpenSG Build Types" FORCE )
51   ENDIF(WIN32)
53   IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
54      CMAKE_BUILD_TYPE STREQUAL "DebugGV")
55     SET(OSG_LIBDIR_SUFFIX "${OSG_LIBDIR_SUFFIX}/debug")
56     SET(OSG_LIBDIR_BUILD_TYPE_SUFFIX "debug")
57   ENDIF()
59   IF(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
60     OPTION(OSG_DISABLE_MS_ITERATOR_DEBUGGING "" ON)
61   ELSE(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
62     OPTION(OSG_DISABLE_MS_ITERATOR_DEBUGGING "" OFF)
63   ENDIF(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
66   IF(NOT WIN32 AND NOT CMAKE_BUILD_TYPE)
67     SET(CMAKE_BUILD_TYPE Debug CACHE STRING
68         "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
69         FORCE)
70   ENDIF(NOT WIN32 AND NOT CMAKE_BUILD_TYPE)
72   # Disable boost cmake config, as it screws up OpenSG's boost config
74   SET(Boost_NO_BOOST_CMAKE TRUE CACHE INTERNAL "" FORCE)
75   SET(Boost_ADDITIONAL_VERSIONS "1.54.0" 
76                                 "1.54"
77                                 "1.53.0" 
78                                 "1.53"
79                                 "1.52.0" 
80                                 "1.52"
81                                 "1.51.0" 
82                                 "1.51"
83                                 "1.50.0"
84                                 "1.50"
85                                 "1.49.0" 
86                                 "1.49"
87                                 "1.48.0"
88                                 "1.48"
89                                 "1.47.0"
90                                 "1.47.0")
92   SET(OSG_BUILD_ACTIVE TRUE)
93   ADD_DEFINITIONS(-D OSG_BUILD_ACTIVE)
95   IF(NOT WIN32)
96     SET(OSG_SUPPORT_INC_SUBDIR "/OpenSG")
97   ENDIF()
99   OSG_COMMON_TARGETS()
101   INCLUDE(OpenSGExtDep)
103   #############
104   #### OpenSG
106   SET(_OSG_PREF "OSG")
108   LIST(FIND _OSG_COMPONENTS OSG2Base _OSG_USE_OSG2_NAME)
110   IF(NOT _OSG_USE_OSG2_NAME EQUAL -1)
111     SET(_OSG_PREF "OSG2")
112   ENDIF()
114   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}FileIO _OSG_USE_FILEIO)
115   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}ImageFileIO _OSG_USE_IMAGEFILEIO)
116   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}ContribComputeBase _OSG_USE_CONTRIBCOMPUTE)
117   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}ContribCSM _OSG_USE_CONTRIBCSM)
118   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}Cluster _OSG_USE_CLUSTER)
119   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}WindowQT4 _OSG_USE_QT)
120   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}System _OSG_USE_SYSTEM)
121   LIST(FIND _OSG_COMPONENTS ${_OSG_PREF}ContribWebInterface _OSG_USE_WEBINTERFACE)
123   IF(_OSG_USE_CONTRIBCOMPUTE EQUAL -1 AND NOT _OSG_USE_SYSTEM EQUAL -1)
124     LIST(FIND ${_OSG_PREF}System_DEP_LIB CUDA_CUDART_LIBRARY _OSG_USE_CONTRIBCOMPUTE)
125   ENDIF()
127   IF(NOT _OSG_USE_CONTRIBCSM EQUAL -1)
128     IF(_OSG_USE_FILEIO EQUAL -1)
129       LIST(APPEND _OSG_COMPONENTS ${_OSG_PREF}FileIO)
130       SET(_OSG_USE_FILEIO 1)
131     ENDIF(_OSG_USE_FILEIO EQUAL -1)
133     IF(_OSG_USE_CLUSTER EQUAL -1)
134       LIST(APPEND _OSG_COMPONENTS ${_OSG_PREF}Cluster)
135       SET(_OSG_USE_CLUSTER 1)
136     ENDIF(_OSG_USE_CLUSTER EQUAL -1)
138     IF(_OSG_USE_WEBINTERFACE EQUAL -1)
139       LIST(FIND OSGContribCSM_DEP_OSG_LIB ${_OSG_PREF}ContribWebInterface 
140                 _OSG_USE_WEBINTERFACE)
142       IF(NOT _OSG_USE_WEBINTERFACE EQUAL -1)
143         LIST(APPEND _OSG_COMPONENTS ${_OSG_PREF}ContribWebInterface)
144       ENDIF()
145     ENDIF()
147   ENDIF(NOT _OSG_USE_CONTRIBCSM EQUAL -1)
149   IF(NOT OSG_EXTPROJ_NO_OSGINCLUDE)
150     FIND_PACKAGE(OpenSG REQUIRED COMPONENTS ${_OSG_COMPONENTS})
151   ELSE()
152     FIND_PACKAGE(OpenSG REQUIRED)
153   ENDIF()
155   IF(OpenSG_DIR)
156     IF(NOT OSG_COMPILER_DEFAULTS)
157       INCLUDE(OSGSetupCompiler)
158       SET(OSG_COMPILER_DEFAULTS 1 CACHE INTERNAL "Defaults written" FORCE ) #INTERNAL
159     ENDIF(NOT OSG_COMPILER_DEFAULTS)
161     INCLUDE(OSGUpdateCompiler)
163     INCLUDE(OSGBuildFunctions)
164     INCLUDE(OSGConfigurePackages)
166     IF(NOT OSG_EXTPROJ_NO_OSGINCLUDE)
167       INCLUDE_DIRECTORIES(${OpenSG_INCLUDE_DIRS})
168     ELSE()
169       LIST(APPEND OSG_GLOBAL_DEP_DEFS "OSGEXT_NO_OSG_INCLUDES")
170     ENDIF()
172     OSG_CONFIGURE_SUPPORT()
174   ENDIF(OpenSG_DIR)
176   #############
177   #### Support
178   #############
180   IF(UNIX)
181     FIND_LIBRARY(OSG_THREAD_LIB NAMES pthread)
182     FIND_LIBRARY(OSG_DL_LIB     NAMES dl)
183     FIND_LIBRARY(OSG_RT_LIB     NAMES rt)
185     OSG_ADD_OPT(OSG_THREAD_LIB)
186     OSG_ADD_OPT(OSG_DL_LIB)
187     OSG_ADD_OPT(OSG_RT_LIB)
188   ENDIF(UNIX)
190   IF(APPLE)
191     FIND_LIBRARY(OSG_APPLICATIONSERVICES_FRAMEWORK NAMES ApplicationServices)
192     FIND_LIBRARY(OSG_CARBON_FRAMEWORK NAMES Carbon)
193     FIND_LIBRARY(OSG_COCOA_FRAMEWORK NAMES Cocoa)
194   ENDIF(APPLE)
196   #############
197   #### OpenGL
198   #############
200   IF(OSG_EXT_OPENGL_OPTIONAL)
201     FIND_PACKAGE(OpenGL)
202   ELSE()
203     FIND_PACKAGE(OpenGL REQUIRED)
204   ENDIF()
206   IF(OpenGL_FOUND)
207     OSG_ADD_OPT(OPENGL_gl_LIBRARY)
208     OSG_ADD_OPT(OPENGL_glu_LIBRARY)
209   ENDIF()
211   #############
212   #### X11
213   #############
215   FIND_PACKAGE(X11)
217   IF(X11_FOUND)
218     OSG_SET(OSG_X_LIBS ${X11_X11_LIB})
219     OSG_SET(OSG_X_INC_DIR ${X11_X11_INCLUDE_PATH})
220   ENDIF(X11_FOUND)
222   OSG_ADD_OPT(X11_FOUND)
224   #############
225   #### GLUT
226   #############
228   OSG_CONFIGURE_GLUT()
230   IF(GLUT_FOUND)
231     OSG_SET(OSG_WITH_GLUT 1)
232     OSG_SET(OSG_GLUT_INC_DIR ${GLUT_INCLUDE_DIR})
233     OSG_SET(OSG_GLUT_LIBS ${GLUT_LIBRARIES})
234   ELSE(GLUT_FOUND)
235     OSG_SET(OSG_WITH_GLUT 0)
236     OSG_SET(OSG_GLUT_INC_DIR "")
237     OSG_SET(OSG_GLUT_LIBS "")
238   ENDIF(GLUT_FOUND)
240   #############
241   #### Python
242   #############
244   FIND_PACKAGE(PythonInterp)
246   ##########
247   #### boost
248   ##########
250   OSG_CONFIGURE_BOOST()
251   OSG_CONFIGURE_ZLIB()
253   MESSAGE(STATUS "Need fileio deps    : ${_OSG_USE_FILEIO}")
254   MESSAGE(STATUS "Need imgfileio deps : ${_OSG_USE_IMAGEFILEIO}")
255   MESSAGE(STATUS "Need cuda deps      : ${_OSG_USE_CONTRIBCOMPUTE}")
256   MESSAGE(STATUS "Need cluster        : ${_OSG_USE_CLUSTER}")
257   MESSAGE(STATUS "Need csm            : ${_OSG_USE_CONTRIBCSM}")
258   MESSAGE(STATUS "Need qt             : ${_OSG_USE_QT}")
260   IF(NOT _OSG_USE_IMAGEFILEIO EQUAL -1)
262     MESSAGE(STATUS "Configure image file io")
264     OSG_CONFIGURE_TIFF()
265     OSG_CONFIGURE_PNG()
266     OSG_CONFIGURE_JPEG()
267     OSG_CONFIGURE_OPENEXR()
269     IF(TIFF_FOUND)
270       SET(OSG_EXTERNAL_IMAGELIBS ${OSG_EXTERNAL_IMAGELIBS} TIFF_LIBRARIES)
271       SET(OSG_EXTERNAL_IMAGEINCS ${OSG_EXTERNAL_IMAGEINCS} TIFF_INCLUDE_DIR)
272       OSG_SET(OSG_WITH_TIF 1)
273       OSG_ADD_OPT(TIFF_LIBRARIES)
274     ENDIF(TIFF_FOUND)
276     IF(PNG_FOUND)
277       SET(OSG_EXTERNAL_IMAGELIBS ${OSG_EXTERNAL_IMAGELIBS} PNG_LIBRARIES)
278       SET(OSG_EXTERNAL_IMAGEINCS ${OSG_EXTERNAL_IMAGEINCS} PNG_INCLUDE_DIR)
279       OSG_SET(OSG_WITH_PNG 1)
280       OSG_ADD_OPT(PNG_INCLUDE_DIR)
281       OSG_ADD_OPT(PNG_LIBRARIES)
282     ENDIF(PNG_FOUND)
284     IF(JPEG_FOUND)
285       SET(OSG_EXTERNAL_IMAGELIBS ${OSG_EXTERNAL_IMAGELIBS} JPEG_LIBRARIES)
286       SET(OSG_EXTERNAL_IMAGEINCS ${OSG_EXTERNAL_IMAGEINCS} JPEG_INCLUDE_DIR)
287       OSG_SET(OSG_WITH_JPG 1)
288       OSG_ADD_OPT(JPEG_LIBRARIES)
289     ENDIF(JPEG_FOUND)
291     IF(GDAL_FOUND)
292       SET(OSG_EXTERNAL_IMAGELIBS ${OSG_EXTERNAL_IMAGELIBS} GDAL_LIBRARIES)
293       SET(OSG_EXTERNAL_IMAGEINCS ${OSG_EXTERNAL_IMAGEINCS} GDAL_INCLUDE_DIR)
294       OSG_SET(OSG_WITH_GDAL 1)
295       OSG_ADD_OPT(GDAL_LIBRARIES)
296     ENDIF(GDAL_FOUND)
298     IF(OPENEXR_FOUND)
299       SET(OSG_EXTERNAL_IMAGELIBS ${OSG_EXTERNAL_IMAGELIBS} OPENEXR_LIBRARIES)
300       SET(OSG_EXTERNAL_IMAGEINCS ${OSG_EXTERNAL_IMAGEINCS} OPENEXR_INCLUDE_DIR)
301       OSG_SET(OSG_WITH_IMF 1)
303       OSG_ADD_OPT(OPENEXR_LIBRARIES)
304       OSG_ADD_OPT(OPENEXR_INCLUDE_DIR)
305     ENDIF(OPENEXR_FOUND)
307   ENDIF(NOT _OSG_USE_IMAGEFILEIO EQUAL -1)
309   IF(NOT _OSG_USE_FILEIO EQUAL -1)
311     MESSAGE(STATUS "Configure file io")
313     OSG_CONFIGURE_COLLADA()
315     IF(COLLADA_FOUND)
317       IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR 
318          CMAKE_BUILD_TYPE STREQUAL "DebugOpt")
320         OSG_SET(OSG_COLLADA_LIBS ${COLLADA_LIBRARY_DEBUG})
322       ELSE()
324         OSG_SET(OSG_COLLADA_LIBS ${COLLADA_LIBRARY_RELEASE})
326       ENDIF()
328       IF(WIN32)
329         SET(OSG_COLLADA_LIBS ${OSG_COLLADA_TARGETS})
330       ENDIF(WIN32)
332     ELSE(COLLADA_FOUND)
334         SET(OSG_COLLADA_LIBS "")
336     ENDIF(COLLADA_FOUND)
337   ENDIF(NOT _OSG_USE_FILEIO EQUAL -1)
339   IF(NOT _OSG_USE_CONTRIBCOMPUTE EQUAL -1) # AND OSG_ENABLE_CUDA)
341     MESSAGE(STATUS "Configure cuda deps")
343     FIND_PACKAGE(CUDA QUIET REQUIRED)
345     INCLUDE(CudaHelper)
347     OSG_SETUP_CUDA_FLAGS()
349     INCLUDE(ConfigurePackages.OSGContribComputeBase)
351     IF(NOT OSG_BUILD_DEPENDEND)
352       OSG_CONFIGURE_NVSDKCOMMON()
353       OSG_CONFIGURE_NVOCLUTILS()
354       OSG_CONFIGURE_CUDACOMMON()
355       OSG_CONFIGURE_CUDAUTIL()
356 #      OSG_CONFIGURE_CUDPP()
357       OSG_CONFIGURE_CUDAPARTSDK(${OSG_SUPPORT_ROOT})
358       
359       IF(NOT OSG_WITH_CUDAPARTSDK AND OSG_EXT_SUPPORT_ROOT)
360         OSG_CONFIGURE_CUDAPARTSDK(${OSG_EXT_SUPPORT_ROOT})
361       ENDIF()
362     ENDIF(NOT OSG_BUILD_DEPENDEND)
364     MESSAGE(STATUS "NV Status: NV:${OSG_NVSDKCOMMON_FOUND}")
365     MESSAGE(STATUS "Cuda Status: CC:${OSG_CUDACOMMON_FOUND} CU:${OSG_CUDAUTIL_FOUND}")
366     MESSAGE(STATUS "OCL Status : NV:${OSG_NVOCLUTILS_FOUND}")
368     OSG_COMMON_CUDA()
370   ENDIF(NOT _OSG_USE_CONTRIBCOMPUTE EQUAL -1) # AND OSG_ENABLE_CUDA)
372   IF(NOT _OSG_USE_QT EQUAL -1)
374     #############
375     #### QT
376     #############
378     IF(WIN32)
379       IF(EXISTS ${OSG_SUPPORT_ROOT}/qt5)
380         SET(QT5_CMAKE_DIR "${OSG_SUPPORT_ROOT}/qt5/lib/cmake" CACHE PATH "" FORCE)
381       ELSEIF(EXISTS ${OSG_SUPPORT_ROOT}/qt4)
382         SET(QT_QMAKE_EXECUTABLE "${OSG_SUPPORT_ROOT}/qt4/bin/qmake.exe" CACHE FILEPATH "" FORCE)
383       ENDIF()
384     ENDIF()
386     OSG_CONFIGURE_QT()
387   ENDIF()
389   #############
390   #### Python
391   #############
393   FIND_PACKAGE(PythonLibs)
395   OSG_ADD_OPT(PYTHON_INCLUDE_PATH)
396   OSG_ADD_OPT(PYTHON_LIBRARY)
398   IF(Boost_FOUND AND PYTHONLIBS_FOUND)
400     FIND_PACKAGE(Boost COMPONENTS python)
402     IF(Boost_FOUND AND WIN32)
404       SET(OSG_BOOST_PYTHON_TARGETS )
405       OSG_ADD_IMPORT_LIB(OSG_BOOST_PYTHON_TARGETS Boost_PYTHON_LIBRARY)
406       SET(OSG_BOOST_PYTHON_LIBS ${OSG_BOOST_PYTHON_TARGETS})
407       
408     ELSE(Boost_FOUND AND WIN32)
410       IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR 
411          CMAKE_BUILD_TYPE STREQUAL "DebugOpt")
413         SET(OSG_BOOST_PYTHON_LIBS ${Boost_PYTHON_LIBRARY_DEBUG})
415       ELSE()
416         SET(OSG_BOOST_PYTHON_LIBS ${Boost_PYTHON_LIBRARY_RELEASE})
417       ENDIF()
419     ENDIF(Boost_FOUND AND WIN32)
421     # We ignore if boost python fails, we catch that somewhere else
422     # so if we get here Boost_FOUND was true in the first place
423     SET(Boost_FOUND TRUE)
425   ENDIF(Boost_FOUND AND PYTHONLIBS_FOUND)
428   CHECK_BUILD_DIR()
430   SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
431   SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
432   SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
435   IF(WIN32)
436     OSG_OPTION(OSG_USE_SEPARATE_LIBDIRS "" ON)
437   ENDIF(WIN32)
439   IF(OSGEXCLUDE_TESTS_FROM_ALL)
440     SET(OSGEXCLUDE_TESTS EXCLUDE_FROM_ALL)
441   ELSE()
442     SET(OSGEXCLUDE_TESTS "")
443   ENDIF()
445   IF(OSGEXCLUDE_UNITTESTS_FROM_ALL)
446     SET(OSGEXCLUDE_UNITTESTS EXCLUDE_FROM_ALL)
447   ELSE()
448     SET(OSGEXCLUDE_UNITTESTS "")
449   ENDIF()
451   IF(OSGEXCLUDE_EXAMPLES_SIMPLE_FROM_ALL)
452     SET(OSGEXCLUDE_EXAMPLES_SIMPLE EXCLUDE_FROM_ALL)
453   ELSE()
454     SET(OSGEXCLUDE_EXAMPLES_SIMPLE "")
455   ENDIF()
457   IF(OSGEXCLUDE_EXAMPLES_ADVANCED_FROM_ALL)
458     SET(OSGEXCLUDE_EXAMPLES_ADVANCED EXCLUDE_FROM_ALL)
459   ELSE()
460     SET(OSGEXCLUDE_EXAMPLES_ADVANCED "")
461   ENDIF()
463   INCLUDE(OSGSetupPython)
465   MESSAGE("FOOOO ${CMAKE_PROJECT_NAME} ${CMAKE_BINARY_DIR}")
467   FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/cmake)
469   STRING(TOUPPER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_UP)
471   STRING(REPLACE "OpenSG" "OSG" CMAKE_PROJECT_NAME_SHORT ${CMAKE_PROJECT_NAME})
472   STRING(TOUPPER ${CMAKE_PROJECT_NAME_SHORT} CMAKE_PROJECT_NAME_SHORT_UP)
474   CONFIGURE_FILE(${OpenSG_DIR}/share/OpenSG/cmake/FindOpenSG.cmake.in
475                  ${CMAKE_BINARY_DIR}/cmake/Find${CMAKE_PROJECT_NAME}.cmake
476                  @ONLY                                      )
478   INSTALL(FILES "${CMAKE_BINARY_DIR}/cmake/Find${CMAKE_PROJECT_NAME}.cmake"
479           DESTINATION share/OpenSG/cmake)
480 #          COMPONENT development_configuration)
482   OSG_SET_CACHE(OSG_EXTRA_EXTERNAL_MODULES "" STRING
483                 "Extra modules that OpenSG will try to import.")
485   OSG_SET_CACHE(OSG_EXTERNAL_MODULES_INCLUDE "" FILEPATH 
486                 "Include file of extra modules")
488   IF(EXISTS "${OSG_EXTERNAL_MODULES_INCLUDE}")
489     INCLUDE("${OSG_EXTERNAL_MODULES_INCLUDE}")
490   ENDIF()
492   FOREACH(EXTERNAL ${OSG_EXTRA_EXTERNAL_MODULES})
493     OPTION(OSGBUILD_${EXTERNAL}
494            "Build using ${EXTERNAL} module" OFF)
496     IF(OSGBUILD_${EXTERNAL})
497       FIND_PATH(OSG_${EXTERNAL}_SOURCE_DIR
498                 CMakeLists.Lib.${EXTERNAL}.txt
499                 ${CMAKE_CURRENT_SOURCE_DIR}/../${EXTERNAL})
501       OSG_ADD_OPT(OSG_${EXTERNAL}_SOURCE_DIR)
503       IF(NOT EXISTS
504             ${OSG_${EXTERNAL}_SOURCE_DIR}/CMakeLists.Lib.${EXTERNAL}.txt)
506         MESSAGE(SEND_ERROR "Cannot find ${EXTERNAL} sources directory: "
507                            "${OSG_${EXTERNAL}_SOURCE_DIR}")              
508       ELSE()
509         LIST(APPEND OSG_EXTERNAL_CONFIGS "${EXTERNAL}")
511         GET_FILENAME_COMPONENT(_EXT_SRC_DIR
512                                "${OSG_${EXTERNAL}_SOURCE_DIR}/.."
513                                REALPATH                         )
515         IF(EXISTS "${OSG_${EXTERNAL}_SOURCE_DIR}/CMakeLists.PackagePrepare.cmake")
516           LIST(APPEND OSG_EXTERNAL_PREPARE "${OSG_${EXTERNAL}_SOURCE_DIR}")
517         ENDIF()
519         IF(EXISTS "${_EXT_SRC_DIR}/CMakeLists.PackagePrepare.cmake")
520           LIST(APPEND OSG_EXTERNAL_PREPARE "${_EXT_SRC_DIR}")
521         ENDIF()
522       ENDIF()
523     ENDIF()
524   ENDFOREACH(EXTERNAL)
526 IF(OSG_EXTERNAL_PREPARE)
527   LIST(REMOVE_DUPLICATES OSG_EXTERNAL_PREPARE)
528 ENDIF()
529 ENDMACRO(OSG_INIT)
532 MACRO(_OSG_SETUP_BUILD)
534   # when adding passes, make sure to add a corresponding pass directory variable
535   # OSG_PASSDIR_${PASSNAME} - this variable may not be empty!
536   SET(OSG_CMAKE_PASSES "OSGCOLLECT" "OSGSETUP")
538   SET(OSG_PASSDIR_OSGCOLLECT "Collect")
539   SET(OSG_PASSDIR_OSGSETUP   "Build")
541   ###############
542   # Clean
543   ###############
545   FILE(GLOB OSG_OLD_BUILD_FILES  "${CMAKE_BINARY_DIR}/*.cmake")
547   IF(OSG_OLD_BUILD_FILES)
548     FILE(REMOVE ${OSG_OLD_BUILD_FILES})
549   ENDIF(OSG_OLD_BUILD_FILES)
551 #  FOREACH(_OSG_COMPONENT ${STORED_PROJECTS})
552   FOREACH(_OSG_COMPONENT ${_OSG_COMPONENTS})
553     MESSAGE(STATUS "FAKE : ${CMAKE_BINARY_DIR}/${_OSG_COMPONENT}.cmake")
554     FILE(WRITE ${CMAKE_BINARY_DIR}/${_OSG_COMPONENT}.cmake "#dummy")
556     SET(_OSG_COMPONENT_LI )
558     FOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_OSG_LIB})
559       LIST(APPEND _OSG_COMPONENT_LI ${_OSG_COMPONENT_DEP})
560     ENDFOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_OSG_LIB})
562     FOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_LIB})
563       IF(TARGET ${_OSG_COMPONENT_DEP})
564         LIST(APPEND _OSG_COMPONENT_LI ${_OSG_COMPONENT_DEP})
565       ELSE(TARGET ${_OSG_COMPONENT_DEP})
566         LIST(APPEND _OSG_COMPONENT_LI ${${_OSG_COMPONENT_DEP}})
567       ENDIF(TARGET ${_OSG_COMPONENT_DEP})
568     ENDFOREACH(_OSG_COMPONENT_DEP ${${_OSG_COMPONENT}_DEP_LIB})
570     IF(_OSG_COMPONENT_LI AND TARGET ${_OSG_COMPONENT})
572       SET_TARGET_PROPERTIES(${_OSG_COMPONENT} PROPERTIES
573                             IMPORTED_LINK_INTERFACE_LIBRARIES "${_OSG_COMPONENT_LI}")
574     ENDIF(_OSG_COMPONENT_LI AND TARGET ${_OSG_COMPONENT})
576     IF(EXISTS "${OSG_PYTHON_MODULE_BASE_DIR}/${_OSG_COMPONENT}/module")
577         SET(OSG_PYTHON_${_OSG_COMPONENT}_MODULE_DIR "${OSG_PYTHON_MODULE_BASE_DIR}/${_OSG_COMPONENT}/module" CACHE INTERNAL "" FORCE)
578     ENDIF()
580   ENDFOREACH(_OSG_COMPONENT ${STORE_PROJECTS})
582   ###############
583   # Tests
584   ###############
586   # optional pass for test programs
587   IF(OSGBUILD_TESTS)
588     LIST(APPEND OSG_CMAKE_PASSES "OSGSETUPTEST")
589     SET(OSG_PASSDIR_OSGSETUPTEST "Test")
590   ENDIF()
592   OSG_OPTION(OSG_ENABLE_FCD2CODE "" ON)
593   OSG_OPTION(OSG_FCD2CODE_WRITE_CLASS "" OFF)
594   OSG_OPTION(OSGBUILD_PYTHON_BINDINGS "Build python bindings" ON)
596   SET(OSG_MAIN_LIB_TARGET OSGAllContribLibs)
599   ###############
600   # Python
601   ###############
603   SETUP_PYTHON_BUILD()
605   ###############
606   #### Doxygen
607   ###############
609   IF(EXISTS "${OSG_SUPPORT_ROOT}/bin/doxygen" AND NOT DOXYGEN_EXECUTABLE)
610     SET(DOXYGEN_EXECUTABLE "${OSG_SUPPORT_ROOT}/bin/doxygen" 
611                            CACHE FILEPATH "doxygen executable (custom)" FORCE)
612   ENDIF()
614   FIND_PACKAGE(Doxygen)
616 #  IF(NOT OSG_DOXY_INPUTS)
617     # add a pass for doxygen to run
618     LIST(APPEND OSG_CMAKE_PASSES "OSGDOXYDOC")
619     SET(OSG_PASSDIR_OSGDOXYDOC "Doc/build")
620 #  ENDIF(NOT OSG_DOXY_INPUTS)
622   # set up variables for the config file
623   IF(DOXYGEN_DOT_EXECUTABLE)
624     SET(OSG_DOXY_HAVE_DOT "YES")
625   ENDIF(DOXYGEN_DOT_EXECUTABLE)
627 ENDMACRO(_OSG_SETUP_BUILD)
629 MACRO(_OSG_RUN_PASSES)
631   FOREACH(LIBCONFIGFILE ${OSG_LIBRARY_CONFIG_FILES})
632     GET_FILENAME_COMPONENT(LIBCONFIGDIR "${LIBCONFIGFILE}" PATH)
633     GET_FILENAME_COMPONENT(LIBFILENAME  "${LIBCONFIGFILE}" NAME)
634     STRING(REPLACE "CMakeLists.Lib." "" LIBFILENAME "${LIBFILENAME}")
635     STRING(REPLACE ".txt"            "" LIBFILENAME "${LIBFILENAME}")
637     IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.Prepare.cmake)
638       INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.Prepare.cmake)
639     ENDIF()
640     IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.PrePasses.cmake)
641       INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/${LIBCONFIGDIR}/${LIBFILENAME}.PrePasses.cmake)
642     ENDIF()
643   ENDFOREACH(LIBCONFIGFILE)
645   FOREACH(EXTERNAL_PREPARE ${OSG_EXTERNAL_PREPARE})
646     INCLUDE("${EXTERNAL_PREPARE}/CMakeLists.PackagePrepare.cmake")
647   ENDFOREACH()
649   FOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
650     IF(EXISTS ${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.Prepare.cmake)
651       INCLUDE(${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.Prepare.cmake)
652     ENDIF(EXISTS
653     ${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.Prepare.cmake)
654   ENDFOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
656   FOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
657     IF(EXISTS ${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.PrePasses.cmake)
658       INCLUDE(${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.PrePasses.cmake)
659     ENDIF(EXISTS ${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.PrePasses.cmake)
660   ENDFOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
662   # run build passes
663   FOREACH(PASS ${OSG_CMAKE_PASSES})
664     SET(OSG_CMAKE_PASS ${PASS})
666     MESSAGE(STATUS "\nPASS : ${OSG_CMAKE_PASS} in ${OSG_PASSDIR_${PASS}}\n")
668     FOREACH(LIBCONFIGFILE ${OSG_LIBRARY_CONFIG_FILES})
669         GET_FILENAME_COMPONENT(LIBCONFIGDIR "${LIBCONFIGFILE}" PATH)
670         GET_FILENAME_COMPONENT(LIBFILENAME  "${LIBCONFIGFILE}" NAME)
671         STRING(REPLACE "CMakeLists.Lib." "" LIBFILENAME "${LIBFILENAME}")
672         STRING(REPLACE ".txt"            "" LIBFILENAME "${LIBFILENAME}")
674         ADD_SUBDIRECTORY("${LIBCONFIGDIR}" "${OSG_PASSDIR_${PASS}}/${LIBFILENAME}")
676     ENDFOREACH(LIBCONFIGFILE)
678     FOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
679         ADD_SUBDIRECTORY("${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}"
680                          "External/${EXTERNAL_CONFIG}/${OSG_PASSDIR_${PASS}}")
681     ENDFOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
682    
683   ENDFOREACH()
685   IF(WIN32)
686     SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugOpt;ReleaseNoOpt"
687                                   CACHE STRING "OpenSG Build Types" FORCE )
688   ELSE()
689     SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;DebugGV"
690                                   CACHE STRING "OpenSG Build Types" FORCE )
691   ENDIF(WIN32)
693   EXECUTE_PROCESS(
694       COMMAND "${CMAKE_COMMAND}" -E copy
695                        "${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME_SHORT}Configured.h.cmake"
696                        "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp.cmake")
698   FOREACH(_OSG_ADD_CONFIGURE_LINE ${${CMAKE_PROJECT_NAME_UP}_ADDITIONAL_CONFIGURE_LINES})
699     FILE(APPEND "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp.cmake" "\n${_OSG_ADD_CONFIGURE_LINE}\n")
700   ENDFOREACH()
702   FILE(APPEND "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp.cmake" "\n#endif // _${CMAKE_PROJECT_NAME_SHORT_UP}CONFIGURED_H_\n")
704   CONFIGURE_FILE("${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp.cmake"
705                  "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp")
707   EXECUTE_PROCESS(
708       COMMAND "${CMAKE_COMMAND}" -E copy_if_different
709                        "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h.tmp" 
710                        "${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h")
712   INSTALL(FILES ${CMAKE_BINARY_DIR}/Source/Base/Base/${CMAKE_PROJECT_NAME_SHORT}Configured.h
713           DESTINATION include/OpenSG
714           PERMISSIONS OWNER_WRITE OWNER_READ
715                       GROUP_READ
716                       WORLD_READ)
718   FOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
719     IF(EXISTS ${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.Finalize.cmake)
720       INCLUDE(${OSG_${EXTERNAL_CONFIG}_SOURCE_DIR}/${EXTERNAL_CONFIG}.Finalize.cmake)
721     ENDIF()
722   ENDFOREACH(EXTERNAL_CONFIG ${OSG_EXTERNAL_CONFIGS})
724 ENDMACRO(_OSG_RUN_PASSES)
726 MACRO(OSG_COLLECT_LIBS CURRENT_DIR_ONLY)
728   _OSG_SETUP_BUILD()
730   ###############
731   # Passes
732   ###############
734   SET(_OSG_CURRDIR_ONLY ${CURRENT_DIR_ONLY})
736   # Find files describing libraries to build, but make sure base
737   # and system are processed first
739   IF(_OSG_CURRDIR_ONLY)
740     FILE(GLOB OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
741          "./*CMakeLists.Lib.*.txt")
742   ELSE()
743     FILE(GLOB_RECURSE OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
744          "./*CMakeLists.Lib.*.txt")
745   ENDIF()
747 MESSAGE("FOOO ${OSG_LIBRARY_CONFIG_FILES}")
749   IF(OSG_EXCLUDE_FROM_BUILD)
750     LIST(REMOVE_ITEM OSG_LIBRARY_CONFIG_FILES ${OSG_EXCLUDE_FROM_BUILD})
751   ENDIF()
753   _OSG_RUN_PASSES()
755 ENDMACRO(OSG_COLLECT_LIBS CURRENT_DIR_ONLY)
757 MACRO(OSG_DOCOLLECT_LIBS)
759   _OSG_SETUP_BUILD()
761   ###############
762   # Passes
763   ###############
765   SET(_OSG_CURRDIR_ONLY ${CURRENT_DIR_ONLY})
767   SET(_OSG_TMPLIST ${ARGV})
768   MATH(EXPR _OSG_LISTCOUNT ${ARGC}-1)
770   # Find files describing libraries to build, but make sure base
771   # and system are processed first
773   SET(_OSG_TMPLIST ${ARGV})
774   MATH(EXPR _OSG_LISTCOUNT ${ARGC}-1)
776   FOREACH(_LOOPC RANGE 0 ${_OSG_LISTCOUNT} 2)
778     MATH(EXPR _LOOPN ${_LOOPC}+1)
780     LIST(GET _OSG_TMPLIST ${_LOOPC} OSGLIB_SOURCE_DIR)
781     LIST(GET _OSG_TMPLIST ${_LOOPN} _OSG_CURRDIR_ONLY)
783     IF(_OSG_CURRDIR_ONLY)
784       FILE(GLOB _OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
785            "${${OSGLIB_SOURCE_DIR}}/*CMakeLists.Lib.*.txt")
786     ELSE()
787       FILE(GLOB_RECURSE _OSG_LIBRARY_CONFIG_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
788            "${${OSGLIB_SOURCE_DIR}}/*CMakeLists.Lib.*.txt")
789     ENDIF()
791     LIST(APPEND OSG_LIBRARY_CONFIG_FILES ${_OSG_LIBRARY_CONFIG_FILES})
793     IF(EXISTS ${${OSGLIB_SOURCE_DIR}}/CMakeLists.PackagePrepare.cmake)
794       INCLUDE(${${OSGLIB_SOURCE_DIR}}/CMakeLists.PackagePrepare.cmake)
795     ENDIF()
797   ENDFOREACH()
799   IF(OSG_EXCLUDE_FROM_BUILD)
800     LIST(REMOVE_ITEM OSG_LIBRARY_CONFIG_FILES ${OSG_EXCLUDE_FROM_BUILD})
801   ENDIF()
803   _OSG_RUN_PASSES()
805 ENDMACRO(OSG_DOCOLLECT_LIBS)