0029266: CMake install does not copy pdb files in Debug mode due to the changes in...
[occt.git] / adm / cmake / occt_toolkit.cmake
index 947150b..1702611 100644 (file)
@@ -9,6 +9,13 @@ endif()
 
 set (PRECOMPILED_DEFS)
 
+if (NOT BUILD_SHARED_LIBS)
+  list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
+  if (WIN32)
+    list (APPEND PRECOMPILED_DEFS "-DHAVE_NO_DLL")
+  endif()
+endif()
+
 # Get all used packages from toolkit
 foreach (OCCT_PACKAGE ${USED_PACKAGES})
   
@@ -127,74 +134,74 @@ if (MSVC)
   endif()
 endif()
 
+set (CURRENT_MODULE)
+foreach (OCCT_MODULE ${OCCT_MODULES})
+  list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
+  if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
+    set (CURRENT_MODULE ${OCCT_MODULE})
+  endif()
+endforeach()
+
+if (WIN32)
+  OCCT_INSERT_CODE_FOR_TARGET ()
+endif()
+
 if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
   add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
 
-  if (DEFINED INSTALL_BIN_DIR)
-    install (TARGETS ${PROJECT_NAME} DESTINATION "${INSTALL_BIN_DIR}")
-  else()
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS Release
-             DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS RelWithDebInfo
-             DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS Debug
-             DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
-  endif()
+  install (TARGETS ${PROJECT_NAME}
+           DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
 else()
   add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
 
-  if (DEFINED INSTALL_LIB_DIR)
-    install (TARGETS ${PROJECT_NAME}
-             RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
-             ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
-             LIBRARY DESTINATION "${INSTALL_LIB_DIR}") 
-  else()
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS Release
-             RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin"
-             ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
-             LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS RelWithDebInfo
-             RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini"
-             ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi"
-             LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
-    install (TARGETS ${PROJECT_NAME}
-             CONFIGURATIONS Debug
-             RUNTIME DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind"
-             ARCHIVE DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
-             LIBRARY DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
-
-    if (MSVC)
-      install (FILES  ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
-               CONFIGURATIONS Debug
-               DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
-    endif()
+  if (MSVC)
+    install (FILES  ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb
+             CONFIGURATIONS Debug RelWithDebInfo
+             DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
   endif()
-endif()
 
-set (CURRENT_MODULE)
-foreach (OCCT_MODULE ${OCCT_MODULES})
-  list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
-  if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
-    set (CURRENT_MODULE ${OCCT_MODULE})
+  if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
+    set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
+    set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
   endif()
-endforeach()
+
+  install (TARGETS ${PROJECT_NAME}
+           EXPORT OpenCASCADE${CURRENT_MODULE}Targets
+           RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
+           ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
+           LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
+
+  if (NOT WIN32)
+    if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
+      set (LINK_NAME    "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}")
+      set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
+      OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
+    endif()
+  endif()
+endif()
 
 if (CURRENT_MODULE)
   set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Modules/${CURRENT_MODULE}")
+  set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
+  if (APPLE)
+    if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
+      set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
+    endif()
+  endif()
 endif()
 
 get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
 get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
 get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
 
-set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
-                                                  SOVERSION     "${OCC_VERSION_MAJOR}"
-                                                  VERSION       "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")               
+if (ANDROID)
+  # do not append version to the filename
+  set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
+else()
+  set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
+                                                    SOVERSION     "${OCC_VERSION_MAJOR}"
+                                                    VERSION       "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
+endif()
 
 set (USED_TOOLKITS_BY_CURRENT_PROJECT)
 set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
@@ -209,16 +216,48 @@ foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
     
     if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
       list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
+      if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK)
+        OCCT_INSTALL_VTK(${USED_ITEM})
+      endif()
     else()
       string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
       if ("${CSF_FOUND}" STREQUAL "")
         message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
       else() # get CSF_ value
         set (CURRENT_CSF ${${USED_ITEM}})
-        if (NOT "${CURRENT_CSF}" STREQUAL "")
-          # prepare a list from a string with whitespaces
+        if (NOT "x${CURRENT_CSF}" STREQUAL "x")
+          set (LIBRARY_FROM_CACHE 0)
           separate_arguments (CURRENT_CSF)
-          list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
+          foreach (CSF_LIBRARY ${CURRENT_CSF})
+            string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY)
+            string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}")
+            string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}")
+            get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES)
+            string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}")
+            foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES})
+              set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}})
+              string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE)
+
+              if (EXISTS "${CURRENT_CACHE_LIBRARY}" AND NOT IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}")
+                string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}")
+                string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}")
+                string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}")
+                if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR
+                    "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR
+                    NOT "x${IS_ENDING}" STREQUAL "x" OR
+                    NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x")
+                  list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${CURRENT_CACHE_LIBRARY}")
+                  set (LIBRARY_FROM_CACHE 1)
+                endif()
+              endif()
+            endforeach()
+          endforeach()
+
+          if (NOT ${LIBRARY_FROM_CACHE})
+            # prepare a list from a string with whitespaces
+            separate_arguments (CURRENT_CSF)
+            list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
+          endif()
         endif()
       endif()
     endif()
