From 26ed16ba52a15cd7d96a3758c675f66c08e739aa Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Tue, 3 Nov 2015 16:06:20 +0200 Subject: [PATCH] Make possible to switch between Python 2 & 3 easily. Fixes also possible confusion when having both 32-bit and 64-bit Python installations side by side. --- src/ifcwrap/CMakeLists.txt | 50 ++++++++++++++++++++++++++++++++------ win/build-deps.cmd | 6 +++-- win/readme.txt | 5 +++- win/run-cmake.bat | 15 ++++++++++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/ifcwrap/CMakeLists.txt b/src/ifcwrap/CMakeLists.txt index a5a2f36e22..8e65a06b10 100644 --- a/src/ifcwrap/CMakeLists.txt +++ b/src/ifcwrap/CMakeLists.txt @@ -1,9 +1,37 @@ +################################################################################ +# # +# 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 . # +# # +################################################################################ + FIND_PACKAGE(SWIG) IF(SWIG_FOUND) INCLUDE(${SWIG_USE_FILE}) +IF(NOT "$ENV{OCC_LIBRARY_DIR}" STREQUAL "") + SET(PYTHON_INCLUDE_DIR $ENV{PYTHON_INCLUDE_DIR} CACHE FILEPATH "Python header files") + MESSAGE(STATUS "Looking for Python header files in: ${PYTHON_INCLUDE_DIR}") +ENDIF() +IF(NOT "$ENV{OCC_LIBRARY_DIR}" STREQUAL "") + SET(PYTHON_LIBRARY $ENV{PYTHON_LIBRARY} CACHE FILEPATH "Python library file") + MESSAGE(STATUS "Looking for Python library file in: ${PYTHON_LIBRARY}") +ENDIF() + FIND_PACKAGE(PythonLibs) IF(PYTHONLIBS_FOUND) @@ -16,22 +44,30 @@ SET(CMAKE_SWIG_FLAGS "") SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON) SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i) -SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${PYTHON_LIBRARIES} IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKOffset ${ICU_LIBRARIES}) +SWIG_LINK_LIBRARIES(ifcopenshell_wrapper + ${PYTHON_LIBRARIES} IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing + TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKOffset ${ICU_LIBRARIES} +) # To install IfcPython let's get the site-packages dir from python -EXECUTE_PROCESS(COMMAND python -c "import sys; from distutils.sysconfig import get_python_lib; sys.stdout.write(get_python_lib())" +EXECUTE_PROCESS(COMMAND + python -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 "") + MESSAGE(FATAL_ERROR "Python executable not in PATH, aborting") +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" + "${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") + "${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") ENDIF(PYTHONLIBS_FOUND) -ENDIF(SWIG_FOUND) \ No newline at end of file +ENDIF(SWIG_FOUND) diff --git a/win/build-deps.cmd b/win/build-deps.cmd index 5e67f42f3d..dc17888e22 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -282,6 +282,8 @@ IF NOT %ERRORLEVEL%==0 GOTO :Error :: TODO Update to 3.5 when it's released as it will have an option to install debug libraries. set PYTHON_VERSION=3.4.3 IF "%IFCOS_USE_PYTHON2%"=="TRUE" set PYTHON_VERSION=2.7.10 +set PY_VER_MAJOR_MINOR=%PYTHON_VERSION:~0,3% +set PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR:.=% set DEPENDENCY_NAME=Python %PYTHON_VERSION% set DEPENDENCY_DIR=N/A set PYTHON_AMD64_POSTFIX=.amd64 @@ -299,9 +301,9 @@ IF "%IFCOS_INSTALL_PYTHON%"=="TRUE" ( msiexec /x %PYTHON_INSTALLER% /qn ) - IF NOT EXIST "%INSTALL_DIR%\Python". ( + IF NOT EXIST "%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR%". ( cecho {0D}Installing %DEPENDENCY_NAME%. Please be patient, this will take a while.{# #}{\n} - msiexec /qn /i %PYTHON_INSTALLER% TARGETDIR=%INSTALL_DIR%\Python + msiexec /qn /i %PYTHON_INSTALLER% TARGETDIR=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% ) ELSE ( cecho {0D}%DEPENDENCY_NAME% already installed. Skipping.{# #}{\n} ) diff --git a/win/readme.txt b/win/readme.txt index f8779f3d10..0718d1cb5c 100644 --- a/win/readme.txt +++ b/win/readme.txt @@ -28,7 +28,10 @@ After the dependencies are build, execute run-cmake.bat. The batch file expects is provided, the same default value as above is used. This batch script will create a folder of form build-vs- which will contain the solution and project files for Visual Studio. IMPORTANT: If you wish to use any library from a custom location, modify the paths in run-cmake.bat -accordingly. +accordingly. If you used IFCOS_USE_PYTHON2=TRUE when running build-deps.cmd, currently it must also be +set accordingly before running run-cmake.bat, if run-cmake.bat is not run in the same command prompt +session as build-deps.cmd was run. + All of the dependencies are build as static libraries against the static run-time allowing the developer to effortlessly deploy standalone binaries. diff --git a/win/run-cmake.bat b/win/run-cmake.bat index 42ac88b4a9..2e186475d0 100644 --- a/win/run-cmake.bat +++ b/win/run-cmake.bat @@ -27,11 +27,18 @@ setlocal EnableDelayedExpansion call vs-cfg.cmd %1 -set CMAKE_INSTALL_PREFIX=%CD%\..\installed-vs%VS_VER%-%TARGET_ARCH% +pushd .. +set CMAKE_INSTALL_PREFIX=%CD%\installed-vs%VS_VER%-%TARGET_ARCH% +popd set BUILD_DIR=build-vs%VS_VER%-%TARGET_ARCH% IF NOT EXIST ..\%BUILD_DIR%. mkdir ..\%BUILD_DIR% pushd ..\%BUILD_DIR% +:: TODO Duplicate code with build-deps.cmd: have some kind of build cache/config file and read Pyhon version from there. +set PYTHON_VERSION=3.4.3 +IF "%IFCOS_USE_PYTHON2%"=="TRUE" set PYTHON_VERSION=2.7.10 +set PY_VER_MAJOR_MINOR=%PYTHON_VERSION:~0,3% +set PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR:.=% set BOOST_ROOT=%DEPS_DIR%\boost REM set BOOST_INCLUDEDIR=%DEPS_DIR%\boost @@ -42,7 +49,9 @@ set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib set OPENCOLLADA_INCLUDE_DIR=%INSTALL_DIR%\OpenCOLLADA\include\opencollada set OPENCOLLADA_LIBRARY_DIR=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada -set PYTHONPATH=%INSTALL_DIR%\Python +set PYTHON_INCLUDE_DIR=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR%\include +set PYTHON_LIBRARY=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR%\libs\python%PY_VER_MAJOR_MINOR%.lib +set PYTHONPATH=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% set SWIG_DIR=%INSTALL_DIR%\swigwin set PATH=%PATH%;%SWIG_DIR%;%PYTHONPATH% :: TODO 3ds Max SDK? @@ -62,6 +71,8 @@ echo OCC_INCLUDE_DIR = %OCC_INCLUDE_DIR% echo OCC_LIBRARY_DIR = %OCC_LIBRARY_DIR% echo OPENCOLLADA_INCLUDE_DIR = %OPENCOLLADA_INCLUDE_DIR% echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR% +echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR% +echo PYTHON_LIBRARY = %PYTHON_LIBRARY% echo PYTHONPATH = %PYTHONPATH% echo SWIG_DIR = %SWIG_DIR% echo.