Files
IfcOpenShell/cmake/CMakeLists.txt
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

764 lines
30 KiB
CMake
Raw Normal View History

################################################################################
# #
# This file is part of IfcOpenShell. #
# #
# IfcOpenShell is free software: you can redistribute it and/or modify #
# it under the terms of the Lesser GNU General Public License as published by #
# the Free Software Foundation, either version 3.0 of the License, or #
# (at your option) any later version. #
# #
# IfcOpenShell is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# Lesser GNU General Public License for more details. #
# #
# You should have received a copy of the Lesser GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
2024-06-07 23:48:39 +10:00
cmake_minimum_required(VERSION 3.21)
2025-12-20 13:27:35 +05:00
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
2025-12-20 13:27:35 +05:00
if(CMAKE_CXX_STANDARD LESS 17)
message(FATAL_ERROR "C++17 or newer is required.")
endif()
2023-08-28 09:29:58 +02:00
set(CMAKE_CXX_STANDARD_REQUIRED ON) # not necessary, but encouraged
2024-06-07 23:48:39 +10:00
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# The VERSION file in the repository root is the single source of truth for the
# release version. Read it unconditionally so a plain source build reports the
# real version through buildinfo.cpp instead of the stale hardcoded 0.8.0
# fallback (see #8164). VERSION_OVERRIDE still controls the branch name used
# when ADD_COMMIT_SHA embeds a commit sha.
file(READ "../VERSION" "RELEASE_VERSION_")
string(STRIP "${RELEASE_VERSION_}" RELEASE_VERSION)
message(STATUS "Detected version '${RELEASE_VERSION}'")
add_definitions(-D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
2025-10-03 09:04:43 +02:00
if(POLICY CMP0141) # 3.25+
# Has to be set before `project` to take effect.
2025-12-20 13:27:35 +05:00
cmake_policy(SET CMP0141 NEW) # Support for `CMAKE_MSVC_DEBUG_INFORMATION_FORMAT`.
2025-10-03 09:04:43 +02:00
endif()
2025-08-14 12:13:44 +05:00
if(POLICY CMP0144) # 3.27
2024-06-07 23:48:39 +10:00
cmake_policy(SET CMP0144 NEW) # find_package() uses upper-case <PACKAGENAME>_ROOT variables.
2024-02-19 09:26:18 +01:00
endif()
2025-08-14 12:13:44 +05:00
if(POLICY CMP0167) # 3.30
cmake_policy(SET CMP0167 OLD)
endif()
2011-05-08 11:04:32 +00:00
project(IfcOpenShell VERSION ${RELEASE_VERSION})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
2024-06-07 23:48:39 +10:00
# Include utility macros and functions
include(utilities.cmake)
# use extra version to make pre-release using eg semver
2024-06-08 22:54:23 +01:00
if(NOT DEFINED EXTRA_VERSION)
set(EXTRA_VERSION "-alpha.3")
endif()
2011-05-08 11:04:32 +00:00
2023-08-28 09:29:58 +02:00
option(MINIMAL_BUILD "The build is to make a minimal version of IFC converter from OCCT into IFC." OFF)
2023-09-04 20:54:29 +02:00
option(WASM_BUILD "Build a WebAssembly binary." OFF)
2025-12-20 13:27:35 +05:00
option(
ENABLE_BUILD_OPTIMIZATIONS
"Enable certain compiler and linker optimizations on RelWithDebInfo and Release builds."
OFF
)
2023-09-04 20:54:29 +02:00
option(BUILD_SHARED_LIBS "Build IfcParse and IfcGeom as shared libs (SO/DLL)." OFF)
option(MSVC_PARALLEL_BUILD "Multi-threaded compilation in Microsoft Visual Studio (/MP)" OFF)
option(USE_VLD "Use Visual Leak Detector for debugging memory leaks, MSVC-only." OFF)
option(USE_MMAP "Adds a command line options to parse IFC files from memory mapped files using Boost.Iostreams" OFF)
option(NO_WARN "Disable all warnings" OFF)
2023-08-28 09:29:58 +02:00
option(BUILD_IFCGEOM "Build IfcGeom." ON)
option(BUILD_IFCPYTHON "Build IfcPython." ON)
2023-09-04 20:54:29 +02:00
option(BUILD_CONVERT "Build IfcConvert executable." ON)
option(BUILD_DOCUMENTATION "Build IfcOpenShell Documentation." OFF)
option(BUILD_EXAMPLES "Build example applications." OFF)
option(BUILD_GEOMSERVER "Build IfcGeomServer executable (Open CASCADE is required)." ON)
2023-09-04 20:54:29 +02:00
option(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF)
option(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer" OFF) # QtViewer requires Qt6
option(BUILD_PACKAGE "" OFF)
2025-12-12 13:43:09 +05:00
# Most users probably need just common schemas,
# but we're keeping it `OFF` by default to avoid disruption
# (e.g. all Python distribution would need to adapt this option to be set).
2025-12-20 13:27:35 +05:00
option(
BUILD_ONLY_COMMON_SCHEMAS
2025-12-12 13:43:09 +05:00
"Build only common IFC schemas (2x3, 4, 4x3_add2). By default all schemas will be built."
2025-12-20 13:27:35 +05:00
OFF
)
2025-12-12 13:43:09 +05:00
option(SCHEMA_VERSIONS "Explicitly specify schemas to build." "")
2023-09-04 20:54:29 +02:00
2024-06-07 23:48:39 +10:00
option(WITH_OPENCASCADE "Enable geometry interpretation using Open CASCADE" ON)
option(WITH_CGAL "Enable geometry interpretation using CGAL" ON)
2023-09-04 20:54:29 +02:00
option(COLLADA_SUPPORT "Build IfcConvert with COLLADA support (requires OpenCOLLADA)." ON)
option(GLTF_SUPPORT "Build IfcConvert with glTF support (requires json.hpp)." OFF)
2023-08-28 09:29:58 +02:00
option(HDF5_SUPPORT "Enable HDF5 support (requires HDF5, zlib)" ON)
option(WITH_PROJ "Enable output of Earth-Centered Earth-Fixed glTF output using the PROJ library" OFF)
2023-09-04 20:54:29 +02:00
option(IFCXML_SUPPORT "Build IfcParse with ifcXML support (requires libxml2)." ON)
option(USD_SUPPORT "Build IfcConvert with USD support (requires pixar's USD library)." OFF)
2024-06-07 23:48:39 +10:00
option(WITH_RELATIONSHIP_VALIDATION "Build IfcConvert with option to validate geometrical relationships." OFF)
2025-02-21 16:14:01 +01:00
option(WITH_ROCKSDB "Support a RocksDB key-value store as a file backend in IfcOpenShell" OFF)
option(WITH_ZSTD "Use Zstd compression in RocksDB writes" OFF)
2023-08-28 09:29:58 +02:00
2023-09-04 20:54:29 +02:00
option(USERSPACE_PYTHON_PREFIX "Installs IfcPython for the current user only instead of system-wide." OFF)
option(USE_DEBUG_PYTHON "Use debug binaries when building Debug IfcPython on Windows." OFF)
2025-10-03 09:04:43 +02:00
option(ADD_COMMIT_SHA "Add commit sha and branch in version number, requires git" OFF)
2025-12-20 13:27:35 +05:00
option(
VERSION_OVERRIDE
"Override the version defined in buildinfo.cpp with the file VERSION in the repository root"
OFF
)
2025-12-19 19:11:02 +05:00
option(USE_CCACHE "Enable use of ccache if it's available from PATH." ON)
2024-06-25 11:40:42 +02:00
2025-12-20 13:27:35 +05:00
set(PYTHON_MODULE_INSTALL_DIR
""
CACHE PATH
2025-08-13 18:01:31 +05:00
"Directory to install IfcPython package to. By default package is installed in found Python's site-packages."
)
2025-10-04 22:51:51 +02:00
# Make sure CMake modules in this project are found first
list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
2023-09-04 20:54:29 +02:00
if(MINIMAL_BUILD)
message(STATUS "Setting options for minimal build")
set(BUILD_GEOMSERVER OFF)
set(BUILD_IFCPYTHON OFF)
2024-06-07 23:48:39 +10:00
set(WITH_CGAL OFF)
2023-09-04 20:54:29 +02:00
set(COLLADA_SUPPORT OFF)
set(GLTF_SUPPORT OFF)
set(HDF5_SUPPORT OFF)
set(IFCXML_SUPPORT OFF)
set(USD_SUPPORT OFF)
2019-07-10 14:35:56 +02:00
endif()
2019-04-03 15:08:14 +02:00
2025-12-20 13:27:35 +05:00
if((BUILD_CONVERT OR BUILD_GEOMSERVER OR BUILD_IFCPYTHON) AND (NOT BUILD_IFCGEOM))
2023-09-04 20:54:29 +02:00
message(STATUS "'IfcGeom' is required with current outputs")
set(BUILD_IFCGEOM ON)
endif()
2022-03-19 19:32:42 +00:00
find_program(CCACHE_FOUND ccache)
2025-12-19 19:11:02 +05:00
if(USE_CCACHE AND CCACHE_FOUND)
message(STATUS "`ccache` is found, using it as a compiler launcher.")
2025-10-06 12:56:21 +05:00
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND}")
2025-10-03 09:04:43 +02:00
if(MSVC)
# By default Visual Studio generators will use /Zi which is not compatible
# with ccache, so tell Visual Studio to use /Z7 instead.
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
# Not needed for Ninja.
if(CMAKE_GENERATOR MATCHES "Visual Studio")
2025-12-20 13:27:35 +05:00
file(COPY_FILE ${CCACHE_FOUND} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
set(CMAKE_VS_GLOBALS "CLToolExe=cl.exe" "CLToolPath=${CMAKE_BINARY_DIR}" "UseMultiToolTask=true")
2025-10-03 09:04:43 +02:00
endif()
endif()
endif()
mark_as_advanced(CCACHE_FOUND)
2025-10-03 09:04:43 +02:00
2025-12-05 14:29:48 +05:00
# Variable to accumulate swig definitions from various submodules.
set(SWIG_DEFINES "")
2022-06-14 15:25:14 +02:00
if(MSVC AND MSVC_PARALLEL_BUILD)
2023-08-28 09:29:58 +02:00
add_definitions("/MP")
2022-06-14 15:25:14 +02:00
endif()
2023-05-07 11:45:47 +02:00
if(NO_WARN)
if(MSVC)
add_compile_options("/w")
else()
add_compile_options("-w")
endif()
endif()
include(GNUInstallDirs)
2023-08-28 09:29:58 +02:00
2025-12-11 19:22:49 +05:00
set(IFCOPENSHELL_EXPORT_TARGETS "${PROJECT_NAME}Targets")
# On Windows Release and Debug binaries are not compatible.
# So we add a postfix to avoid issues and allow release and debug installations to coexist.
if(WIN32)
set(CMAKE_DEBUG_POSTFIX "_d")
endif()
2023-08-28 09:29:58 +02:00
if(BUILD_SHARED_LIBS)
add_definitions(-DIFC_SHARED_BUILD)
2023-08-28 09:29:58 +02:00
if(MSVC)
2025-12-20 13:27:35 +05:00
message(
WARNING
"Building DLLs against the static VC run-time. This is not recommended if the DLLs are to be redistributed."
)
2016-05-31 14:45:22 +03:00
# C4521: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
# There will be couple hundreds of these so suppress them away, https://msdn.microsoft.com/en-us/library/esew7y1w.aspx
add_definitions(-wd4251)
endif()
endif()
2016-05-15 15:47:21 +02:00
2022-09-13 16:20:30 +02:00
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
2023-08-28 09:29:58 +02:00
if(NOT MINIMAL_BUILD)
2025-10-06 16:29:09 +05:00
UNIFY_ENVVARS_AND_CACHE(PYTHON_INCLUDE_DIR)
UNIFY_ENVVARS_AND_CACHE(PYTHON_LIBRARY)
2023-08-28 09:29:58 +02:00
UNIFY_ENVVARS_AND_CACHE(PYTHON_EXECUTABLE)
endif()
2024-06-07 23:48:39 +10:00
# Get a list of all OPTION flags from the CMakeLists.txt
get_all_option_flags(option_flags)
# Loop through the list of OPTION flags and convert the corresponding environment variables
foreach(option_flag IN LISTS option_flags)
convert_env_var_to_bool("${option_flag}")
endforeach()
if(BUILD_IFCGEOM AND WITH_OPENCASCADE)
find_package(OpenCASCADE REQUIRED)
2024-06-07 23:48:39 +10:00
add_definitions(-DIFOPSH_WITH_OPENCASCADE)
set(SWIG_DEFINES ${SWIG_DEFINES} -DIFOPSH_WITH_OPENCASCADE)
list(APPEND GEOMETRY_KERNELS opencascade)
endif()
2025-12-05 15:26:48 +05:00
set(GLTF_LIBRARIES "")
if(GLTF_SUPPORT)
2025-12-05 15:26:48 +05:00
find_package(nlohmann_json REQUIRED)
set(GLTF_LIBRARIES nlohmann_json::nlohmann_json)
2023-08-28 09:29:58 +02:00
add_definitions(-DWITH_GLTF)
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_GLTF)
endif()
2025-08-12 12:49:20 +05:00
# Add USD support to serializers
2025-12-05 20:16:33 +05:00
set(USD_LIBRARIES "")
2023-09-04 20:54:29 +02:00
if(USD_SUPPORT)
2025-11-19 19:30:54 +05:00
find_package(USD REQUIRED)
2025-12-08 12:15:46 +05:00
set(USD_LIBRARIES pxr::USD)
2024-06-07 23:48:39 +10:00
endif(USD_SUPPORT)
2016-05-15 15:47:21 +02:00
set(ROCKSDB_LIBRARIES "")
2025-12-20 13:27:35 +05:00
if(WITH_ROCKSDB)
2025-10-03 09:04:43 +02:00
# Temporaily mess with CMAKE_FIND_PACKAGE_PREFER_CONFIG to help RocksDB
# find it's zstd dependency on Windows.
# Only do it on Windows, otherwise it might create problems as
# findzstd and zstd-config target names do not match.
# https://github.com/facebook/rocksdb/pull/13975
2025-10-03 09:04:43 +02:00
if(WIN32)
set(TEMP CMAKE_FIND_PACKAGE_PREFER_CONFIG)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
endif()
2025-10-03 09:04:43 +02:00
find_package(RocksDB CONFIG REQUIRED)
mark_as_advanced(RocksDB_DIR)
2025-10-03 09:04:43 +02:00
if(WIN32)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${TEMP})
endif()
2025-10-03 09:04:43 +02:00
message(STATUS "RocksDB: found at '${RocksDB_DIR}'.")
add_library(IFCOPENSHELL_RocksDB INTERFACE)
set(ROCKSDB_LIBRARIES "IFCOPENSHELL_RocksDB")
target_compile_definitions(IFCOPENSHELL_RocksDB INTERFACE IFOPSH_WITH_ROCKSDB)
set(SWIG_DEFINES ${SWIG_DEFINES} -DIFOPSH_WITH_ROCKSDB)
2026-02-11 20:40:45 +05:00
# See https://github.com/facebook/rocksdb/issues/981.
if(TARGET RocksDB::rocksdb)
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE RocksDB::rocksdb)
elseif(TARGET RocksDB::rocksdb-shared)
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE RocksDB::rocksdb-shared)
else()
message(FATAL_ERROR "RocksDB found but neither RocksDB::rocksdb nor RocksDB::rocksdb-shared target exists")
endif()
2025-12-20 13:27:35 +05:00
if(WITH_ZSTD)
2025-09-11 13:53:44 +02:00
# @todo do we actually need the zstd include dir or rather just pass
# the libzstd.a along with the rocksdb library when needed and feature
# detect based on rocksdb API?
2025-10-03 09:04:43 +02:00
find_package(zstd CONFIG REQUIRED)
mark_as_advanced(zstd_DIR)
2025-10-03 09:04:43 +02:00
message(STATUS "zstd: found at '${zstd_DIR}'.")
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE zstd::libzstd_static)
endif()
2025-12-20 13:27:35 +05:00
install(TARGETS IFCOPENSHELL_RocksDB EXPORT ${IFCOPENSHELL_EXPORT_TARGETS})
2025-02-21 16:14:01 +01:00
endif()
# Find Boost: On win32 the (hardcoded) default is to use static libraries and
# runtime, when doing running conda-build we pick what conda prepared for us.
2025-12-05 14:29:48 +05:00
if(WIN32 AND NOT DEFINED ENV{CONDA_BUILD})
2023-08-28 09:29:58 +02:00
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_USE_MULTITHREADED ON)
2020-12-30 12:25:21 +01:00
# Disable Boost's autolinking as the libraries to be linked to are supplied
# already by CMake, and wrong libraries would be asked for when code is
# compiled with a toolset different from default.
if(MSVC)
2023-08-28 09:29:58 +02:00
add_definitions(-DBOOST_ALL_NO_LIB)
2020-12-30 12:25:21 +01:00
# Necessary for boost version >= 1.67
2023-08-28 09:29:58 +02:00
set(BCRYPT_LIBRARIES "bcrypt.lib")
endif()
else()
2018-03-16 12:17:49 +01:00
# Disable Boost's autolinking as the libraries to be linked to are supplied
# already by CMake, and it's going to conflict if there are multiple, as is
# the case in conda-forge's libboost feedstock.
2023-08-28 09:29:58 +02:00
add_definitions(-DBOOST_ALL_NO_LIB)
if(WIN32)
# Necessary for boost version >= 1.67
2023-08-28 09:29:58 +02:00
set(BCRYPT_LIBRARIES "bcrypt.lib")
endif()
endif()
2017-07-23 14:52:04 +02:00
2024-06-07 23:48:39 +10:00
if(WASM_BUILD)
2023-08-28 14:50:58 +02:00
set(BOOST_COMPONENTS)
else()
# @todo review this, shouldn't this be all possible header-only now?
# ... or rewritten using C++17 features?
# Boost.System has been header-only since 1.69 and its compiled stub library
# was dropped in newer Boost, so requesting it as a component makes
# find_package fail on Boost 1.70 and up (for example Boost 1.90). It is
# still pulled in transitively by thread / iostreams where needed, so do not
# request it explicitly.
2025-12-20 13:27:35 +05:00
set(BOOST_COMPONENTS
program_options
regex
thread
date_time
iostreams
)
2023-08-28 14:50:58 +02:00
endif()
2017-07-23 14:52:04 +02:00
if(USE_MMAP)
if(MSVC)
# filesystem is necessary for the utf-16 wpath
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} iostreams filesystem)
else()
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} iostreams)
endif()
2023-08-28 09:29:58 +02:00
2017-07-23 14:52:04 +02:00
add_definitions(-DUSE_MMAP)
endif()
# Handle CGAL after Boost settings are set, since CGAL will use them too.
# Do `find_package(Boost)` only after this, to make sure `FindBoost` finds correct components.
# Otherwise it will find components needed for CGAL and we might some libraries.
if(WITH_CGAL)
find_package(CGAL REQUIRED)
2025-12-12 18:58:04 +05:00
set(CGAL_LIBRARIES IFCOPENSHELL_CGAL)
list(APPEND GEOMETRY_KERNELS cgal)
endif()
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}")
2025-11-20 16:48:48 +05:00
if(COLLADA_SUPPORT)
find_package(OpenCOLLADA REQUIRED)
add_definitions(-DWITH_OPENCOLLADA)
endif()
2023-09-04 20:54:29 +02:00
if(HDF5_SUPPORT)
2025-10-04 22:51:51 +02:00
find_package(HDF5 REQUIRED COMPONENTS C CXX)
2025-12-05 13:26:06 +01:00
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} hdf5::hdf5_cpp)
2023-08-28 09:29:58 +02:00
2021-08-31 11:03:28 +02:00
add_definitions(-DWITH_HDF5)
2023-08-28 09:29:58 +02:00
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_HDF5)
2024-06-07 23:48:39 +10:00
endif(HDF5_SUPPORT)
2021-02-05 13:47:54 +01:00
if(ENABLE_BUILD_OPTIMIZATIONS)
2023-08-28 09:29:58 +02:00
if(MSVC)
# NOTE: RelWithDebInfo and Release use O2 (= /Ox /Gl /Gy/ = Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy) by default,
# with the exception with RelWithDebInfo has /Ob1 instead. /Ob2 has been observed to improve the performance
# of IfcConvert significantly.
# TODO Setting of /GL and /LTCG don't seem to apply for static libraries (IfcGeom, IfcParse)
2023-08-28 09:29:58 +02:00
# C++
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /GL")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
# Linker
# /OPT:REF enables also /OPT:ICF and disables INCREMENTAL
set(LINKER_FLAGS_RELEASE "/LTCG /OPT:REF")
2023-08-28 09:29:58 +02:00
# /OPT:NOICF is recommended when /DEBUG is used (http://msdn.microsoft.com/en-us/library/xe4t6fc1.aspx)
set(LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /OPT:NOICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELEASE}")
2026-02-27 11:18:35 +05:00
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELWITHDEBINFO}"
)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELWITHDEBINFO}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELEASE}")
2026-02-27 11:18:35 +05:00
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_RELWITHDEBINFO}"
)
2023-08-28 09:29:58 +02:00
else()
# GCC-like: Release should use O3 but RelWithDebInfo 02 so enforce 03. Anything other useful that could be added here?
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -O3")
2023-08-28 09:29:58 +02:00
endif()
else()
2024-06-07 23:48:39 +10:00
# @tfk I commented this out as this kind of defeats the purpose of RelWithDebInfo. For the
# best debugging experience simply use Debug. Note that in MSVC you can selectively toggle
# optimization on a specific file if you're investigating a specific issue.
# if(MSVC)
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Od")
# endif()
endif(ENABLE_BUILD_OPTIMIZATIONS)
2023-08-28 09:29:58 +02:00
if(MSVC)
# warning due to virtual inheritance
add_definitions(-wd4250)
# warning due to select definitions in the schema being redundant
add_definitions(-wd4584)
# didn't work well on ifcopenbot, @todo make configurable
# add_definitions(/MP)
2021-07-11 14:55:27 +02:00
2016-02-21 16:52:00 +02:00
# Enable solution folders (free VS versions prior to 2012 don't support solution folders)
2023-08-28 09:29:58 +02:00
if(MSVC_VERSION GREATER 1600)
2016-02-20 00:13:04 +02:00
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
2023-08-28 09:29:58 +02:00
if(USE_VLD)
add_definitions(-DUSE_VLD)
endif()
# Enforce Unicode for CRT and Win32 API calls
add_definitions(-D_UNICODE -DUNICODE)
# Disable warnings about unsafe C functions; we could use the safe C99 & C11 versions if we have no need for supporting old compilers.
add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
add_definitions(-bigobj) # required for building the big ifcXXX.objs, https://msdn.microsoft.com/en-us/library/ms173499.aspx
# Bump up the warning level from the default 3 to 4.
add_definitions(-W4)
if(MSVC_VERSION GREATER 1800) # > 2013
# Disable overeager and false positives causing C4458 ("declaration of 'indentifier' hides class member"), at least for now.
add_definitions(-wd4458)
endif()
# Enforce standards-conformance on VS > 2015, older Boost versions fail to compile with this
2025-12-20 13:27:35 +05:00
if(MSVC_VERSION GREATER 1900 AND (Boost_MAJOR_VERSION GREATER 1 OR Boost_MINOR_VERSION GREATER 66))
add_definitions(-permissive-)
endif()
2023-08-28 09:29:58 +02:00
2024-06-07 23:48:39 +10:00
# Link against the static VC runtime
# TODO Make this configurable
# if("$ENV{CONDA_BUILD}" STREQUAL "")
# foreach(flag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL
# CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
# CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
# if(${flag} MATCHES "/MD")
# STRING(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
# endif()
# if(${flag} MATCHES "/MDd")
# STRING(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}")
# endif()
# endforeach()
# endif()
2025-12-20 13:27:35 +05:00
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
# See #5158.
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.40)
add_definitions(-D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()
2023-08-28 09:29:58 +02:00
else()
2018-12-22 14:05:49 +01:00
add_definitions(-Wall -Wextra)
2023-08-28 09:29:58 +02:00
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2016-10-09 13:39:47 +03:00
add_definitions(-Wno-tautological-constant-out-of-range-compare)
2018-12-22 14:05:49 +01:00
else()
add_definitions(-Wno-maybe-uninitialized)
2016-10-09 13:39:47 +03:00
endif()
2023-08-28 09:29:58 +02:00
2025-12-20 13:27:35 +05:00
if(
CMAKE_CXX_COMPILER_ID MATCHES "GNU"
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 9.0)
)
2021-03-20 21:23:05 +02:00
# OpenCascade spews a lot of deprecated-copy warnings
add_definitions(-Wno-deprecated-copy)
endif()
2023-08-28 09:29:58 +02:00
# -fPIC is not relevant on Windows and creates pointless warnings
2023-08-28 09:29:58 +02:00
if(UNIX)
add_definitions(-fPIC)
endif()
2024-06-07 23:48:39 +10:00
endif(MSVC)
2011-05-08 11:04:32 +00:00
2025-12-20 13:27:35 +05:00
include_directories(${OPENCOLLADA_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${HDF5_INCLUDE_DIR})
2021-07-10 21:10:03 +02:00
if(NOT SCHEMA_VERSIONS)
2025-12-12 13:43:09 +05:00
# `WASM_BUILD` - super arbitrarily try to keep size down at least a little bit
if(BUILD_ONLY_COMMON_SCHEMAS OR WASM_BUILD)
set(SCHEMA_VERSIONS "2x3" "4" "4x3_add2")
else()
2025-12-20 13:27:35 +05:00
set(SCHEMA_VERSIONS
"2x3"
"4"
"4x1"
"4x2"
"4x3"
"4x3_tc1"
"4x3_add1"
"4x3_add2"
)
endif()
2021-07-10 21:10:03 +02:00
endif()
message(STATUS "IFC SCHEMA_VERSIONS that will be used for the build: ${SCHEMA_VERSIONS}.")
set(SCHEMA_DEFINITIONS "")
foreach(schema ${SCHEMA_VERSIONS})
list(APPEND SCHEMA_DEFINITIONS "-DHAS_SCHEMA_${schema}")
endforeach()
2022-07-17 21:13:46 +02:00
string(REPLACE ";" ")(" schema_version_seq "(${SCHEMA_VERSIONS})")
list(APPEND SCHEMA_DEFINITIONS "-DSCHEMA_SEQ=${schema_version_seq}")
2022-07-17 21:13:46 +02:00
if(COMPILE_SCHEMA)
2023-08-28 09:29:58 +02:00
# @todo, this appears to be untested at the moment
find_package(PythonInterp)
2023-08-28 09:29:58 +02:00
if(NOT PYTHONINTERP_FOUND)
2025-12-20 13:27:35 +05:00
message(
FATAL_ERROR
"A Python interpreter is necessary when COMPILE_SCHEMA is enabled. Disable COMPILE_SCHEMA or fix Python paths to proceed."
)
2023-08-28 09:29:58 +02:00
endif()
set(IFC_RELEASE_NOT_USED ${SCHEMA_VERSIONS})
# Install pyparsing if necessary
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip freeze OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
2023-08-28 09:29:58 +02:00
if("${PYTHON_PACKAGE_LIST}" STREQUAL "")
execute_process(COMMAND pip freeze OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
2023-08-28 09:29:58 +02:00
if("${PYTHON_PACKAGE_LIST}" STREQUAL "")
message(WARNING "Failed to find pip. Pip is required to automatically install pyparsing")
endif()
endif()
2023-08-28 09:29:58 +02:00
string(FIND "${PYTHON_PACKAGE_LIST}" pyparsing PYPARSING_FOUND)
2023-08-28 09:29:58 +02:00
if("${PYPARSING_FOUND}" STREQUAL "-1")
message(STATUS "Installing pyparsing")
2025-12-20 13:27:35 +05:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -m pip "install" --user pyparsing
RESULT_VARIABLE SUCCESS
)
2023-08-28 09:29:58 +02:00
if(NOT "${SUCCESS}" STREQUAL "0")
execute_process(COMMAND pip "install" --user pyparsing RESULT_VARIABLE SUCCESS)
2023-08-28 09:29:58 +02:00
if(NOT "${SUCCESS}" STREQUAL "0")
message(WARNING "Failed to automatically install pyparsing. Please install manually")
endif()
endif()
else()
message(STATUS "Python interpreter with pyparsing found")
endif()
# Bootstrap the parser
message(STATUS "Compiling schema, this will take a while...")
2025-12-20 13:27:35 +05:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} bootstrap.py
WORKING_DIRECTORY ../src/ifcopenshell-python/ifcopenshell/express
OUTPUT_FILE express_parser.py
2025-12-20 13:27:35 +05:00
RESULT_VARIABLE SUCCESS
)
2023-08-28 09:29:58 +02:00
if(NOT "${SUCCESS}" STREQUAL "0")
message(FATAL_ERROR "Failed to bootstrap parser. Make sure pyparsing is installed")
endif()
# Generate code
2025-12-20 13:27:35 +05:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} ../ifcopenshell-python/ifcopenshell/express/express_parser.py ../../${COMPILE_SCHEMA}
WORKING_DIRECTORY ../src/ifcparse
2025-12-20 13:27:35 +05:00
OUTPUT_VARIABLE COMPILED_SCHEMA_NAME
)
# Prevent the schema that had just been compiled from being excluded
foreach(schema ${SCHEMA_VERSIONS})
if("${COMPILED_SCHEMA_NAME}" STREQUAL "${schema}")
list(REMOVE_ITEM IFC_RELEASE_NOT_USED "${schema}")
2023-08-28 09:29:58 +02:00
endif()
endforeach()
2024-06-07 23:48:39 +10:00
endif(COMPILE_SCHEMA)
2011-08-24 12:21:07 +00:00
# Boost >= 1.58 requires BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE to build on some Linux distros.
2016-05-15 15:47:21 +02:00
if(NOT Boost_VERSION LESS 105800)
add_definitions(-DBOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE)
endif()
add_subdirectory(../src/ifcparse ifcparse)
set(IFCOPENSHELL_LIBRARIES IfcParse)
2024-06-07 23:48:39 +10:00
2023-08-28 09:29:58 +02:00
if(BUILD_IFCGEOM)
add_subdirectory(../src/ifcgeom ifcgeom)
2018-09-08 13:23:36 +02:00
endif(BUILD_IFCGEOM)
2023-08-28 09:29:58 +02:00
if(BUILD_CONVERT OR BUILD_IFCPYTHON)
add_subdirectory(../src/serializers serializers)
set(IFCOPENSHELL_LIBRARIES ${IFCOPENSHELL_LIBRARIES} ${SERIALIZER_SCHEMA_LIBRARIES})
2023-05-09 21:07:36 +02:00
endif(BUILD_CONVERT OR BUILD_IFCPYTHON)
2023-08-28 09:29:58 +02:00
if(BUILD_CONVERT)
add_subdirectory(../src/ifcconvert ifcconvert)
2018-09-08 13:23:36 +02:00
endif(BUILD_CONVERT)
# IfcGeomServer
2023-09-04 20:54:29 +02:00
if(BUILD_GEOMSERVER)
add_subdirectory(../src/ifcgeomserver ifcgeomserver)
2024-06-07 23:48:39 +10:00
endif(BUILD_GEOMSERVER)
2023-08-28 09:29:58 +02:00
if(ADD_COMMIT_SHA)
find_package(Git)
2025-10-03 09:04:43 +02:00
if(NOT GIT_FOUND)
message(FATAL_ERROR "Failed to find Git for ADD_COMMIT_SHA option.")
endif()
2023-08-28 09:29:58 +02:00
if(GIT_FOUND)
2025-12-20 13:27:35 +05:00
if(VERSION_OVERRIDE)
set(git_branch ${RELEASE_VERSION})
2024-06-25 11:40:42 +02:00
else()
message("git found: ${GIT_EXECUTABLE} with version ${GIT_VERSION_STRING}")
execute_process(
COMMAND ${GIT_EXECUTABLE} branch -a --contains HEAD
2025-01-17 13:57:14 +01:00
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2024-06-25 11:40:42 +02:00
OUTPUT_VARIABLE git_branches
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" ";" git_branch_list "${git_branches}")
foreach(git_branch_candidate IN ITEMS ${git_branch_list})
2025-12-20 13:27:35 +05:00
string(REPLACE "*" "" git_branch_candidate_temp "${git_branch_candidate}")
string(STRIP "${git_branch_candidate_temp}" git_branch_candidate_2)
2024-06-25 11:40:42 +02:00
if(NOT git_branch_candidate_2 MATCHES "^HEAD$")
string(REPLACE "/" ";" git_branch_candidate_2_list "${git_branch_candidate_2}")
list(GET git_branch_candidate_2_list -1 git_branch)
endif()
endforeach()
endif()
2018-09-08 13:23:36 +02:00
2023-08-28 09:29:58 +02:00
execute_process(
2025-01-17 13:57:14 +01:00
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
2023-08-28 09:29:58 +02:00
OUTPUT_VARIABLE git_sha
OUTPUT_STRIP_TRAILING_WHITESPACE
)
2025-01-17 13:57:14 +01:00
2023-08-28 09:29:58 +02:00
message(STATUS "IfcOpenShell branch: \"${git_branch}\"")
message(STATUS "IfcOpenShell commit: \"${git_sha}\"")
2025-01-17 13:57:14 +01:00
2025-12-20 13:27:35 +05:00
if("${git_branch}" STREQUAL "" OR "${git_sha}" STREQUAL "")
2025-01-17 13:57:14 +01:00
message(FATAL_ERROR "Unable to determine commit sha and/or branch")
endif()
2025-12-20 13:27:35 +05:00
target_compile_definitions(
IfcParse
PRIVATE -DIFCOPENSHELL_BRANCH=${git_branch} -DIFCOPENSHELL_COMMIT=${git_sha}
2025-10-03 09:04:43 +02:00
)
2023-08-28 09:29:58 +02:00
endif()
2024-06-07 23:48:39 +10:00
endif(ADD_COMMIT_SHA)
# Always expose the release version (from the VERSION file) to buildinfo.cpp so
# that a build without commit-sha info reports the correct version instead of a
# stale hardcoded fallback. See #8164.
target_compile_definitions(IfcParse PRIVATE IFCOPENSHELL_VERSION_STRING=${RELEASE_VERSION})
2024-06-07 23:48:39 +10:00
if(MSVC)
# @todo still needs to be understood better, but the cgal and cgal-simple kernel cause multiply defined boost lambda placeholders _1 ... _3
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /FORCE:MULTIPLE")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /FORCE:MULTIPLE")
2023-08-28 09:29:58 +02:00
endif()
2018-09-08 13:23:36 +02:00
2023-08-28 09:29:58 +02:00
# Documentation
if(BUILD_DOCUMENTATION)
set(CMAKE_MODULE_PATH "../docs/cmake")
add_subdirectory(../docs docs)
2018-09-08 13:23:36 +02:00
endif()
2023-09-04 20:54:29 +02:00
if(BUILD_IFCPYTHON)
2023-08-28 09:29:58 +02:00
add_subdirectory(../src/ifcwrap ifcwrap)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(../src/examples examples)
endif()
if(BUILD_IFCMAX)
add_subdirectory(../src/ifcmax ifcmax)
2023-08-28 09:29:58 +02:00
endif()
if(BUILD_IFCPYTHON AND WITH_CGAL)
2025-08-12 12:49:20 +05:00
add_subdirectory(../src/svgfill svgfill)
2023-08-28 09:29:58 +02:00
endif()
if(BUILD_QTVIEWER)
add_subdirectory(../src/qtviewer qtviewer)
2022-02-10 11:11:49 +03:00
endif()
2022-09-13 16:18:06 +02:00
# Cmake uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2025-12-20 13:27:35 +05:00
IMMEDIATE
@ONLY
)
2022-09-13 16:18:06 +02:00
2025-12-20 13:27:35 +05:00
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
2022-09-13 16:18:06 +02:00
endif()
# Packaging
2025-12-20 13:27:35 +05:00
list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git" "/build/" "/.pytest_cache/" "/__pycache__/")
2024-06-08 22:54:23 +01:00
set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR}/..;/")
2025-12-20 13:27:35 +05:00
set(CPACK_PACKAGE_NAME
"${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${EXTRA_VERSION}"
)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}${EXTRA_VERSION}")
2025-12-20 13:27:35 +05:00
set(CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${EXTRA_VERSION}-${CMAKE_SYSTEM_NAME}"
)
set(CPACK_PACKAGE_DIRECTORY "${PROJECT_BINARY_DIR}/assets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IfcOpenShell")
set(CPACK_PACKAGE_DESCRIPTION "IfcOpenShell.")
set(CPACK_PACKAGE_VENDOR "Cemosis")
set(CPACK_PACKAGE_CONTACT "Christophe Prud'homme <christophe.prudhomme@cemosis.fr>")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_GENERATOR "TGZ;DEB")
set(CPACK_SOURCE_GENERATOR "TGZ")
2021-02-10 07:04:43 +00:00
2025-12-05 14:29:48 +05:00
set(BOOST_DEPS "")
2023-08-28 09:29:58 +02:00
foreach(COMPONENT IN ITEMS ${BOOST_COMPONENTS})
2021-02-09 15:08:22 +00:00
string(REPLACE "_" "-" COMP ${COMPONENT})
2022-08-31 20:48:36 +02:00
set(BOOST_DEPS "${BOOST_DEPS}, libboost-${COMP}-dev")
2021-02-09 15:08:22 +00:00
endforeach(COMPONENT)
2021-02-10 07:04:43 +00:00
set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_CONTACT}")
2025-12-20 13:27:35 +05:00
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"python3, libxml2, libocct-foundation-dev, libocct-modeling-algorithms-dev, libocct-modeling-data-dev, libocct-ocaf-dev, libocct-visualization-dev, libocct-data-exchange-dev, libhdf5-serial-dev, libpython3-dev, python3-pytest ${BOOST_DEPS}"
)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "science")
2025-12-20 13:27:35 +05:00
set(CPACK_DEBIAN_PACKAGE_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}${EXTRA_VERSION}"
)
set(CPACK_DEBIAN_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
2023-08-28 09:29:58 +02:00
# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/debian/postinst")
2024-06-07 23:48:39 +10:00
include(CPack)
2025-12-11 19:22:49 +05:00
include(package_export.cmake)