@@ -235,4 +274,71 @@ if (APPLE)
   endif()
 endif()
 
-target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
+# Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
+# Add VTK_OPENGL2_BACKEND definition.
+if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
+  add_definitions(-DVTK_OPENGL2_BACKEND)
+  foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
+    list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
+    if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
+      list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
+      if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
+        list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
+        if(VTK_MAJOR_VERSION GREATER 6)
+          list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingGL2PSOpenGL2)
+        endif()
+      endif()
+    endif()
+  endforeach()
+else()
+  if(VTK_MAJOR_VERSION EQUAL 6 AND VTK_MINOR_VERSION GREATER 2 OR VTK_MAJOR_VERSION GREATER 6)
+    list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL" IS_VTK_RENDER_FREETYPE_FOUND)
+    if (NOT ${IS_VTK_RENDER_FREETYPE_FOUND} EQUAL -1)
+      list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL")
+    endif()
+  endif()
+endif()
+
+if (BUILD_SHARED_LIBS)
+  target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
+endif()
+
+# suppress deprecation warnings inside OCCT itself for old gcc versions with unavailable Standard_DISABLE_DEPRECATION_WARNINGS
+if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6.0)
+    add_definitions("-DOCCT_NO_DEPRECATED")
+    message (STATUS "Warning: internal deprecation warnings by Standard_DEPRECATED have been disabled due to old gcc version being used")
+  endif()
+endif()
+
+# use Cotire to accelerate build via usage of precompiled headers
+if (BUILD_USE_PCH)
+  if (WIN32)
+    # prevent definition of min and max macros through inclusion of Windows.h
+    # (for cotire builds)
+    add_definitions("-DNOMINMAX")
+    # avoid warnings on deprecated names from standard C library (see strsafe.h)
+    add_definitions("-DSTRSAFE_NO_DEPRECATE")
+    # avoid "std::Equal1" warning in QANCollection_Stl.cxx in debug mode
+    # suggesting using msvc "Checked Iterators"
+    add_definitions("-D_SCL_SECURE_NO_WARNINGS")
+  endif()
+
+  # Exclude system-provided glext.h.
+  # These macros are already defined within OpenGl_GlFunctions.hxx,
+  # however we have to duplicate them here for building TKOpenGl with PCH.
+  add_definitions("-DGL_GLEXT_LEGACY")
+  add_definitions("-DGLX_GLXEXT_LEGACY")
+
+  # workaround for old gcc
+  if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
+    add_definitions("-D__STDC_CONSTANT_MACROS")
+    add_definitions("-D__STDC_FORMAT_MACROS")
+  endif()
+
+  # unity builds are not used since they do not add speed but cause conflicts
+  # in TKV3d
+  set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
+
+  cotire(${PROJECT_NAME})
+endif()