Skip to content

Commit 613015e

Browse files
cmake: Externalize OpenCascade config (#7365)
Co-authored-by: Andrej <azhilenkov@gmail.com>
1 parent be0eea1 commit 613015e

File tree

8 files changed

+144
-143
lines changed

8 files changed

+144
-143
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -490,141 +490,7 @@ if(BUILD_IFCGEOM)
490490

491491
# Open CASCADE
492492
if(WITH_OPENCASCADE)
493-
if(OCC_INCLUDE_DIR)
494-
set(OCC_INCLUDE_DIR ${OCC_INCLUDE_DIR} CACHE FILEPATH "Open CASCADE header files")
495-
message(STATUS "Looking for Open CASCADE include files in: ${OCC_INCLUDE_DIR}")
496-
endif()
497-
498-
if(OCC_LIBRARY_DIR)
499-
set(OCC_LIBRARY_DIR ${OCC_LIBRARY_DIR} CACHE FILEPATH "Open CASCADE library files")
500-
message(STATUS "Looking for Open CASCADE library files in: ${OCC_LIBRARY_DIR}")
501-
endif()
502-
503-
# No specific paths specified, try to find package.
504-
if(OCC_INCLUDE_DIR AND OCC_LIBRARY_DIR)
505-
message(
506-
STATUS
507-
"Using provided OCC_INCLUDE_DIR ('${OCC_INCLUDE_DIR}') "
508-
"and OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}')."
509-
)
510-
# Parse OCC_VERSION_STRING.
511-
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAJOR
512-
REGEX "#define OCC_VERSION_MAJOR.*"
513-
)
514-
string(REGEX MATCH "[0-9]+" OCC_MAJOR ${OCC_MAJOR})
515-
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MINOR
516-
REGEX "#define OCC_VERSION_MINOR.*"
517-
)
518-
string(REGEX MATCH "[0-9]+" OCC_MINOR ${OCC_MINOR})
519-
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAINT
520-
REGEX "#define OCC_VERSION_MAINTENANCE.*"
521-
)
522-
string(REGEX MATCH "[0-9]+" OCC_MAINT ${OCC_MAINT})
523-
set(OCC_VERSION_STRING "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}")
524-
elseif(NOT OCC_INCLUDE_DIR AND NOT OCC_LIBRARY_DIR)
525-
# OCE is not supported for find_package, because it's using a different name (`oce`)
526-
# and also has an odd directory structure (install/lib/oce-0.18/*.cmake).
527-
find_package(OpenCASCADE CONFIG REQUIRED)
528-
set(OCC_INCLUDE_DIR ${OpenCASCADE_INCLUDE_DIR})
529-
# Do not use OpenCASCADE_LIBRARY_DIR for OCC_LIBRARY_DIR - check target property explicitly.
530-
# On Windows there is a case with OpenCASCADE_LIBRARY_DIR points to `lib` folder,
531-
# while TKernel is actually in `libi`.
532-
get_target_property(TKERNEL_LIB_PATH TKernel LOCATION)
533-
get_filename_component(OCC_LIBRARY_DIR "${TKERNEL_LIB_PATH}" DIRECTORY)
534-
set(OCC_VERSION_STRING ${OpenCASCADE_VERSION})
535-
message(
536-
STATUS
537-
"Found Open CASCADE package at '${OpenCASCADE_DIR}', "
538-
"deducing from it OCC_INCLUDE_DIR: '${OCC_INCLUDE_DIR}' "
539-
"and OCC_LIBRARY_DIR: '${OCC_LIBRARY_DIR}'."
540-
)
541-
else()
542-
message(
543-
FATAL_ERROR
544-
"Couldn't find Open CASCADE installation. "
545-
"Either both OCC_INCLUDE_DIR ('${OCC_INCLUDE_DIR}') and OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}') "
546-
"must be specified or OpenCASCADE package should be discoverable. "
547-
"If you're using OCE, then providing a package is not available "
548-
"and you need to provide OCE_INCLUDE_DIR and OCE_LIBRARY_DIR directly."
549-
)
550-
endif()
551-
552-
set(
553-
OPENCASCADE_LIBRARY_NAMES
554-
TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO
555-
TKFillet TKXSBase TKOffset TKHLR
556-
557-
# @todo investigate the exact conditions when this is necessary
558-
TKBin
559-
)
560-
561-
if(OCC_VERSION_STRING VERSION_LESS 7.8.0)
562-
list(APPEND OPENCASCADE_LIBRARY_NAMES TKIGES TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP)
563-
else(OCC_VERSION_STRING VERSION_LESS 7.8.0)
564-
list(APPEND OPENCASCADE_LIBRARY_NAMES TKDESTEP TKDEIGES)
565-
endif(OCC_VERSION_STRING VERSION_LESS 7.8.0)
566-
567-
clear_wasm_sysroot()
568-
find_library(libTKernel NAMES TKernel TKerneld PATHS ${OCC_LIBRARY_DIR} NO_DEFAULT_PATH)
569-
restore_wasm_sysroot()
570-
571-
if(libTKernel)
572-
message(STATUS "Required Open Cascade Library files found")
573-
else()
574-
message(
575-
FATAL_ERROR
576-
"Unable to find Open Cascade library files in OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}'), aborting"
577-
)
578-
endif()
579-
580-
# Use the found libTKernel as a template for all other OCC libraries
581-
# TODO Extract this into macro/function
582-
foreach(lib ${OPENCASCADE_LIBRARY_NAMES})
583-
# Make sure we'll handle the Windows/MSVC debug postfix convention too.
584-
string(REPLACE TKerneld "${lib}" lib_path "${libTKernel}")
585-
string(REPLACE TKernel "${lib}" lib_path "${lib_path}")
586-
list(APPEND OPENCASCADE_LIBRARIES "${lib_path}")
587-
endforeach()
588-
589-
if(MSVC)
590-
add_definitions(-DHAVE_NO_DLL)
591-
add_debug_variants(OPENCASCADE_LIBRARIES "${OPENCASCADE_LIBRARIES}" d)
592-
endif()
593-
594-
if(WIN32)
595-
# OCC might require linking to Winsock depending on the version and build configuration
596-
list(APPEND OPENCASCADE_LIBRARIES ws2_32.lib)
597-
endif()
598-
599-
# Make sure cross-referenced symbols between static OCC libraries get
600-
# resolved. Also add thread and rt libraries.
601-
get_filename_component(libTKernelExt ${libTKernel} EXT)
602-
if("${libTKernelExt}" STREQUAL ".a")
603-
set(OCCT_STATIC ON)
604-
endif()
605-
606-
if(OCCT_STATIC)
607-
find_package(Threads)
608-
609-
if(WASM_BUILD)
610-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
611-
else()
612-
# OPENCASCADE_LIBRARIES repeated N times below in order to fix cyclic dependencies
613-
# tfk: --start-group ... --end-group didn't work on the apple linker when last tested
614-
if(APPLE)
615-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
616-
else()
617-
set(OPENCASCADE_LIBRARIES -Wl,--start-group ${OPENCASCADE_LIBRARIES} -Wl,--end-group ${CMAKE_THREAD_LIBS_INIT})
618-
endif()
619-
endif()
620-
621-
if(NOT APPLE AND NOT WIN32)
622-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} "rt")
623-
endif()
624-
if(NOT WIN32)
625-
set(OPENCASCADE_LIBRARIES ${OPENCASCADE_LIBRARIES} "dl")
626-
endif()
627-
endif()
493+
find_package(OpenCASCADE REQUIRED)
628494
endif(WITH_OPENCASCADE)
629495
endif(BUILD_IFCGEOM)
630496

