0027478: Configuration - avoid inclusion of Xlib.h within Graphic3d_GraphicDriver.hxx
[occt.git] / CMakeLists.txt
index 3a94c98..dc95958 100644 (file)
@@ -24,8 +24,14 @@ endif()
 
 if ("${BUILD_LIBRARY_TYPE}" STREQUAL "Shared")
   set (BUILD_SHARED_LIBS ON)
+
+  if (NOT DEFINED BUILD_SHARED_LIBRARY_NAME_POSTFIX)
+    set (BUILD_SHARED_LIBRARY_NAME_POSTFIX "" CACHE STRING "${BUILD_SHARED_LIBRARY_NAME_POSTFIX_DESCR}" FORCE)
+  endif()
 else()
   unset (BUILD_SHARED_LIBS)
+  message (STATUS "Info: Only 3rdparty's header files are used for building of static OCCT libraries")
+  unset (BUILD_SHARED_LIBRARY_NAME_POSTFIX)
 endif()
 
 # the name of the project
@@ -59,9 +65,16 @@ if (DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE) # single-configuration ge
 endif()
 
 # enable extended messages of many OCCT algorithms
-set (BUILD_WITH_DEBUG OFF CACHE BOOL "${BUILD_WITH_DEBUG_DESCR}")
+if ((SINGLE_GENERATOR AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") OR NOT SINGLE_GENERATOR)
+  if (NOT BUILD_WITH_DEBUG)
+    set (BUILD_WITH_DEBUG OFF CACHE BOOL "${BUILD_WITH_DEBUG_DESCR}")
+  endif()
+else()
+  OCCT_CHECK_AND_UNSET (BUILD_WITH_DEBUG)
+endif()
+
 if (BUILD_WITH_DEBUG)
-  add_definitions (-DOCCT_DEBUG)
+  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:DEBUG>:OCCT_DEBUG>)
 endif()
 
 # copy samples to install directory
@@ -70,10 +83,13 @@ set (INSTALL_SAMPLES OFF CACHE BOOL "${INSTALL_SAMPLES_DESCR}")
 # install dir of the project
 if (NOT DEFINED INSTALL_DIR)
   # set default install directory for Windows
-  if (WIN32)
+  if (WIN32 AND NOT DEFINED CMAKE_INSTALL_PREFIX)
     set (CMAKE_INSTALL_PREFIX "C:/opencascade-${OCC_VERSION_STRING_EXT}")
   endif()
   set (INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" CACHE PATH "${INSTALL_DIR_DESCR}")
+else()
+  file (TO_CMAKE_PATH "${INSTALL_DIR}" INSTALL_DIR)
+  set (INSTALL_DIR "${INSTALL_DIR}" CACHE PATH "${INSTALL_DIR_DESCR}" FORCE)
 endif()
 
 # choose a variant of the layout of the install paths
@@ -265,7 +281,7 @@ if (NOT DEFINED INSTALL_DIR_CMAKE)
       set (INSTALL_DIR_CMAKE "lib/cmake/opencascade" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
     endif()
   else()
-    set (INSTALL_DIR_CMAKE "${OS_WITH_BIT}/${COMPILER}/lib" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
+    set (INSTALL_DIR_CMAKE "cmake" CACHE PATH "${INSTALL_DIR_CMAKE_DESCR}")
   endif()
 endif()
 
@@ -313,7 +329,17 @@ if (ANDROID AND BUILD_MODULE_Draw)
 endif()
 
 # Overview
-set (BUILD_DOC_Overview OFF CACHE BOOL "${BUILD_DOC_Overview_DESCR}")
+if (NOT DEFINED BUILD_DOC_Overview)
+  set (DO_ONLY_CHECK_FOR_DOXYGEN ON)
+  OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/doxygen")
+  set (DO_ONLY_CHECK_FOR_DOXYGEN OFF)
+  
+  if (CAN_DOXYGEN_BE_USED)
+    message (STATUS "Info. Overview building is turned on")
+  endif()
+
+  set (BUILD_DOC_Overview ${CAN_DOXYGEN_BE_USED} CACHE BOOL "${BUILD_DOC_Overview_DESCR}")
+endif()
 
 if (NOT USE_D3D)
   list (REMOVE_ITEM Visualization_TOOLKITS TKD3DHost)
@@ -377,6 +403,9 @@ endif()
 if (NOT DEFINED 3RDPARTY_DIR)
   set (3RDPARTY_DIR "" CACHE PATH ${3RDPARTY_DIR_DESCR})
   get_filename_component (3RDPARTY_DIR "${3RDPARTY_DIR}" ABSOLUTE)
+else()
+  file (TO_CMAKE_PATH "${3RDPARTY_DIR}" 3RDPARTY_DIR)
+  set (3RDPARTY_DIR "${3RDPARTY_DIR}" CACHE PATH "${3RDPARTY_DIR_DESCR}" FORCE)
 endif()
 
 # search for CSF_TclLibs variable in EXTERNLIB of each being used toolkit
@@ -556,17 +585,17 @@ endif()
 if (3RDPARTY_INCLUDE_DIRS)
   list (REMOVE_DUPLICATES 3RDPARTY_INCLUDE_DIRS)
   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_INCLUDE_DIRS_WITH_ENDS "${3RDPARTY_INCLUDE_DIRS}")
-  message (STATUS "Info: The directories of 3rdparty headers: ${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
+  message (STATUS "Info: The directories of 3rdparty headers: \n\t${3RDPARTY_INCLUDE_DIRS_WITH_ENDS}")
   include_directories (${3RDPARTY_INCLUDE_DIRS})
 endif()
 
 # include <cmake binary folder>/inc
 include_directories (${CMAKE_BINARY_DIR}/inc)
 
-if (3RDPARTY_LIBRARY_DIRS)
+if (3RDPARTY_LIBRARY_DIRS AND BUILD_SHARED_LIBS)
   list (REMOVE_DUPLICATES 3RDPARTY_LIBRARY_DIRS)
   string (REGEX REPLACE ";" "\n\t" 3RDPARTY_LIBRARY_DIRS_WITH_ENDS "${3RDPARTY_LIBRARY_DIRS}")
-  message (STATUS "Info: The directories of 3rdparty libraries: ${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
+  message (STATUS "Info: The directories of 3rdparty libraries: \n\t${3RDPARTY_LIBRARY_DIRS_WITH_ENDS}")
   link_directories (${3RDPARTY_LIBRARY_DIRS})
 endif()
 
@@ -607,7 +636,11 @@ COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOLKITS}"
 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
 message (STATUS "Info: \(${CURRENT_TIME}\) End the collecting")
 
-OCCT_INSTALL_FILE_OR_DIR ("data/" "${INSTALL_DIR}/${INSTALL_DIR_DATA}")
+list (FIND BUILD_TOOLKITS DRAWEXE DRAWEXE_INDEX)
+if (${DRAWEXE_INDEX} GREATER -1)
+  OCCT_INSTALL_FILE_OR_DIR ("data/" "${INSTALL_DIR}/${INSTALL_DIR_DATA}")
+  OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR}/${INSTALL_DIR_SAMPLES}")
+endif()
 
 if (WIN32)
   set (SCRIPT_EXT bat)
@@ -635,8 +668,6 @@ if (INSTALL_SAMPLES)
   install (FILES "${CMAKE_BINARY_DIR}/env.samples.${SCRIPT_EXT}" DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_SAMPLES}/qt/Tutorial" RENAME "env.${SCRIPT_EXT}")
 endif()
 
-OCCT_INSTALL_FILE_OR_DIR ("samples/tcl" "${INSTALL_DIR}/${INSTALL_DIR_SAMPLES}")
-
 if (INSTALL_TEST_CASES)
   OCCT_INSTALL_FILE_OR_DIR ("tests/" "${INSTALL_DIR}/${INSTALL_DIR_TESTS}")
 endif()
@@ -707,6 +738,11 @@ foreach(RESOURCE ${RESOURCES})
   endif()
 endforeach()
 
+# patch installed DrawDefault file if BUILD_SHARED_LIBRARY_NAME_POSTFIX is changed
+if (NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
+  OCCT_UPDATE_DRAW_DEFAULT_FILE()
+endif()
+
 # define CSF variable
 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_csf")
 
@@ -763,6 +799,7 @@ endif()
 # Prepare variables for configuration of OpenCASCADE cmake config file
 set (OCCT_MODULES_ENABLED)
 set (OCCT_LIBRARIES)
+set (SET_OpenCASCADE_MODULES_TOOLKITS "\n# List of available OpenCASCADE libraries for each module\n")
 foreach (OCCT_TOOLKIT ${BUILD_TOOLKITS})
   if (TARGET ${OCCT_TOOLKIT})
 
@@ -770,18 +807,36 @@ foreach (OCCT_TOOLKIT ${BUILD_TOOLKITS})
     get_target_property (${OCCT_TOOLKIT}_TYPE ${OCCT_TOOLKIT} "TYPE")
     if ("${${OCCT_TOOLKIT}_TYPE}" STREQUAL "STATIC_LIBRARY" OR "${${OCCT_TOOLKIT}_TYPE}" STREQUAL "SHARED_LIBRARY" )
       list (APPEND OCCT_LIBRARIES ${OCCT_TOOLKIT})
-    endif()
 
-    # get all modules
-    get_target_property (${OCCT_TOOLKIT}_FOLDER ${OCCT_TOOLKIT} "FOLDER")
-    string (REGEX MATCH "/(.+)" ${OCCT_TOOLKIT}_MODULE "${${OCCT_TOOLKIT}_FOLDER}")
-    if (NOT "${CMAKE_MATCH_1}" STREQUAL "")
-      list (APPEND OCCT_MODULES_ENABLED ${CMAKE_MATCH_1})
+      # get all modules
+      get_target_property (${OCCT_TOOLKIT}_MODULE ${OCCT_TOOLKIT} "MODULE")
+      list (APPEND OCCT_MODULES_ENABLED ${${OCCT_TOOLKIT}_MODULE})
+      list (APPEND OpenCASCADE_${${OCCT_TOOLKIT}_MODULE}_TOOLKITS ${OCCT_TOOLKIT})
     endif()
   endif()
 endforeach()
 list (REMOVE_DUPLICATES OCCT_MODULES_ENABLED)
 
+foreach (OCCT_MODULE ${OCCT_MODULES})
+  if (BUILD_MODULE_${OCCT_MODULE})
+    set (SET_OpenCASCADE_MODULES_TOOLKITS "${SET_OpenCASCADE_MODULES_TOOLKITS}set (OpenCASCADE_${OCCT_MODULE}_LIBRARIES ${OpenCASCADE_${OCCT_MODULE}_TOOLKITS})\n")
+  endif()
+
+  # sort enabled modules for correct work of OpenCASCADE config file
+  list(FIND OCCT_MODULES_ENABLED "${OCCT_MODULE}" OCCT_MODULE_INDEX)
+  if (NOT ${OCCT_MODULE_INDEX} EQUAL -1)
+    list (APPEND OCCT_MODULES_ENABLED_SORTED ${OCCT_MODULE})
+  endif()
+endforeach()
+set (OCCT_MODULES_ENABLED ${OCCT_MODULES_ENABLED_SORTED})
+
+# Add all targets to the build-tree export set
+export (TARGETS ${OCCT_LIBRARIES} FILE "${CMAKE_BINARY_DIR}/OpenCASCADETargets.cmake")
+
+# Export the package for use from the build-tree
+# (this registers the build-tree with a global CMake-registry)
+export(PACKAGE OpenCASCADE)
+
 if (CMAKE_BUILD_TYPE)
   set (SET_OpenCASCADE_BUILD_TYPE "set (OpenCASCADE_BUILD_TYPE        \"${CMAKE_BUILD_TYPE}\")")
 endif()
@@ -799,8 +854,13 @@ if (APPLE)
   set (SET_OpenCASCADE_WITH_GLX "set (OpenCASCADE_WITH_GLX       ${USE_GLX})")
 endif()
 
+if (NOT SINGLE_GENERATOR)
+  OCCT_INSERT_CODE_FOR_TARGET()
+endif()
+
 # Configure and install cmake config file
-OCCT_CONFIGURE_AND_INSTALL ("adm/templates/OpenCASCADEConfig.cmake.in" "OpenCASCADEConfig.cmake" "OpenCASCADEConfig.cmake" "${INSTALL_DIR}/${INSTALL_DIR_CMAKE}")
+configure_file("${CMAKE_SOURCE_DIR}/adm/templates/OpenCASCADEConfig.cmake.in" "OpenCASCADEConfig.cmake" @ONLY)
+install(FILES "${CMAKE_BINARY_DIR}/OpenCASCADEConfig.cmake" DESTINATION  "${INSTALL_DIR}/${INSTALL_DIR_CMAKE}")
 
 # Configure cmake version file
 include(CMakePackageConfigHelpers)
@@ -810,3 +870,12 @@ write_basic_package_version_file( ${CMAKE_BINARY_DIR}/OpenCASCADEConfigVersion.c
 
 # Install cmake version file
 install (FILES "${CMAKE_BINARY_DIR}/OpenCASCADEConfigVersion.cmake" DESTINATION "${INSTALL_DIR}/${INSTALL_DIR_CMAKE}")
+
+# Install the export set for use with the install-tree for each configuration
+foreach (OCCT_MODULE ${OCCT_MODULES_ENABLED})
+  install(EXPORT OpenCASCADE${OCCT_MODULE}Targets DESTINATION "${INSTALL_DIR_CMAKE}")
+endforeach()
+
+# Update generated OpenCASCADETargets-*.cmake files 
+# to have correct paths to libraries depending on the configuration
+OCCT_UPDATE_TARGET_FILE ()