From 30184a3f6dd9cae93e73464fd4d7166a3407e296 Mon Sep 17 00:00:00 2001 From: Esteban DUGUEPEROUX Date: Sat, 15 Nov 2025 20:31:13 +0100 Subject: [PATCH] cmake: Externalize geometry_serializer cmake config files to their own directory --- cmake/CMakeLists.txt | 34 ++----------------- src/examples/CMakeLists.txt | 24 ++++++------- src/ifcgeom/CMakeLists.txt | 7 +++- src/ifcgeom/Serialization/CMakeLists.txt | 15 ++++++++ .../Serialization/schema/CMakeLists.txt | 7 ++++ 5 files changed, 43 insertions(+), 44 deletions(-) create mode 100644 src/ifcgeom/Serialization/CMakeLists.txt create mode 100644 src/ifcgeom/Serialization/schema/CMakeLists.txt diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2a2aff9cc7..3d2bbb220b 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -205,6 +205,9 @@ if(WITH_CGAL) endif() if(WITH_OPENCASCADE) + find_package(OpenCASCADE REQUIRED) + # Map OpenCASCADE_LIBRARIES variable from OpenCASCADEConfig.cmake to OPENCASCADE_LIBRARIES used by kernel generic cmake file + set(OPENCASCADE_LIBRARIES ${OpenCASCADE_LIBRARIES}) add_definitions(-DIFOPSH_WITH_OPENCASCADE) set(SWIG_DEFINES ${SWIG_DEFINES} -DIFOPSH_WITH_OPENCASCADE) list(APPEND GEOMETRY_KERNELS opencascade) @@ -324,13 +327,6 @@ find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) message(STATUS "Boost include files found in ${Boost_INCLUDE_DIRS}") message(STATUS "Boost libraries found in ${Boost_LIBRARY_DIRS}") -if(BUILD_IFCGEOM) - # Open CASCADE - if(WITH_OPENCASCADE) - find_package(OpenCASCADE REQUIRED) - endif(WITH_OPENCASCADE) -endif(BUILD_IFCGEOM) - if(COLLADA_SUPPORT) find_package(OpenCOLLADA REQUIRED) endif() @@ -557,24 +553,6 @@ if(BUILD_IFCGEOM) set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} IfcGeom ${IFCGEOM_SCHEMA_LIBRARIES}) endif() -if(BUILD_CONVERT OR BUILD_IFCPYTHON) - if(WITH_OPENCASCADE) - foreach(schema ${SCHEMA_VERSIONS}) - set(GEOM_SERIALIZER_SCHEMA_LIBRARIES ${GEOM_SERIALIZER_SCHEMA_LIBRARIES} GeometrySerializers_ifc${schema}) - - add_library(geometry_serializer_ifc${schema} OBJECT ../src/ifcgeom/Serialization/schema/Serialization.cpp) - set_target_properties(geometry_serializer_ifc${schema} PROPERTIES COMPILE_FLAGS "-DIFC_GEOMSERIALIZATION_EXPORTS -DIfcSchema=Ifc${schema}") - target_link_libraries(geometry_serializer_ifc${schema} ${OpenCASCADE_LIBRARIES}) - list(APPEND geometry_serializer_libraries geometry_serializer_ifc${schema}) - endforeach() - - add_library(geometry_serializer OBJECT ../src/ifcgeom/Serialization/Serialization.h ../src/ifcgeom/Serialization/Serialization.cpp) - set_target_properties(geometry_serializer PROPERTIES COMPILE_FLAGS "-DIFC_GEOMSERIALIZATION_EXPORTS") - target_link_libraries(geometry_serializer ${geometry_serializer_libraries} IfcParse) - set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} geometry_serializer ${geometry_serializer_libraries}) - endif() -endif() - if(BUILD_IFCGEOM) # CGAL::CGAL target already has dependencies resolved. if(WITH_CGAL AND CGAL_DIR) @@ -747,12 +725,6 @@ if(BUILD_IFCGEOM) install(TARGETS ${IFCGEOM_SCHEMA_LIBRARIES} ${kernel_libraries} IfcGeom) endif(BUILD_IFCGEOM) -if(BUILD_CONVERT OR BUILD_IFCPYTHON) - if(WITH_OPENCASCADE) - install(TARGETS geometry_serializer ${geometry_serializer_libraries}) - endif() -endif(BUILD_CONVERT OR BUILD_IFCPYTHON) - # Cmake uninstall target if(NOT TARGET uninstall) configure_file( diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index eee834f5c7..1bdad7f032 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -18,22 +18,22 @@ ################################################################################ if(SCHEMA_VERSIONS MATCHES "2x3") -ADD_EXECUTABLE(IfcParseExamples IfcParseExamples.cpp) -TARGET_LINK_LIBRARIES(IfcParseExamples IfcParse) -set_target_properties(IfcParseExamples PROPERTIES FOLDER Examples) -target_compile_features(IfcParseExamples PUBLIC cxx_std_17) + ADD_EXECUTABLE(IfcParseExamples IfcParseExamples.cpp) + TARGET_LINK_LIBRARIES(IfcParseExamples IfcParse) + set_target_properties(IfcParseExamples PROPERTIES FOLDER Examples) + target_compile_features(IfcParseExamples PUBLIC cxx_std_17) -if (WITH_OPENCASCADE) + if(WITH_OPENCASCADE) -ADD_EXECUTABLE(IfcOpenHouse IfcOpenHouse.cpp) -TARGET_LINK_LIBRARIES(IfcOpenHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES}) -set_target_properties(IfcOpenHouse PROPERTIES FOLDER Examples) + ADD_EXECUTABLE(IfcOpenHouse IfcOpenHouse.cpp) + TARGET_LINK_LIBRARIES(IfcOpenHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES}) + set_target_properties(IfcOpenHouse PROPERTIES FOLDER Examples) -ADD_EXECUTABLE(IfcAdvancedHouse IfcAdvancedHouse.cpp) -TARGET_LINK_LIBRARIES(IfcAdvancedHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES}) -set_target_properties(IfcAdvancedHouse PROPERTIES FOLDER Examples) + ADD_EXECUTABLE(IfcAdvancedHouse IfcAdvancedHouse.cpp) + TARGET_LINK_LIBRARIES(IfcAdvancedHouse ${IFCOPENSHELL_LIBRARIES} ${OpenCASCADE_LIBRARIES}) + set_target_properties(IfcAdvancedHouse PROPERTIES FOLDER Examples) -endif() + endif() endif(SCHEMA_VERSIONS MATCHES "2x3") if(SCHEMA_VERSIONS MATCHES "4x3_add2") diff --git a/src/ifcgeom/CMakeLists.txt b/src/ifcgeom/CMakeLists.txt index 5e1bf299d0..dfea18038e 100644 --- a/src/ifcgeom/CMakeLists.txt +++ b/src/ifcgeom/CMakeLists.txt @@ -1,3 +1,8 @@ add_subdirectory(kernels) - set(kernel_libraries ${kernel_libraries} PARENT_SCOPE) + +if((BUILD_CONVERT OR BUILD_IFCPYTHON) AND WITH_OPENCASCADE) + add_subdirectory(Serialization) + set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} PARENT_SCOPE) +endif() + diff --git a/src/ifcgeom/Serialization/CMakeLists.txt b/src/ifcgeom/Serialization/CMakeLists.txt new file mode 100644 index 0000000000..e105effa6c --- /dev/null +++ b/src/ifcgeom/Serialization/CMakeLists.txt @@ -0,0 +1,15 @@ +add_subdirectory(schema) +set(geometry_serializer_libraries ${geometry_serializer_libraries} PARENT_SCOPE) + +add_library(geometry_serializer STATIC Serialization.cpp) +set_target_properties(geometry_serializer PROPERTIES COMPILE_FLAGS "-DIFC_GEOMSERIALIZATION_EXPORTS") +target_link_libraries(geometry_serializer ${geometry_serializer_libraries} IfcParse) +set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} "geometry_serializer" ${geometry_serializer_libraries}) +set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} PARENT_SCOPE) + +file(GLOB IFCGEOM_SERIALIZATION_H_FILE *.h) +install(FILES ${IFCGEOM_SERIALIZATION_H_FILE} + DESTINATION ${INCLUDEDIR}/ifcgeom/Serialization +) + +install(TARGETS geometry_serializer ${geometry_serializer_libraries}) diff --git a/src/ifcgeom/Serialization/schema/CMakeLists.txt b/src/ifcgeom/Serialization/schema/CMakeLists.txt new file mode 100644 index 0000000000..0ff0938674 --- /dev/null +++ b/src/ifcgeom/Serialization/schema/CMakeLists.txt @@ -0,0 +1,7 @@ +foreach(schema ${SCHEMA_VERSIONS}) + add_library(geometry_serializer_ifc${schema} STATIC Serialization.cpp) + target_link_libraries(geometry_serializer_ifc${schema} ${OpenCASCADE_LIBRARIES}) + set_target_properties(geometry_serializer_ifc${schema} PROPERTIES COMPILE_FLAGS "-DIFC_GEOMSERIALIZATION_EXPORTS -DIfcSchema=Ifc${schema}") + list(APPEND geometry_serializer_libraries geometry_serializer_ifc${schema}) +endforeach() +set(geometry_serializer_libraries ${geometry_serializer_libraries} PARENT_SCOPE) \ No newline at end of file