@@ -969,7 +835,7 @@ if(BUILD_CONVERT OR BUILD_IFCPYTHON)
969835

970836
add_library(geometry_serializer_ifc${schema} STATIC ../src/ifcgeom/Serialization/schema/Serialization.cpp)
971837
set_target_properties(geometry_serializer_ifc${schema} PROPERTIES COMPILE_FLAGS "-DIFC_GEOMSERIALIZATION_EXPORTS -DIfcSchema=Ifc${schema}")
972-
target_link_libraries(geometry_serializer_ifc${schema} ${OPENCASCADE_LIBRARIES})
838+
target_link_libraries(geometry_serializer_ifc${schema} ${OpenCASCADE_LIBRARIES})
973839
list(APPEND geometry_serializer_libraries geometry_serializer_ifc${schema})
974840
endforeach()
975841

cmake/FindOpenCASCADE.cmake

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
if(OCC_INCLUDE_DIR)
2+
set(OCC_INCLUDE_DIR ${OCC_INCLUDE_DIR} CACHE FILEPATH "Open CASCADE header files")
3+
message(STATUS "Looking for Open CASCADE include files in: ${OCC_INCLUDE_DIR}")
4+
endif()
5+
6+
if(OCC_LIBRARY_DIR)
7+
set(OCC_LIBRARY_DIR ${OCC_LIBRARY_DIR} CACHE FILEPATH "Open CASCADE library files")
8+
message(STATUS "Looking for Open CASCADE library files in: ${OCC_LIBRARY_DIR}")
9+
endif()
10+
11+
# No specific paths specified, try to find package.
12+
if(OCC_INCLUDE_DIR AND OCC_LIBRARY_DIR)
13+
message(
14+
STATUS
15+
"Using provided OCC_INCLUDE_DIR ('${OCC_INCLUDE_DIR}') "
16+
"and OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}')."
17+
)
18+
# Parse OCC_VERSION_STRING.
19+
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAJOR
20+
REGEX "#define OCC_VERSION_MAJOR.*"
21+
)
22+
string(REGEX MATCH "[0-9]+" OCC_MAJOR ${OCC_MAJOR})
23+
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MINOR
24+
REGEX "#define OCC_VERSION_MINOR.*"
25+
)
26+
string(REGEX MATCH "[0-9]+" OCC_MINOR ${OCC_MINOR})
27+
file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAINT
28+
REGEX "#define OCC_VERSION_MAINTENANCE.*"
29+
)
30+
string(REGEX MATCH "[0-9]+" OCC_MAINT ${OCC_MAINT})
31+
set(OCC_VERSION_STRING "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}")
32+
elseif(NOT OCC_INCLUDE_DIR AND NOT OCC_LIBRARY_DIR)
33+
# OCE is not supported for find_package, because it's using a different name (`oce`)
34+
# and also has an odd directory structure (install/lib/oce-0.18/*.cmake).
35+
find_package(OpenCASCADE CONFIG REQUIRED)
36+
set(OCC_INCLUDE_DIR ${OpenCASCADE_INCLUDE_DIR})
37+
# Do not use OpenCASCADE_LIBRARY_DIR for OCC_LIBRARY_DIR - check target property explicitly.
38+
# On Windows there is a case with OpenCASCADE_LIBRARY_DIR points to `lib` folder,
39+
# while TKernel is actually in `libi`.
40+
get_target_property(TKERNEL_LIB_PATH TKernel LOCATION)
41+
get_filename_component(OCC_LIBRARY_DIR "${TKERNEL_LIB_PATH}" DIRECTORY)
42+
set(OCC_VERSION_STRING ${OpenCASCADE_VERSION})
43+
message(
44+
STATUS
45+
"Found Open CASCADE package at '${OpenCASCADE_DIR}', "
46+
"deducing from it OCC_INCLUDE_DIR: '${OCC_INCLUDE_DIR}' "
47+
"and OCC_LIBRARY_DIR: '${OCC_LIBRARY_DIR}'."
48+
)
49+
else()
50+
message(
51+
FATAL_ERROR
52+
"Couldn't find Open CASCADE installation. "
53+
"Either both OCC_INCLUDE_DIR ('${OCC_INCLUDE_DIR}') and OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}') "
54+
"must be specified or OpenCASCADE package should be discoverable. "
55+
"If you're using OCE, then providing a package is not available "
56+
"and you need to provide OCE_INCLUDE_DIR and OCE_LIBRARY_DIR directly."
57+
)
58+
endif()
59+
60+
set(
61+
OpenCASCADE_LIBRARIES
62+
TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO
63+
TKFillet TKXSBase TKOffset TKHLR
64+
65+
# @todo investigate the exact conditions when this is necessary
66+
TKBin
67+
)
68+
69+
if(OCC_VERSION_STRING VERSION_LESS 7.8.0)
70+
list(APPEND OpenCASCADE_LIBRARIES TKIGES TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP)
71+
else(OCC_VERSION_STRING VERSION_LESS 7.8.0)
72+
list(APPEND OpenCASCADE_LIBRARIES TKDESTEP TKDEIGES)
73+
endif(OCC_VERSION_STRING VERSION_LESS 7.8.0)
74+
75+
clear_wasm_sysroot()
76+
find_library(libTKernel NAMES TKernel TKerneld PATHS ${OCC_LIBRARY_DIR} NO_DEFAULT_PATH)
77+
restore_wasm_sysroot()
78+
79+
if(libTKernel)
80+
message(STATUS "Required Open Cascade Library files found")
81+
else()
82+
message(
83+
FATAL_ERROR
84+
"Unable to find Open Cascade library files in OCC_LIBRARY_DIR ('${OCC_LIBRARY_DIR}'), aborting"
85+
)
86+
endif()
87+
88+
# Use the found libTKernel as a template for all other OCC libraries
89+
# TODO Extract this into macro/function
90+
foreach(lib ${OpenCASCADE_LIBRARIES})
91+
# Make sure we'll handle the Windows/MSVC debug postfix convention too.
92+
string(REPLACE TKerneld "${lib}" lib_path "${libTKernel}")
93+
string(REPLACE TKernel "${lib}" lib_path "${lib_path}")
94+
list(APPEND OpenCASCADE_LIBRARIES "${lib_path}")
95+
endforeach()
96+
97+
if(MSVC)
98+
add_definitions(-DHAVE_NO_DLL)
99+
add_debug_variants(OpenCASCADE_LIBRARIES "${OpenCASCADE_LIBRARIES}" d)
100+
endif()
101+
102+
if(WIN32)
103+
# OCC might require linking to Winsock depending on the version and build configuration
104+
list(APPEND OpenCASCADE_LIBRARIES ws2_32.lib)
105+
endif()
106+
107+
# Make sure cross-referenced symbols between static OCC libraries get
108+
# resolved. Also add thread and rt libraries.
109+
get_filename_component(libTKernelExt ${libTKernel} EXT)
110+
if("${libTKernelExt}" STREQUAL ".a")
111+
set(OCCT_STATIC ON)
112+
endif()
113+
114+
if(OCCT_STATIC)
115+
find_package(Threads)
116+
117+
if(WASM_BUILD)
118+
set(OpenCASCADE_LIBRARIES ${OpenCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
119+
else()
120+
# OpenCASCADE_LIBRARIES repeated N times below in order to fix cyclic dependencies
121+
# tfk: --start-group ... --end-group didn't work on the apple linker when last tested
122+
if(APPLE)
123+
set(OpenCASCADE_LIBRARIES ${OpenCASCADE_LIBRARIES} ${OpenCASCADE_LIBRARIES} ${OpenCASCADE_LIBRARIES} ${OpenCASCADE_LIBRARIES} ${OpenCASCADE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
124+
else()
125+
set(OpenCASCADE_LIBRARIES -Wl,--start-group ${OpenCASCADE_LIBRARIES} -Wl,--end-group ${CMAKE_THREAD_LIBS_INIT})
126+
endif()
127+
endif()
128+
129+
if(NOT APPLE AND NOT WIN32)
130+
set(OpenCASCADE_LIBRARIES ${OpenCASCADE_LIBRARIES} "rt")
131+
endif()
132+
if(NOT WIN32)
133+
set(OpenCASCADE_LIBRARIES ${OpenCASCADE_LIBRARIES} "dl")
134+
endif()
135+
endif()

src/examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ target_compile_features(IfcParseExamples PUBLIC cxx_std_17)
2626
if (WITH_OPENCASCADE)
2727

2828
ADD_EXECUTABLE(IfcOpenHouse IfcOpenHouse.cpp)
29-
TARGET_LINK_LIBRARIES(IfcOpenHouse ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES})
29+
TARGET_LINK_LIBRARIES(IfcOpenHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES})
3030
set_target_properties(IfcOpenHouse PROPERTIES FOLDER Examples)
3131

3232
ADD_EXECUTABLE(IfcAdvancedHouse IfcAdvancedHouse.cpp)
33-
TARGET_LINK_LIBRARIES(IfcAdvancedHouse ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES})
33+
TARGET_LINK_LIBRARIES(IfcAdvancedHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES})
3434
set_target_properties(IfcAdvancedHouse PROPERTIES FOLDER Examples)
3535

