diff --git a/api/swig/python/CMakeLists.txt b/api/swig/python/CMakeLists.txt index d460c8c378..ee67515655 100644 --- a/api/swig/python/CMakeLists.txt +++ b/api/swig/python/CMakeLists.txt @@ -4,15 +4,15 @@ cmake_policy(SET CMP0078 NEW) cmake_policy(SET CMP0086 NEW) # Handle where to install the resulting Python package -#if (CALL_FROM_SETUP_PY) -# # The CMakeExtension will set CMAKE_INSTALL_PREFIX to the root -# # of the resulting wheel archive -# set(S2GEOMETRY_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) -#else() -# # The Python package is installed directly in the folder of the -# # detected interpreter (system, user, or virtualenv) -# set(S2GEOMETRY_INSTALL_PREFIX ${Python3_SITELIB}) -#endif() +if (CALL_FROM_SETUP_PY) + # The CMakeExtension will set CMAKE_INSTALL_PREFIX to the root + # of the resulting wheel archive + set(BAGPY_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) +else() + # The Python package is installed directly in the folder of the + # detected interpreter (system, user, or virtualenv) + set(BAGPY_INSTALL_PREFIX ${Python3_SITELIB}) +endif() if(Python_LOOKUP_VERSION) set(Python_FIND_STRATEGY VERSION) @@ -56,38 +56,25 @@ target_link_libraries(bagPy baglib ) -#if(${CMAKE_SYSTEM_NAME} MATCHES Darwin) -# if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL MinSizeRel) -# set(BAGPY_LIB _bagPy.so) -# else() -# set(BAGPY_LIB _bagPyd.so) -# endif() -# # Somehow CPython on macOS looks for native code to end in .so instead of .dylib so copy the -# # compiled extension to a file ending in .so... -# add_custom_command(TARGET bagPy POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy_if_different $ "${BAGPY_LIB}") -#elseif(${CMAKE_SYSTEM_NAME} MATCHES Linux) -# if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL MinSizeRel) -# set(BAGPY_LIB _bagPy.so) -# else() -# set(BAGPY_LIB _bagPyd.so) -# endif() -#elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows) -# # TODO: Adjust this for debug builds on Windows as above -# set(BAGPY_LIB _bagPy.pyd) -#endif() - -# Files to install with Python -#set(PYTHON_INSTALL_FILES -# ${CMAKE_CURRENT_BINARY_DIR}/${BAGPY_MODULE_NAME} -# ${CMAKE_CURRENT_BINARY_DIR}/${BAGPY_LIB}) +if(${CMAKE_SYSTEM_NAME} MATCHES Darwin) + set(BAGPY_LIB _bagPy.so) + # Somehow CPython on macOS looks for native code to end in .so instead of .dylib so copy the + # compiled extension to a file ending in .so... + add_custom_command(TARGET bagPy POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ "${BAGPY_LIB}") +elseif(${CMAKE_SYSTEM_NAME} MATCHES Linux) + set(BAGPY_LIB _bagPy.so) +elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows) + set(BAGPY_LIB _bagPy.pyd) +endif() -# Configure setup.py and copy to output directory -#set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in) -#set(SETUP_PY_OUT ${CMAKE_CURRENT_BINARY_DIR}/setup.py) -#configure_file(${SETUP_PY_IN} ${SETUP_PY_OUT}) +# Install the wrapper. +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BAGPY_LIB} DESTINATION ${BAGPY_INSTALL_PREFIX}) -# Install target to call setup.py -#add_custom_target(install-python -# DEPENDS _bagPy -# COMMAND python ${SETUP_PY_OUT} install) +# Install swig-generated Python file (we rename it to __init__.py as it will +# ultimately end up in a directory called bagPy in site-packages, which will +# serve as the module directory. +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/bagPy.py" + DESTINATION ${BAGPY_INSTALL_PREFIX} + RENAME __init__.py + COMPONENT bagPy) diff --git a/api/swig/python/setup.cfg.in b/api/swig/python/setup.cfg.in index 8fa4758eeb..baacc1b7d0 100644 --- a/api/swig/python/setup.cfg.in +++ b/api/swig/python/setup.cfg.in @@ -20,4 +20,4 @@ python_requres = >=3.8 [options.packages.find] where = - ${CMAKE_SOURCE_DIR}/api + ${CMAKE_SOURCE_DIR}/api/python diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 5d1486b245..7e76508dcc 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -6,7 +6,7 @@ #### Build C++ library, tests, and example binaries: ```shell -cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -B build -S . -DCMAKE_INSTALL_PREFIX=/usr/local \ +cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -B build -S . \ -DBAG_BUILD_TESTS:BOOL=ON -DBAG_CODE_COVERAGE:BOOL=ON \ -DBAG_BUILD_PYTHON:BOOL=OFF -DBAG_BUILD_EXAMPLES:BOOL=ON cmake --build build -j 8 @@ -39,7 +39,7 @@ $ python -m pip wheel -w dist/ . Then you can install the wheel with: ```shell -$ python -m pip +$ python -m pip install dist/bagPy-*.whl ``` ## Windows: Visual Studio 2022/2019