diff --git a/CMakeLists.txt b/CMakeLists.txt index c60b776..e36b72c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,10 @@ project(carma_clock LANGUAGES CXX ) +option(BUILD_PYTHON_BINDINGS + "BUILD PYTHON BINDINGS is used to configure whether or not to including building python module bindings into the cmake build process. + **NOTE** Build python bindings is currently only support for native builds (not supported for cross-compile builds) " ON) + include(cmake/dependencies.cmake) add_library(${PROJECT_NAME} SHARED ) @@ -25,32 +29,45 @@ set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1 ) -if (DEFINED ENV{BUILD_ARCHITECTURE}) - message(STATUS "Building Python Module binding NOT supported for crosss compiling " $ENV{BUILD_ARCHITECTURE} " builds...") -else() +include(CommonSource) +include(Testing) +include(CodeCoverage) +include(InstallingGeneral) +include(InstallingConfigs) + +# Build customization for BUILD_PYTHON_BINDINGS option +if (${BUILD_PYTHON_BINDINGS}) + # BUILD_ARCHIECTURE is an environment variable set in carma-builds base image for cross-compile targets. It is unset + # for native builds. Since python module binding does not work for cross-compiled targets, if build architecture is + # set, we must turn off build python bindings. (carma-builds repo https://github.com/usdot-fhwa-stol/carma-builds) + #TODO Move this check from CMAKE file to build.sh file to remove coupling of CMake file to carma-builds base image + if (DEFINED ENV{BUILD_ARCHITECTURE}) + set(BUILD_PYTHON_BINDINGS OFF) + message(WARNING "BUILD_PYTHON_BINDINGS option NOT supported for cross compiled targets (" $ENV{BUILD_ARCHITECTURE} ") ...") + endif() +endif() +if (${BUILD_PYTHON_BINDINGS}) + message(VERBOSE "Adding dependencies and tests for building python module bindings (set BUILD_PYTHON_BINDINGS=OFF to prevent python module binding build) ...") include(carma_clock_py/cmake/dependencies.cmake) target_link_libraries( ${PROJECT_NAME} PUBLIC Python3::Python pybind11::module ) - message(STATUS "Building Python Module binding only supported for native x64 builds...") # set up sources based on target name target_sources (${PROJECT_NAME} PRIVATE carma_clock_py/src/carma_clock_py.cpp ) + # set up test for python module binding FILE(COPY carma_clock_py/python_wrapper_test.py DESTINATION .) add_test(NAME test_carma_clock_python_module_binding COMMAND ${PYTHON_EXECUTABLE} python_wrapper_test.py ) + # set cpack depedencies + set(CPACK_DEBIAN_PACKAGE_DEPENDS carma-clock-1 python3-dev) + # remove debug post fix for library. Required due to import naming for python module import + set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "") endif() -include(CommonSource) -include(Testing) -include(CodeCoverage) -include(InstallingGeneral) -include(InstallingConfigs) -set(CPACK_DEBIAN_PACKAGE_DEPENDS carma-clock-1 python3-dev) -set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "") - include(Packing) + diff --git a/carma_clock_py/cmake/dependencies.cmake b/carma_clock_py/cmake/dependencies.cmake index 4e9b0b3..7d3ad40 100755 --- a/carma_clock_py/cmake/dependencies.cmake +++ b/carma_clock_py/cmake/dependencies.cmake @@ -1,8 +1,6 @@ find_package(Python3 REQUIRED COMPONENTS Interpreter Development) include(GetCPM) set(CPM_USE_LOCAL_PACKAGES ON) -set(PYBIND11_INSTALL ON) -set(PYBIND11_TEST OFF) CPMAddPackage( NAME pybind11 GITHUB_REPOSITORY pybind/pybind11