3636
endif()

src/ifcconvert/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ endif()
99
set(IFCCONVERT_FILES ${IFCCONVERT_CPP_FILES} ${IFCCONVERT_H_FILES})
1010
add_executable(IfcConvert ${IFCCONVERT_FILES})
1111

12-
target_link_libraries(IfcConvert IfcGeom IfcParse Serializers ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES} ${USD_LIBRARIES})
12+
target_link_libraries(IfcConvert IfcGeom IfcParse Serializers ${OpenCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES} ${USD_LIBRARIES})
1313
if(WITH_RELATIONSHIP_VALIDATION)
1414
set_property(TARGET IfcConvert APPEND_STRING PROPERTY COMPILE_FLAGS " -DWITH_RELATIONSHIP_VALIDATION")
1515
endif()

src/ifcgeomserver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ find_package(Boost REQUIRED)
33
file(GLOB CPP_FILES *.cpp)
44
set(SOURCE_FILES ${CPP_FILES})
55
add_executable(IfcGeomServer ${SOURCE_FILES})
6-
target_link_libraries(IfcGeomServer IfcGeom ${kernel_libraries} ${OPENCASCADE_LIBRARIES})
6+
target_link_libraries(IfcGeomServer IfcGeom ${kernel_libraries} ${OpenCASCADE_LIBRARIES})
77

