Skip to content

Commit

Permalink
PR Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed May 28, 2024
1 parent 7228b6f commit 17a27ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 29 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand All @@ -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)



2 changes: 0 additions & 2 deletions carma_clock_py/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 17a27ed

Please sign in to comment.