From d8a56d341286d271e0d8fc4dbfb415378e5869ae Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Tue, 1 Apr 2025 00:27:41 -0500 Subject: [PATCH 1/8] Initial cmake config work --- CMakeLists.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a09bdf..e5e463c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,5 +103,23 @@ install(TARGETS ${arduino_test_target} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +export(TARGETS ${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + ) + +install(EXPORT + ${PROJECT_NAME}Config + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake" + NAMESPACE ${PROJECT_NAME}:: + ) + +message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") include(cpack.cmake) \ No newline at end of file From a982f2c3302bb1307e5067d4944508059aa90977 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Thu, 10 Apr 2025 19:10:40 -0500 Subject: [PATCH 2/8] Work on switching to more modern config generation --- CMakeLists.txt | 39 ++++++++++++++++++++++----------------- cpack.cmake | 4 +--- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5e463c..5fc98b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,9 @@ project(openFrameworksArduino) # ********** Setup CMake ********** # Default to C++17 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -endif() +if (NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif () if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # enables building a static library but later link it into a dynamic library @@ -103,23 +103,28 @@ install(TARGETS ${arduino_test_target} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}Config - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) +# Parse version number from file +file(READ "version" version_input) +string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${version_input}) -export(TARGETS ${PROJECT_NAME} +install(EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake NAMESPACE ${PROJECT_NAME}:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + DESTINATION lib/cmake/${PROJECT_NAME} ) -install(EXPORT - ${PROJECT_NAME}Config - DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake" - NAMESPACE ${PROJECT_NAME}:: +include(CMakePackageConfigHelpers) +write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${version_input} + COMPATIBILITY AnyNewerVersion ) -message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") -include(cpack.cmake) \ No newline at end of file +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION . + ) + +message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") +include(cpack.cmake) + diff --git a/cpack.cmake b/cpack.cmake index cad76bd..55bf1c9 100644 --- a/cpack.cmake +++ b/cpack.cmake @@ -1,8 +1,6 @@ set(MAINTAINER_NAME "David Cofer ") -# Parse version number from file -file(READ "version" version_input) -string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${version_input}) + set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2}) From 04811e4a0dfed02c7a918b3edd80a531bc6a58d7 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Thu, 10 Apr 2025 21:55:42 -0500 Subject: [PATCH 3/8] Simplified CMakeLists to one based on https://blog.vito.nyc/posts/cmake-pkg/ --- CMakeLists.txt | 127 ++++++++++++++++++++++-------------------------- config.in.cmake | 4 ++ 2 files changed, 62 insertions(+), 69 deletions(-) create mode 100644 config.in.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fc98b4..66a5809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,17 +8,17 @@ if (NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif () -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # enables building a static library but later link it into a dynamic library - add_compile_options(-fPIC) -endif() -if(NOT WIN32) - # About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of - # implicit sign conversions in gtest.cc, see https://ci.ros2.org/job/ci_osx/9381/clang/. - # Hence disabling -Wsign-conversion for now until all those have eventually been fixed. - # (from https://github.com/ros2/rcutils/pull/263#issuecomment-663252537) - add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic) -endif() +if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # enables building a static library but later link it into a dynamic library + add_compile_options(-fPIC) +endif () +if (NOT WIN32) + # About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of + # implicit sign conversions in gtest.cc, see https://ci.ros2.org/job/ci_osx/9381/clang/. + # Hence disabling -Wsign-conversion for now until all those have eventually been fixed. + # (from https://github.com/ros2/rcutils/pull/263#issuecomment-663252537) + add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic) +endif () # Setup Boost find_package(Boost REQUIRED COMPONENTS thread) @@ -26,105 +26,94 @@ include_directories(${Boost_INCLUDE_DIRS}) # ********** Setup openFrameworksArduino library ********** -set(openFrameworksArduino_sources +set(lib_target ${PROJECT_NAME}) + +add_library(${lib_target}) + +target_sources(${lib_target} PRIVATE # These files will only be available during building src/ofArduino.cpp src/ofSerial.cpp src/ofSerialLinux.cpp src/ofSerialWin.cpp ) -set_source_files_properties( - ${openFrameworksArduino_sources} - PROPERTIES language "CXX") -add_library( - ${PROJECT_NAME} - ${openFrameworksArduino_sources}) -target_include_directories(${PROJECT_NAME} PUBLIC - "$" - "$" - "$") - - -target_link_libraries(${PROJECT_NAME} - ${Boost_LIBRARIES} - ) -set(public_headers +# Locate headers +# Using FILE_SET would be much cleaner, but needs CMake 3.23+ and ROS Humble ships with 3.22 +set(public_headers # These files will be installed with the library src/ofArduino.h src/ofConstants.h src/ofSerial.h src/ofSerialLinux.h src/ofSerialWin.h src/ofTypes.h + src/StdAfx.h ) +set_property(TARGET ${lib_target} PROPERTY PUBLIC_HEADER ${public_headers}) +target_include_directories(${lib_target} PUBLIC # Everything in this folder will be available during building + "$" + "$" + "$") -set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) -set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${public_headers}") +target_link_libraries(${lib_target} + ${Boost_LIBRARIES} + ) # ********** Setup ArduinoTest executable ********** set(arduino_test_target ArduinoTest) -set(arduino_test_sources + +add_executable(${arduino_test_target}) + +target_sources(${arduino_test_target} PRIVATE examples/ArduinoTest.cpp examples/HexapodTimingTest.cpp examples/PlaybackMovements.cpp examples/Test.cpp ) -set_source_files_properties( - ${arduino_test_sources} - PROPERTIES language "CXX") -add_executable( - ${arduino_test_target} - ${arduino_test_sources}) -target_include_directories(${arduino_test_target} PUBLIC - "$" - "$" - "$") target_link_libraries(${arduino_test_target} - ${PROJECT_NAME} + ${lib_target} ) -set_target_properties(${arduino_test_target} PROPERTIES LINKER_LANGUAGE CXX) - # ********** Setup packaging ********** include(GNUInstallDirs) -install(TARGETS ${PROJECT_NAME} - EXPORT "${PROJECT_NAME}Targets" - COMPONENT ${PROJECT_NAME} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) - -install(TARGETS ${arduino_test_target} - EXPORT "${arduino_test_target}Targets" - COMPONENT ${arduino_test_target} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) +include(CMakePackageConfigHelpers) -# Parse version number from file +# Parse version number from the file file(READ "version" version_input) string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${version_input}) -install(EXPORT ${PROJECT_NAME}Targets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION lib/cmake/${PROJECT_NAME} - ) +# Fill in cmake variables in config template +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/config.in.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + @ONLY +) -include(CMakePackageConfigHelpers) -write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${version_input} COMPATIBILITY AnyNewerVersion - ) +) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION . + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} ) +install( + TARGETS ${lib_target} ${arduino_test_target} # These targets will be packaged + EXPORT ${PROJECT_NAME}Targets +) + +install( + EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} +) + message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") include(cpack.cmake) diff --git a/config.in.cmake b/config.in.cmake new file mode 100644 index 0000000..ba038e4 --- /dev/null +++ b/config.in.cmake @@ -0,0 +1,4 @@ +# Copy any dependencies here +find_dependency(Boost REQUIRED COMPONENTS thread) + +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake) \ No newline at end of file From 34d0f20bcc62863866f043b2d0021783f6e74ca3 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Thu, 10 Apr 2025 22:01:32 -0500 Subject: [PATCH 4/8] Fixed headers not being put in a subfolder of include --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66a5809..1ec5eb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ install(FILES install( TARGETS ${lib_target} ${arduino_test_target} # These targets will be packaged EXPORT ${PROJECT_NAME}Targets + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ) install( From 183016c8701d7a55b38fd17394d8de7db043b930 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Thu, 10 Apr 2025 22:08:46 -0500 Subject: [PATCH 5/8] Fixed include namespace pollution. Now only adding "/opt/openFrameworksArduino/include/" to the include directory instead of "/opt/openFrameworksArduino/include/openFrameworksArduino". This means you need to "#include " instead of just "#include " --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ec5eb2..bc66cfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ set_property(TARGET ${lib_target} PROPERTY PUBLIC_HEADER ${public_headers}) target_include_directories(${lib_target} PUBLIC # Everything in this folder will be available during building "$" "$" - "$") + "$") target_link_libraries(${lib_target} ${Boost_LIBRARIES} From cc7d62ab962fa77662c768bafc18fbca66a35b38 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Thu, 10 Apr 2025 22:21:29 -0500 Subject: [PATCH 6/8] Changed Boost link visibility in case this ever becomes a shared lib --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc66cfd..4c0dc54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ target_include_directories(${lib_target} PUBLIC # Everything in this folder will "$" "$") -target_link_libraries(${lib_target} +target_link_libraries(${lib_target} PRIVATE ${Boost_LIBRARIES} ) From 9f3cf63175f8f3690b7465c2332dcdd4511b928e Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Fri, 11 Apr 2025 22:46:30 -0500 Subject: [PATCH 7/8] Switched to explicit Boost library linking. This was causing problems when doing it this way for Boost::log in umrt-arm-firmware-lib, so propagating best practices --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c0dc54..7033e68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ target_include_directories(${lib_target} PUBLIC # Everything in this folder will "$") target_link_libraries(${lib_target} PRIVATE - ${Boost_LIBRARIES} + Boost::thread ) # ********** Setup ArduinoTest executable ********** From 2961dc4396be2c586e2574393a3b23fcd1012a63 Mon Sep 17 00:00:00 2001 From: Noah Reeder Date: Fri, 11 Apr 2025 22:55:49 -0500 Subject: [PATCH 8/8] Version bump --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 7bcd0e3..6812f81 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.2 \ No newline at end of file +0.0.3 \ No newline at end of file