From 8fffd2e06b65c9de769c7d0ef092b308538871fa Mon Sep 17 00:00:00 2001 From: Jean-Nicolas Brunet Date: Sat, 16 Jan 2021 14:54:16 +0100 Subject: [PATCH 1/3] [cmake] Fix compilation issue on MacOS --- CMake/SofaPython3Tools.cmake | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CMake/SofaPython3Tools.cmake b/CMake/SofaPython3Tools.cmake index 2cd7109e..22cf3d36 100644 --- a/CMake/SofaPython3Tools.cmake +++ b/CMake/SofaPython3Tools.cmake @@ -122,14 +122,37 @@ function(SP3_add_python_module) find_package(pybind11 CONFIG QUIET REQUIRED) - pybind11_add_module(${A_TARGET} SHARED NO_EXTRAS "${A_SOURCES}") + # We are doing manually what's usually done with pybind11_add_module(${A_TARGET} SHARED "${A_SOURCES}") + # since we got some problems on MacOS using recent versions of pybind11 where the SHARED argument wasn't taken + # into account + python_add_library(${A_TARGET} SHARED "${A_SOURCES}") add_library(SofaPython3::${A_TARGET} ALIAS ${A_TARGET}) + target_link_libraries(${A_TARGET} PRIVATE pybind11::headers) + target_link_libraries(${A_TARGET} PRIVATE pybind11::embed) + target_link_libraries(${A_TARGET} PRIVATE pybind11::lto) + + if(MSVC) + target_link_libraries(${A_TARGET} PRIVATE pybind11::windows_extras) + endif() + + set_target_properties(${A_TARGET} + PROPERTIES + CXX_VISIBILITY_PRESET "hidden" + CUDA_VISIBILITY_PRESET "hidden") + target_include_directories(${A_TARGET} PUBLIC "$" PUBLIC $ ) + pybind11_extension(${A_TARGET}) + + if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) + # Strip unnecessary sections of the binary on Linux/macOS + pybind11_strip(${A_TARGET}) + endif() + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang or AppleCLang target_compile_options(${A_TARGET} PUBLIC -fsized-deallocation) endif() From 4417501d388c21397a1169951bae3f384df30e91 Mon Sep 17 00:00:00 2001 From: Jean-Nicolas Brunet Date: Sat, 16 Jan 2021 15:04:27 +0100 Subject: [PATCH 2/3] [cmake] Fix compilation issue on MacOS --- CMake/SofaPython3Tools.cmake | 39 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/CMake/SofaPython3Tools.cmake b/CMake/SofaPython3Tools.cmake index 22cf3d36..54d7a171 100644 --- a/CMake/SofaPython3Tools.cmake +++ b/CMake/SofaPython3Tools.cmake @@ -128,12 +128,36 @@ function(SP3_add_python_module) python_add_library(${A_TARGET} SHARED "${A_SOURCES}") add_library(SofaPython3::${A_TARGET} ALIAS ${A_TARGET}) - target_link_libraries(${A_TARGET} PRIVATE pybind11::headers) - target_link_libraries(${A_TARGET} PRIVATE pybind11::embed) - target_link_libraries(${A_TARGET} PRIVATE pybind11::lto) + if ("${pybind11_VERSION}" VERSION_GREATER_EQUAL "2.6.0") + target_link_libraries(${A_TARGET} PRIVATE pybind11::headers) + target_link_libraries(${A_TARGET} PRIVATE pybind11::embed) + target_link_libraries(${A_TARGET} PRIVATE pybind11::lto) + if(MSVC) + target_link_libraries(${A_TARGET} PRIVATE pybind11::windows_extras) + endif() + + pybind11_extension(${A_TARGET}) + pybind11_strip(${A_TARGET}) + else() + target_link_libraries(${A_TARGET} PRIVATE pybind11::module) + + # Equivalent to pybind11_extension(${A_TARGET}) which doesn't exists on pybind11 versions < 5 + set_target_properties(${A_TARGET} PROPERTIES PREFIX "" SUFFIX "${PYTHON_MODULE_EXTENSION}") - if(MSVC) - target_link_libraries(${A_TARGET} PRIVATE pybind11::windows_extras) + if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) + # Equivalent to pybind11_strip(${A_TARGET}) which doesn't exists on pybind11 versions < 5 + # Strip unnecessary sections of the binary on Linux/macOS + if(CMAKE_STRIP) + if(APPLE) + set(x_opt -x) + endif() + + add_custom_command( + TARGET ${A_TARGET} + POST_BUILD + COMMAND ${CMAKE_STRIP} ${x_opt} $) + endif() + endif() endif() set_target_properties(${A_TARGET} @@ -146,12 +170,7 @@ function(SP3_add_python_module) PUBLIC $ ) - pybind11_extension(${A_TARGET}) - if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) - # Strip unnecessary sections of the binary on Linux/macOS - pybind11_strip(${A_TARGET}) - endif() if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang or AppleCLang target_compile_options(${A_TARGET} PUBLIC -fsized-deallocation) From 5b819db6097f958d86fe9f75da27a92fbaf6a995 Mon Sep 17 00:00:00 2001 From: Jean-Nicolas Brunet Date: Sat, 16 Jan 2021 21:19:28 +0100 Subject: [PATCH 3/3] [workflow] Fix python detection --- .github/workflows/macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 4574ae63..b608b482 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -70,6 +70,7 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake -DCMAKE_BUILD_TYPE=Release + -DPYTHON_EXECUTABLE=$(which python) . && ninja && ninja install && echo ${CCACHE_BASEDIR}