From d2cbe446461db193fe34eed994d927c26a56296f Mon Sep 17 00:00:00 2001 From: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> Date: Wed, 17 Jun 2026 16:21:17 -0600 Subject: [PATCH] Support local install with example Signed-off-by: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> --- CMakeLists.txt | 11 ++++++++++- README.md | 11 +++++++++++ examples/cpp/CMakeLists.txt | 4 +++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d4d27..e21d94e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,15 @@ install(TARGETS PiPCA9685_cpp INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +# Strip the install prefix if Python_SITEARCH is underneath it +cmake_path( + RELATIVE_PATH Python_SITEARCH + BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}" + OUTPUT_VARIABLE PYTHON_INSTALL_DIR +) + install(TARGETS PiPCA9685_python - DESTINATION ${Python_SITEARCH} + LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}" ) install(EXPORT PiPCA9685_export @@ -74,3 +81,5 @@ if(NOT TARGET uninstall) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() + +add_subdirectory(examples/cpp) diff --git a/README.md b/README.md index cd1412f..f20cbf6 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,14 @@ To run the Python example, run the following command in the `examples/python/` d ```bash python3 example.py ``` + +## Development + +If you want to work on a local copy without root access: +```bash +cmake -B build +cmake --build build +cmake --install build --prefix install +``` + +With this workflow, the example will be built in `./build/examples/cpp/example-cpp`. diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index e6eea03..430ad72 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -3,7 +3,9 @@ project(example) set(CMAKE_CXX_STANDARD 23) -find_package(PiPCA9685 REQUIRED) +if(NOT TARGET PiPCA9685::PiPCA9685) + find_package(PiPCA9685 REQUIRED) +endif() add_executable(example-cpp main.cpp) target_link_libraries(example-cpp PiPCA9685::PiPCA9685)