mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
Let CMake find python interpreter for schema compilation and installation dir
Remove unused compiled schema in cpp installation target
This commit is contained in:
+28
-32
@@ -288,32 +288,32 @@ function(files_for_ifc_version IFC_VERSION RESULT_NAME)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(COMPILE_SCHEMA)
|
if(COMPILE_SCHEMA)
|
||||||
|
find_package(PythonInterp)
|
||||||
|
|
||||||
|
IF(NOT PYTHONINTERP_FOUND)
|
||||||
|
MESSAGE(FATAL_ERROR "A Python interpreter is necessary when COMPILE_SCHEMA is enabled. Disable COMPILE_SCHEMA or fix Python paths to proceed.")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
set(IFC_RELEASE_NOT_USED "2x3" "4")
|
set(IFC_RELEASE_NOT_USED "2x3" "4")
|
||||||
|
|
||||||
if(PYTHON_EXECUTABLE)
|
|
||||||
set(PYTHON_EXECUTABLE_USED ${PYTHON_EXECUTABLE})
|
|
||||||
else()
|
|
||||||
set(PYTHON_EXECUTABLE_USED "python")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Install pyparsing if necessary
|
# Install pyparsing if necessary
|
||||||
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} -m pip "list" OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip "list" OUTPUT_VARIABLE PYTHON_PACKAGE_LIST)
|
||||||
string(FIND "${PYTHON_PACKAGE_LIST}" pyparsing PYPARSING_FOUND)
|
string(FIND "${PYTHON_PACKAGE_LIST}" pyparsing PYPARSING_FOUND)
|
||||||
if ("${PYPARSING_FOUND}" STREQUAL "-1")
|
if ("${PYPARSING_FOUND}" STREQUAL "-1")
|
||||||
message(STATUS "Installing pyparsing")
|
message(STATUS "Installing pyparsing")
|
||||||
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} -m pip "install" --user pyparsing)
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip "install" --user pyparsing)
|
||||||
else()
|
else()
|
||||||
message(STATUS "Python interpreter with pyparsing found")
|
message(STATUS "Python interpreter with pyparsing found")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Bootstrap the parser
|
# Bootstrap the parser
|
||||||
message(STATUS "Compiling schema, this will take a while...")
|
message(STATUS "Compiling schema, this will take a while...")
|
||||||
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} bootstrap.py express.bnf
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} bootstrap.py express.bnf
|
||||||
WORKING_DIRECTORY ../src/ifcexpressparser
|
WORKING_DIRECTORY ../src/ifcexpressparser
|
||||||
OUTPUT_FILE express_parser.py)
|
OUTPUT_FILE express_parser.py)
|
||||||
|
|
||||||
# Generate code
|
# Generate code
|
||||||
execute_process(COMMAND ${PYTHON_EXECUTABLE_USED} ../ifcexpressparser/express_parser.py ../../${COMPILE_SCHEMA}
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} ../ifcexpressparser/express_parser.py ../../${COMPILE_SCHEMA}
|
||||||
WORKING_DIRECTORY ../src/ifcparse
|
WORKING_DIRECTORY ../src/ifcparse
|
||||||
OUTPUT_VARIABLE COMPILED_SCHEMA_NAME)
|
OUTPUT_VARIABLE COMPILED_SCHEMA_NAME)
|
||||||
|
|
||||||
@@ -334,28 +334,31 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# IfcParse
|
# IfcParse
|
||||||
file(GLOB CPP_FILES ../src/ifcparse/*.cpp)
|
file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h)
|
||||||
file(GLOB H_FILES ../src/ifcparse/*.h)
|
file(GLOB IFCPARSE_CPP_FILES ../src/ifcparse/*.cpp)
|
||||||
set(SOURCE_FILES ${CPP_FILES} ${H_FILES})
|
|
||||||
|
|
||||||
foreach(IFC_RELEASE ${IFC_RELEASE_NOT_USED})
|
foreach(IFC_RELEASE ${IFC_RELEASE_NOT_USED})
|
||||||
files_for_ifc_version(${IFC_RELEASE} SOURCE_FILES_NOT_USED)
|
files_for_ifc_version(${IFC_RELEASE} SOURCE_FILES_NOT_USED)
|
||||||
foreach(SOURCE_FILE ${SOURCE_FILES_NOT_USED})
|
foreach(SOURCE_FILE ${SOURCE_FILES_NOT_USED})
|
||||||
list(REMOVE_ITEM SOURCE_FILES ${SOURCE_FILE})
|
list(REMOVE_ITEM IFCPARSE_CPP_FILES ${SOURCE_FILE})
|
||||||
|
list(REMOVE_ITEM IFCPARSE_H_FILES ${SOURCE_FILE})
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
ADD_LIBRARY(IfcParse STATIC ${SOURCE_FILES})
|
set(IFCPARSE_FILES ${IFCPARSE_CPP_FILES} ${IFCPARSE_H_FILES})
|
||||||
|
|
||||||
|
ADD_LIBRARY(IfcParse STATIC ${IFCPARSE_FILES})
|
||||||
|
|
||||||
IF(UNICODE_SUPPORT)
|
IF(UNICODE_SUPPORT)
|
||||||
TARGET_LINK_LIBRARIES(IfcParse ${ICU_LIBRARIES})
|
TARGET_LINK_LIBRARIES(IfcParse ${ICU_LIBRARIES})
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# IfcGeom
|
# IfcGeom
|
||||||
file(GLOB CPP_FILES ../src/ifcgeom/*.cpp)
|
file(GLOB IFCGEOM_H_FILES ../src/ifcgeom/*.h)
|
||||||
file(GLOB H_FILES ../src/ifcgeom/*.h)
|
file(GLOB IFCGEOM_CPP_FILES ../src/ifcgeom/*.cpp)
|
||||||
set(SOURCE_FILES ${CPP_FILES} ${H_FILES})
|
|
||||||
ADD_LIBRARY(IfcGeom STATIC ${SOURCE_FILES})
|
set(IFCGEOM_FILES ${IFCGEOM_CPP_FILES} ${IFCGEOM_H_FILES})
|
||||||
|
ADD_LIBRARY(IfcGeom STATIC ${IFCGEOM_FILES})
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
|
TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
|
||||||
|
|
||||||
@@ -366,10 +369,10 @@ if(NOT WIN32)
|
|||||||
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
|
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
file(GLOB CPP_FILES ../src/ifcconvert/*.cpp)
|
file(GLOB IFCCONVERT_CPP_FILES ../src/ifcconvert/*.cpp)
|
||||||
file(GLOB H_FILES ../src/ifcconvert/*.h)
|
file(GLOB IFCCONVERT_H_FILES ../src/ifcconvert/*.h)
|
||||||
set(SOURCE_FILES ${CPP_FILES} ${H_FILES})
|
set(IFCCONVERT_FILES ${IFCCONVERT_CPP_FILES} ${IFCCONVERT_H_FILES})
|
||||||
ADD_EXECUTABLE(IfcConvert ${SOURCE_FILES})
|
ADD_EXECUTABLE(IfcConvert ${IFCCONVERT_FILES})
|
||||||
|
|
||||||
# Make sure cross-referenced symbols between static OCC libraries get
|
# Make sure cross-referenced symbols between static OCC libraries get
|
||||||
# resolved. Also add thread and rt libraries.
|
# resolved. Also add thread and rt libraries.
|
||||||
@@ -397,15 +400,8 @@ IF(BUILD_EXAMPLES)
|
|||||||
ADD_SUBDIRECTORY(../src/examples examples)
|
ADD_SUBDIRECTORY(../src/examples examples)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# TODO QtViewer is deprecated ATM as it uses the 0.4 API
|
|
||||||
# IF(BUILD_QTVIEWER)
|
|
||||||
# ADD_SUBDIRECTORY(../src/qtviewer qtviewer)
|
|
||||||
# ENDIF()
|
|
||||||
|
|
||||||
# CMake installation targets
|
# CMake installation targets
|
||||||
FILE(GLOB include_files_geom ../src/ifcgeom/*.h)
|
INSTALL(FILES ${IFCPARSE_H_FILES} DESTINATION include/ifcparse)
|
||||||
FILE(GLOB include_files_parse ../src/ifcparse/*.h)
|
INSTALL(FILES ${IFCGEOM_H_FILES} DESTINATION include/ifcgeom)
|
||||||
INSTALL(FILES ${include_files_geom} DESTINATION include/ifcgeom)
|
|
||||||
INSTALL(FILES ${include_files_parse} DESTINATION include/ifcparse)
|
|
||||||
INSTALL(TARGETS IfcConvert IfcGeomServer DESTINATION bin)
|
INSTALL(TARGETS IfcConvert IfcGeomServer DESTINATION bin)
|
||||||
INSTALL(TARGETS IfcParse IfcGeom DESTINATION lib)
|
INSTALL(TARGETS IfcParse IfcGeom DESTINATION lib)
|
||||||
|
|||||||
+24
-16
@@ -54,21 +54,29 @@ SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON)
|
|||||||
SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i)
|
SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i)
|
||||||
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper IfcParse IfcGeom ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${ICU_LIBRARIES})
|
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper IfcParse IfcGeom ${PYTHON_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${ICU_LIBRARIES})
|
||||||
|
|
||||||
# To install IfcPython let's get the site-packages dir from python
|
# Try to find the Python interpreter to get the site-packages
|
||||||
EXECUTE_PROCESS(COMMAND
|
# directory in which the wrapper can be installed.
|
||||||
python -c "import sys; from distutils.sysconfig import get_python_lib; sys.stdout.write(get_python_lib())"
|
FIND_PACKAGE(PythonInterp)
|
||||||
OUTPUT_VARIABLE python_package_dir)
|
IF(PYTHONINTERP_FOUND)
|
||||||
|
EXECUTE_PROCESS(
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} -c "import sys; from distutils.sysconfig import get_python_lib; sys.stdout.write(get_python_lib())"
|
||||||
|
OUTPUT_VARIABLE python_package_dir
|
||||||
|
)
|
||||||
|
|
||||||
IF("${python_package_dir}" STREQUAL "")
|
IF("${python_package_dir}" STREQUAL "")
|
||||||
MESSAGE(FATAL_ERROR "Python executable not in PATH, aborting")
|
MESSAGE(WARNING "Unable to locate Python site-package directory, unable to install the Python wrapper")
|
||||||
|
ELSE()
|
||||||
|
INSTALL(FILES
|
||||||
|
"${CMAKE_BINARY_DIR}/ifcwrap/ifcopenshell_wrapper.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/__init__.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/guid.py"
|
||||||
|
DESTINATION "${python_package_dir}/ifcopenshell")
|
||||||
|
INSTALL(FILES
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/geom/__init__.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/geom/occ_utils.py"
|
||||||
|
DESTINATION "${python_package_dir}/ifcopenshell/geom")
|
||||||
|
INSTALL(TARGETS _ifcopenshell_wrapper DESTINATION "${python_package_dir}/ifcopenshell")
|
||||||
|
ENDIF()
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "No Python interpreter found, unable to install the Python wrapper")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
INSTALL(FILES
|
|
||||||
"${CMAKE_BINARY_DIR}/ifcwrap/ifcopenshell_wrapper.py"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/__init__.py"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/guid.py"
|
|
||||||
DESTINATION "${python_package_dir}/ifcopenshell")
|
|
||||||
INSTALL(FILES
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ifcopenshell-python/ifcopenshell/geom/__init__.py"
|
|
||||||
DESTINATION "${python_package_dir}/ifcopenshell/geom")
|
|
||||||
INSTALL(TARGETS _ifcopenshell_wrapper DESTINATION "${python_package_dir}/ifcopenshell")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user