mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
cmake: move all macros/functions into utility file
This commit is contained in:
committed by
Thomas Krijnen
parent
b3d10ce43e
commit
1263f3c4d3
+3
-74
@@ -33,6 +33,9 @@ if(NOT CMAKE_BUILD_TYPE)
|
|||||||
set(CMAKE_BUILD_TYPE "Release")
|
set(CMAKE_BUILD_TYPE "Release")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Include utility macros and functions
|
||||||
|
include(utilities.cmake)
|
||||||
|
|
||||||
# use extra version to make pre-release using eg semver
|
# use extra version to make pre-release using eg semver
|
||||||
set(EXTRA_VERSION "-alpha.3")
|
set(EXTRA_VERSION "-alpha.3")
|
||||||
|
|
||||||
@@ -138,13 +141,6 @@ if(BUILD_SHARED_LIBS)
|
|||||||
set(IFCOPENSHELL_LIBRARY_DIR "${LIBDIR}")
|
set(IFCOPENSHELL_LIBRARY_DIR "${LIBDIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Create cache entries if absent for environment variables
|
|
||||||
macro(UNIFY_ENVVARS_AND_CACHE VAR)
|
|
||||||
if((NOT DEFINED ${VAR}) AND(NOT "$ENV{${VAR}}" STREQUAL ""))
|
|
||||||
set(${VAR} "$ENV{${VAR}}" CACHE STRING "${VAR}" FORCE)
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
UNIFY_ENVVARS_AND_CACHE(OCC_INCLUDE_DIR)
|
UNIFY_ENVVARS_AND_CACHE(OCC_INCLUDE_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(OCC_LIBRARY_DIR)
|
UNIFY_ENVVARS_AND_CACHE(OCC_LIBRARY_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
|
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
|
||||||
@@ -169,9 +165,6 @@ if(NOT MINIMAL_BUILD)
|
|||||||
UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR)
|
UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include the 'convert_env_var_to_bool' and 'get_all_option_flags' functions
|
|
||||||
include(utilities.cmake)
|
|
||||||
|
|
||||||
# Get a list of all OPTION flags from the CMakeLists.txt
|
# Get a list of all OPTION flags from the CMakeLists.txt
|
||||||
get_all_option_flags(option_flags)
|
get_all_option_flags(option_flags)
|
||||||
|
|
||||||
@@ -264,22 +257,6 @@ if(USD_SUPPORT)
|
|||||||
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_USD)
|
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_USD)
|
||||||
endif(USD_SUPPORT)
|
endif(USD_SUPPORT)
|
||||||
|
|
||||||
# Set INSTALL_RPATH for target
|
|
||||||
macro(SET_INSTALL_RPATHS _target _paths)
|
|
||||||
set(${_target}_rpaths "")
|
|
||||||
|
|
||||||
foreach(_path ${_paths})
|
|
||||||
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_path}" isSystemDir)
|
|
||||||
|
|
||||||
if("${isSystemDir}" STREQUAL "-1")
|
|
||||||
list(APPEND ${_target}_rpaths ${_path})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
message(STATUS "Set INSTALL_RPATH for ${_target}: ${${_target}_rpaths}")
|
|
||||||
set_target_properties(${_target} PROPERTIES INSTALL_RPATH "${${_target}_rpaths}")
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
# Find Boost: On win32 the (hardcoded) default is to use static libraries and
|
# 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.
|
# runtime, when doing running conda-build we pick what conda prepared for us.
|
||||||
if(WIN32 AND("$ENV{CONDA_BUILD}" STREQUAL ""))
|
if(WIN32 AND("$ENV{CONDA_BUILD}" STREQUAL ""))
|
||||||
@@ -341,44 +318,6 @@ if(IFCXML_SUPPORT)
|
|||||||
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_IFCXML)
|
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_IFCXML)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# set(SOME_LIRARIES foo bar)
|
|
||||||
# add_debug_variants(SOME_LIRARIES "${SOME_LIRARIES}" d)
|
|
||||||
# "foo bar" -> "optimized foo debug food optimized bar debug bard"
|
|
||||||
# or
|
|
||||||
# set(SOME_LIRARIES path/foo.lib)
|
|
||||||
# add_debug_variants(SOME_LIRARIES "${SOME_LIRARIES}" "d")
|
|
||||||
# "path/foo.lib" -> "optimized path/foo.lib debug path/food.lib"
|
|
||||||
# TODO Could be refined: take the library file extension as a parameter and
|
|
||||||
# make sure the lib variable ends with not just contains it.
|
|
||||||
function(add_debug_variants NAME LIBRARIES POSTFIX)
|
|
||||||
set(LIBRARIES_STR "${LIBRARIES}")
|
|
||||||
set(LIBRARIES "")
|
|
||||||
|
|
||||||
# the result, "optimized <lib> debug <lib>", needs to be a list instead of a string
|
|
||||||
foreach(lib ${LIBRARIES_STR})
|
|
||||||
list(APPEND LIBRARIES optimized)
|
|
||||||
|
|
||||||
if("${lib}" MATCHES ".lib")
|
|
||||||
string(REPLACE ".lib" "" lib ${lib})
|
|
||||||
list(APPEND LIBRARIES ${lib}.lib)
|
|
||||||
else()
|
|
||||||
list(APPEND LIBRARIES ${lib})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(APPEND LIBRARIES debug)
|
|
||||||
|
|
||||||
if("${lib}" MATCHES ".lib")
|
|
||||||
string(REPLACE ".lib" "" lib ${lib})
|
|
||||||
list(APPEND LIBRARIES ${lib}${POSTFIX}.lib)
|
|
||||||
else()
|
|
||||||
list(APPEND LIBRARIES ${lib}${POSTFIX})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(${NAME} ${LIBRARIES} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
if(BUILD_IFCGEOM)
|
if(BUILD_IFCGEOM)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_debug_variants(LIBXML2_LIBRARIES "${LIBXML2_LIBRARIES}" d)
|
add_debug_variants(LIBXML2_LIBRARIES "${LIBXML2_LIBRARIES}" d)
|
||||||
@@ -756,16 +695,6 @@ include_directories(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCL
|
|||||||
${EIGEN_DIR} ${CGAL_INCLUDE_DIR} ${GMP_INCLUDE_DIR} ${MPFR_INCLUDE_DIR} ${USD_INCLUDE_DIR}
|
${EIGEN_DIR} ${CGAL_INCLUDE_DIR} ${GMP_INCLUDE_DIR} ${MPFR_INCLUDE_DIR} ${USD_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
function(files_for_ifc_version IFC_VERSION RESULT_NAME)
|
|
||||||
set(IFC_PARSE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse)
|
|
||||||
set(${RESULT_NAME}
|
|
||||||
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.h
|
|
||||||
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}enum.h
|
|
||||||
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.cpp
|
|
||||||
PARENT_SCOPE
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
if(NOT SCHEMA_VERSIONS)
|
if(NOT SCHEMA_VERSIONS)
|
||||||
if(WASM_BUILD)
|
if(WASM_BUILD)
|
||||||
# super arbitrarily try to keep size down at least a little bit
|
# super arbitrarily try to keep size down at least a little bit
|
||||||
|
|||||||
@@ -1,3 +1,46 @@
|
|||||||
|
################################################################################
|
||||||
|
# #
|
||||||
|
# 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/>. #
|
||||||
|
# #
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Create a cache entry if absent for environment variables
|
||||||
|
macro(UNIFY_ENVVARS_AND_CACHE VAR)
|
||||||
|
if((NOT DEFINED ${VAR}) AND(NOT "$ENV{${VAR}}" STREQUAL ""))
|
||||||
|
set(${VAR} "$ENV{${VAR}}" CACHE STRING "${VAR}" FORCE)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Set INSTALL_RPATH for target with given paths
|
||||||
|
macro(SET_INSTALL_RPATHS _target _paths)
|
||||||
|
set(${_target}_rpaths "")
|
||||||
|
|
||||||
|
foreach(_path ${_paths})
|
||||||
|
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_path}" isSystemDir)
|
||||||
|
|
||||||
|
if("${isSystemDir}" STREQUAL "-1")
|
||||||
|
list(APPEND ${_target}_rpaths ${_path})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
message(STATUS "Set INSTALL_RPATH for ${_target}: ${${_target}_rpaths}")
|
||||||
|
set_target_properties(${_target} PROPERTIES INSTALL_RPATH "${${_target}_rpaths}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Get a list of all OPTION flags from the CMakeLists.txt and store in an output LIST
|
||||||
function(get_all_option_flags output_list)
|
function(get_all_option_flags output_list)
|
||||||
# Read the contents of the CMakeLists.txt
|
# Read the contents of the CMakeLists.txt
|
||||||
file(READ "${CMAKE_SOURCE_DIR}/CMakeLists.txt" cmake_contents)
|
file(READ "${CMAKE_SOURCE_DIR}/CMakeLists.txt" cmake_contents)
|
||||||
@@ -16,6 +59,7 @@ function(get_all_option_flags output_list)
|
|||||||
set(${output_list} "${option_flags}" PARENT_SCOPE)
|
set(${output_list} "${option_flags}" PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Loop through a LIST of OPTION flags and convert to corresponding environment variables
|
||||||
function(convert_env_var_to_bool var_name)
|
function(convert_env_var_to_bool var_name)
|
||||||
if(DEFINED ENV{${var_name}})
|
if(DEFINED ENV{${var_name}})
|
||||||
string(TOUPPER "$ENV{${var_name}}" bool_value)
|
string(TOUPPER "$ENV{${var_name}}" bool_value)
|
||||||
@@ -29,4 +73,52 @@ function(convert_env_var_to_bool var_name)
|
|||||||
else()
|
else()
|
||||||
# Not defined, leave it as a string
|
# Not defined, leave it as a string
|
||||||
endif()
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# set(SOME_LIRARIES foo bar)
|
||||||
|
# add_debug_variants(SOME_LIRARIES "${SOME_LIRARIES}" d)
|
||||||
|
# "foo bar" -> "optimized foo debug food optimized bar debug bard"
|
||||||
|
# or
|
||||||
|
# set(SOME_LIRARIES path/foo.lib)
|
||||||
|
# add_debug_variants(SOME_LIRARIES "${SOME_LIRARIES}" "d")
|
||||||
|
# "path/foo.lib" -> "optimized path/foo.lib debug path/food.lib"
|
||||||
|
# TODO Could be refined: take the library file extension as a parameter and
|
||||||
|
# make sure the lib variable ends with not just contains it.
|
||||||
|
function(add_debug_variants NAME LIBRARIES POSTFIX)
|
||||||
|
set(LIBRARIES_STR "${LIBRARIES}")
|
||||||
|
set(LIBRARIES "")
|
||||||
|
|
||||||
|
# the result, "optimized <lib> debug <lib>", needs to be a list instead of a string
|
||||||
|
foreach(lib ${LIBRARIES_STR})
|
||||||
|
list(APPEND LIBRARIES optimized)
|
||||||
|
|
||||||
|
if("${lib}" MATCHES ".lib")
|
||||||
|
string(REPLACE ".lib" "" lib ${lib})
|
||||||
|
list(APPEND LIBRARIES ${lib}.lib)
|
||||||
|
else()
|
||||||
|
list(APPEND LIBRARIES ${lib})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND LIBRARIES debug)
|
||||||
|
|
||||||
|
if("${lib}" MATCHES ".lib")
|
||||||
|
string(REPLACE ".lib" "" lib ${lib})
|
||||||
|
list(APPEND LIBRARIES ${lib}${POSTFIX}.lib)
|
||||||
|
else()
|
||||||
|
list(APPEND LIBRARIES ${lib}${POSTFIX})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(${NAME} ${LIBRARIES} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(files_for_ifc_version IFC_VERSION RESULT_NAME)
|
||||||
|
set(IFC_PARSE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/ifcparse)
|
||||||
|
set(${RESULT_NAME}
|
||||||
|
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.h
|
||||||
|
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}enum.h
|
||||||
|
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.cpp
|
||||||
|
PARENT_SCOPE
|
||||||
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
Reference in New Issue
Block a user