0032613: Samples - glfw compilation error on Linux
[occt.git] / samples / glfw / adm / cmake / FindOpenCASCADE.cmake
1 # This script finds OpenCASCADE Technology libraries.
2 # The script requires:
3 #  OpenCASCADE_DIR - root OCCT folder or folder with CMake configuration files
4 #
5 # Script will define the following variables on success:
6 #  OpenCASCADE_FOUND       - package is successfully found
7 #  OpenCASCADE_INCLUDE_DIR - directory with headers
8 #  OpenCASCADE_LIBRARY_DIR - directory with libraries for linker
9 #  OpenCASCADE_BINARY_DIR  - directory with DLLs
10 include(FindPackageHandleStandardArgs)
11
12 # MY_PLATFORM variable
13 math (EXPR MY_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
14 if (WIN32)
15   set (MY_PLATFORM "win${MY_BITNESS}")
16 elseif(APPLE)
17   set (MY_PLATFORM "mac")
18 else()
19   set (MY_PLATFORM "lin")
20 endif()
21
22 # MY_PLATFORM_AND_COMPILER variable
23 if (MSVC)
24   if (MSVC90)
25     set (MY_COMPILER vc9)
26   elseif (MSVC10)
27     set (MY_COMPILER vc10)
28   elseif (MSVC11)
29     set (MY_COMPILER vc11)
30   elseif (MSVC12)
31     set (MY_COMPILER vc12)
32   elseif (MSVC14)
33     set (MY_COMPILER vc14)
34   else()
35     set (MY_COMPILER vc15)
36     message (WARNING "Unknown msvc version. $$MY_COMPILER is used")
37   endif()
38 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
39   set (MY_COMPILER gcc)
40 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
41   set (MY_COMPILER gcc)
42 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
43   set (MY_COMPILER clang)
44 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
45   set (MY_COMPILER icc)
46 else()
47   set (MY_COMPILER ${CMAKE_GENERATOR})
48   string (REGEX REPLACE " " "" COMPILER ${MY_COMPILER})
49 endif()
50 set (MY_PLATFORM_AND_COMPILER "${MY_PLATFORM}/${MY_COMPILER}")
51
52 set (OpenCASCADE_DIR "" CACHE PATH "Path to Open CASCADE libraries.")
53
54 # default paths
55 set (OpenCASCADE_INCLUDE_DIR "${OpenCASCADE_DIR}/inc")
56 set (OpenCASCADE_LIBRARY_DIR "${OpenCASCADE_DIR}/${MY_PLATFORM_AND_COMPILER}/lib")
57 set (OpenCASCADE_BINARY_DIR  "${OpenCASCADE_DIR}/${MY_PLATFORM_AND_COMPILER}/bin")
58
59 # complete list of OCCT Toolkits (copy-paste from adm/UDLIST, since installed OCCT does not include UDLIST)
60 set (OpenCASCADE_TKLIST "")
61 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKernel TKMath) # FoundationClasses
62 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKG2d TKG3d TKGeomBase TKBRep) # ModelingData
63 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKGeomAlgo TKTopAlgo TKPrim TKBO TKBool TKHLR TKFillet TKOffset TKFeat TKMesh TKXMesh TKShHealing) # ModelingAlgorithms
64 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKService TKV3d TKOpenGl TKMeshVS TKIVtk TKD3DHost) # Visualization
65 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKCDF TKLCAF TKCAF TKBinL TKXmlL TKBin TKXml TKStdL TKStd TKTObj TKBinTObj TKXmlTObj TKVCAF) # ApplicationFramework
66 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF TKRWMesh) # DataExchange
67 set (OpenCASCADE_TKLIST ${OpenCASCADE_TKLIST} TKDraw TKViewerTest) # Draw
68
69 # validate location of OCCT libraries and headers
70 set (OpenCASCADE_INCLUDE_DIR_FOUND)
71 set (OpenCASCADE_LIBRARY_DIR_FOUND)
72 set (OpenCASCADE_LIBRARY_DEBUG_DIR_FOUND)
73 set (OpenCASCADE_IMPLIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
74 set (OpenCASCADE_SHAREDLIB_RELEASE_FOUND)
75 set (OpenCASCADE_SHAREDLIB_DEBUG_FOUND)
76 if (EXISTS "${OpenCASCADE_INCLUDE_DIR}/Standard.hxx")
77   set (OpenCASCADE_INCLUDE_DIR_FOUND ON)
78 endif()
79
80 if (EXISTS "${OpenCASCADE_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_STATIC_LIBRARY_SUFFIX}")
81   set (OpenCASCADE_LIBRARY_DIR_FOUND ON)
82 elseif (NOT WIN32 AND EXISTS "${OpenCASCADE_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
83   set (OpenCASCADE_LIBRARY_DIR_FOUND ON)
84   set (OpenCASCADE_IMPLIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
85 endif()
86
87 if (EXISTS "${OpenCASCADE_LIBRARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_STATIC_LIBRARY_SUFFIX}")
88   set (OpenCASCADE_LIBRARY_DEBUG_DIR_FOUND ON)
89 elseif (NOT WIN32 AND EXISTS "${OpenCASCADE_LIBRARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
90   set (OpenCASCADE_LIBRARY_DEBUG_DIR_FOUND ON)
91   set (OpenCASCADE_IMPLIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
92 elseif (OpenCASCADE_LIBRARY_DIR_FOUND)
93   message (STATUS "Only release OpenCASCADE libraries have been found")
94 endif()
95
96 if (NOT OpenCASCADE_LIBRARY_DIR_FOUND AND OpenCASCADE_LIBRARY_DEBUG_DIR_FOUND)
97   set (OpenCASCADE_LIBRARY_DIR_FOUND ON)
98   message (WARNING "Only debug OpenCASCADE libraries have been found")
99 endif()
100
101 if (WIN32)
102   if (EXISTS "${OpenCASCADE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
103     set (OpenCASCADE_SHAREDLIB_RELEASE_FOUND ON)
104   endif()
105   if (EXISTS "${OpenCASCADE_BINARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
106     set (OpenCASCADE_SHAREDLIB_DEBUG_FOUND ON)
107   endif()
108 else()
109   if (EXISTS "${OpenCASCADE_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
110     set (OpenCASCADE_SHAREDLIB_RELEASE_FOUND ON)
111   endif()
112   if (EXISTS "${OpenCASCADE_LIBRARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}TKernel${CMAKE_SHARED_LIBRARY_SUFFIX}")
113     set (OpenCASCADE_SHAREDLIB_DEBUG_FOUND ON)
114   endif()
115 endif()
116
117 if (OpenCASCADE_INCLUDE_DIR_FOUND AND OpenCASCADE_LIBRARY_DIR_FOUND)
118   set (OpenCASCADE_FOUND ON)
119   set (OpenCASCADE_INSTALL_PREFIX ${OpenCASCADE_DIR})
120
121   # Define OCCT toolkits so that CMake can put absolute paths to linker;
122   # the library existance is not checked here, since modules can be disabled.
123   foreach (aLibIter ${OpenCASCADE_TKLIST})
124     add_library (${aLibIter} SHARED IMPORTED)
125
126     set_property (TARGET ${aLibIter} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
127     set_target_properties (${aLibIter} PROPERTIES IMPORTED_IMPLIB_RELEASE "${OpenCASCADE_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${OpenCASCADE_IMPLIB_SUFFIX}")
128     if (OpenCASCADE_SHAREDLIB_RELEASE_FOUND)
129       if (WIN32)
130         set_target_properties (${aLibIter} PROPERTIES IMPORTED_LOCATION_RELEASE "${OpenCASCADE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${CMAKE_SHARED_LIBRARY_SUFFIX}")
131       else()
132         set_target_properties (${aLibIter} PROPERTIES IMPORTED_LOCATION_RELEASE "${OpenCASCADE_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${CMAKE_SHARED_LIBRARY_SUFFIX}")
133       endif()
134     endif()
135
136     if (OpenCASCADE_LIBRARY_DEBUG_DIR_FOUND)
137       set_property (TARGET ${aLibIter} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
138       set_target_properties (${aLibIter} PROPERTIES IMPORTED_IMPLIB_DEBUG "${OpenCASCADE_LIBRARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${OpenCASCADE_IMPLIB_SUFFIX}")
139       if (OpenCASCADE_SHAREDLIB_DEBUG_FOUND)
140         if (WIN32)
141           set_target_properties (${aLibIter} PROPERTIES IMPORTED_LOCATION_DEBUG "${OpenCASCADE_BINARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${CMAKE_SHARED_LIBRARY_SUFFIX}")
142         else()
143           set_target_properties (${aLibIter} PROPERTIES IMPORTED_LOCATION_DEBUG "${OpenCASCADE_LIBRARY_DIR}d/${CMAKE_SHARED_LIBRARY_PREFIX}${aLibIter}${CMAKE_SHARED_LIBRARY_SUFFIX}")
144         endif()
145       endif()
146     endif()
147   endforeach()
148 else()
149   # fallback searching for CMake configs
150   if (NOT "${OpenCASCADE_DIR}" STREQUAL "")
151     set (anOcctDirBak "${OpenCASCADE_DIR}")
152     find_package (OpenCASCADE CONFIG QUIET PATHS "${OpenCASCADE_DIR}" NO_DEFAULT_PATH)
153     set (OpenCASCADE_DIR "${anOcctDirBak}" CACHE PATH "Path to Open CASCADE libraries." FORCE)
154   else()
155     find_package (OpenCASCADE CONFIG QUIET)
156   endif()
157 endif()