88
install(TARGETS IfcGeomServer)

src/ifcmax/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if(HAS_MAX)
7474
tessint.lib
7575
viewfile.lib
7676
zlibdll.lib
77-
${OPENCASCADE_LIBRARIES}
77+
${OpenCASCADE_LIBRARIES}
7878
)
7979

8080
set_target_properties(IfcMax_${max_year} PROPERTIES SUFFIX ".dli")

src/ifcwrap/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ if (WASM_BUILD)
130130
endif()
131131
if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress")
132132
# On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time.
133-
target_link_libraries(ifcopenshell_wrapper PRIVATE ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${LIBSVGFILL})
133+
target_link_libraries(ifcopenshell_wrapper PRIVATE ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${LIBSVGFILL})
134134
else()
135135
target_link_libraries(ifcopenshell_wrapper PRIVATE ${IFCOPENSHELL_LIBRARIES} ${LIBSVGFILL})
136136
endif()

src/qtviewer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ set_target_properties(${targetName} PROPERTIES
8484

8585
target_link_libraries(${targetName}
8686
${IFCOPENSHELL_LIBRARIES}
87-
${OPENCASCADE_LIBRARIES}
87+
${OpenCASCADE_LIBRARIES}
8888
${OPENSCENEGRAPH_LIBRARIES}
8989
Qt${QT_VERSION}::Core
9090
Qt${QT_VERSION}::Gui

0 commit comments

Comments
 (0)