From 30259398ae05f43658e45a1f9f1950652d301b50 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 3 Jul 2019 13:24:15 -0700 Subject: [PATCH 01/10] Convert package to a pure CMake package cherry-picking commit 4d5be00 from @cottsay See: https://github.com/wjwwood/serial/pull/209#issuecomment-520018303 Author: Scott K Logan Date: Wed Jul 3 13:24:15 2019 -0700 Conflicts: CMakeLists.txt package.xml tests/CMakeLists.txt Signed-off-by: Alex Moriarty --- CMakeLists.txt | 40 +++++++++++++++------------------------- Makefile | 4 ++-- cmake/serialConfig.cmake | 3 +++ package.xml | 9 ++++++++- tests/CMakeLists.txt | 15 +++++++++++---- 5 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 cmake/serialConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 49270209..230d99fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,11 @@ cmake_minimum_required(VERSION 2.8.3) project(serial) -# Find catkin -find_package(catkin REQUIRED) - if(APPLE) find_library(IOKIT_LIBRARY IOKit) find_library(FOUNDATION_LIBRARY Foundation) endif() -if(UNIX AND NOT APPLE) - # If Linux, add rt and pthread - set(rt_LIBRARIES rt) - set(pthread_LIBRARIES pthread) - catkin_package( - LIBRARIES ${PROJECT_NAME} - INCLUDE_DIRS include - DEPENDS rt pthread - ) -else() - # Otherwise normal call - catkin_package( - LIBRARIES ${PROJECT_NAME} - INCLUDE_DIRS include - ) -endif() - ## Sources set(serial_SRCS src/serial.cc @@ -66,16 +46,26 @@ include_directories(include) ## Install executable install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin ) ## Install headers install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) + DESTINATION include/serial) + +## Install CMake config +install(FILES cmake/serialConfig.cmake + DESTINATION share/serial/cmake) + + +## Install package.xml +install(FILES package.xml + DESTINATION share/serial) ## Tests -if(CATKIN_ENABLE_TESTING) +include(CTest) +if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/Makefile b/Makefile index e1720722..0f49ddc7 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ test: @mkdir -p build cd build && cmake $(CMAKE_FLAGS) .. ifneq ($(MAKE),) - cd build && $(MAKE) run_tests + cd build && $(MAKE) all test else - cd build && make run_tests + cd build && make all test endif diff --git a/cmake/serialConfig.cmake b/cmake/serialConfig.cmake new file mode 100644 index 00000000..e90bdf69 --- /dev/null +++ b/cmake/serialConfig.cmake @@ -0,0 +1,3 @@ +get_filename_component(SERIAL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(SERIAL_INCLUDE_DIRS "${SERIAL_CMAKE_DIR}/../../../include") +find_library(SERIAL_LIBRARIES serial PATHS ${SERIAL_CMAKE_DIR}/../../../lib/serial) diff --git a/package.xml b/package.xml index 959f9b87..a63b88ab 100644 --- a/package.xml +++ b/package.xml @@ -19,6 +19,13 @@ William Woodall John Harrison - catkin + cmake + + + gtest + + + cmake + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ac9a4214..196885a4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,19 @@ if(UNIX) - catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) - target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) + find_package(GTest REQUIRED) + include_directories(${GTEST_INCLUDE_DIRS}) + + add_executable(${PROJECT_NAME}-test unix_serial_tests.cc) + target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${GTEST_LIBRARIES}) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() + add_test("${PROJECT_NAME}-test-gtest" ${PROJECT_NAME}-test) if(NOT APPLE) # these tests are unreliable on macOS - catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) - target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) + add_executable(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) + target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} ${GTEST_LIBRARIES}) + add_test("${PROJECT_NAME}-test-timer-gtest" ${PROJECT_NAME}-test-timer) endif() + # Boost is only required for tests/proof_of_concepts which are not enabled by default + # find_package(Boost REQUIRED) endif() From 380c4e4117e1ead7ab8c1a56144c49569e4b7b73 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Wed, 14 Jun 2023 11:18:01 -0300 Subject: [PATCH 02/10] compile with -fPIC and bump cmake version This couldn't be cherry-picked because but essentially the same change from the ros2 branch here: https://github.com/tylerjw/serial/commit/d8d160678aa0b31cdf467c052b954fa287cc6cdf Fixes this error: ``` /usr/bin/ld: /home/alex/ros/h/robotiq/install/serial/lib/libserial.a(serial.cc.o): relocation R_X86_64_PC32 against symbol `_ZTVN6serial6SerialE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value ``` Signed-off-by: Alex Moriarty --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 230d99fb..a67ed041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 2.8.12) project(serial) if(APPLE) @@ -28,6 +28,9 @@ endif() ## Add serial library add_library(${PROJECT_NAME} ${serial_SRCS}) +set_target_properties(${PROJECT_NAME} PROPERTIES + POSITION_INDEPENDENT_CODE ON) + if(APPLE) target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) elseif(UNIX) From c9da89d34893fbe975153795c158611873ab14fd Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 22 Sep 2020 13:08:46 +0200 Subject: [PATCH 03/10] cmake: Use cmake >= 3.5, add project setup. Cmake made major changes in the 2.x -> 3.0 switch, keeping the 2.x compatiblity just isn't worth it. Since serial anyway doesn't build on versions before xenial, use xenial's cmake at 3.5 as baseline. Cherry-pick from PR #231 Conflicts: CMakeLists.txt Author: Alec Leamas Date: Tue Sep 22 13:08:46 2020 +0200 Gbp-Pq: Name 0001-cmake-Use-cmake-3.5-add-project-setup.patch Signed-off-by: Alex Moriarty --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a67ed041..3e3ceb1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ -cmake_minimum_required(VERSION 2.8.12) -project(serial) +cmake_minimum_required(VERSION 3.5.0) + +# General setup +project(serial + VERSION 1.2.1 + DESCRIPTION "Cross-platform, Serial Port library written in C++" + HOMEPAGE_URL "http://wjwwood.io/serial/" +) if(APPLE) find_library(IOKIT_LIBRARY IOKit) From 61da1e2c994ebf3985521d9b6b431d6171c9983b Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 22 Sep 2020 13:28:04 +0200 Subject: [PATCH 04/10] cmake: Add defined so-version and public header to lib. Adding a so-version means defining an ABI level. This level is decoupled from the ordinary version, even a major version change doesn't necessarily mean that the so-version should change (and thus have all dependencies to be rebuilt). Adding the public header to clarify the setup. Note: cherry-pick from PR #231 Conflicts: CMakeLists.txt Author: Alec Leamas Date: Tue Sep 22 13:28:04 2020 +0200 Gbp-Pq: Name 0002-cmake-Add-defined-so-version-and-public-header-to-li.patch Signed-off-by: Alex Moriarty --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e3ceb1b..b2054231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.5.0) # General setup +set(PROJ_SOVERSION 1) project(serial VERSION 1.2.1 DESCRIPTION "Cross-platform, Serial Port library written in C++" @@ -33,9 +34,18 @@ else() endif() ## Add serial library +set(serial_HEADERS + include/serial/serial.h + include/serial/v8stdint.h +) +# Build, link and install main library add_library(${PROJECT_NAME} ${serial_SRCS}) set_target_properties(${PROJECT_NAME} PROPERTIES - POSITION_INDEPENDENT_CODE ON) + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJ_SOVERSION} + PUBLIC_HEADER "${serial_HEADERS}" +) +target_include_directories(${PROJECT_NAME} PUBLIC include) if(APPLE) target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) @@ -58,6 +68,7 @@ install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include/${PROJECT_NAME} ) ## Install headers From 40d295030e910a1a1eb3bf668640322096a8e640 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Thu, 15 Jun 2023 10:32:21 -0300 Subject: [PATCH 05/10] cmake: option BUILD_SHARED_LIBS ON Default to building as a shared libary Signed-off-by: Alex Moriarty --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2054231..28e4c193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.5.0) # General setup +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) + set(PROJ_SOVERSION 1) project(serial VERSION 1.2.1 From 48f14ce4576f35d8ee89c1164576657bda686ee9 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Thu, 15 Jun 2023 11:47:17 -0300 Subject: [PATCH 06/10] cmake: CMAKE_POSITION_INDEPENDENT_CODE - remove set BUILD_SHARED_LIBS ON - set CMAKE_POSITION_INDEPENDENT_CODE ON if undefined When setting BUILD_SHARED_LIBS if user set it to off linking would fail. Adding the suggetion from pull request review, which seems to work in both cases colcon build --cmake-args "-DBUILD_SHARED_LIBS=ON" colcon build --cmake-args "-DBUILD_SHARED_LIBS=OFF" Signed-off-by: Alex Moriarty --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28e4c193..75a05bb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.5.0) # General setup -option(BUILD_SHARED_LIBS "Build using shared libraries" ON) - set(PROJ_SOVERSION 1) project(serial VERSION 1.2.1 @@ -41,12 +39,16 @@ set(serial_HEADERS include/serial/v8stdint.h ) # Build, link and install main library +if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() add_library(${PROJECT_NAME} ${serial_SRCS}) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJ_SOVERSION} PUBLIC_HEADER "${serial_HEADERS}" ) + target_include_directories(${PROJECT_NAME} PUBLIC include) if(APPLE) From 7b7f62b606db7d661f46a3fe251134c8cd393a11 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 16 Jun 2023 20:14:00 -0300 Subject: [PATCH 07/10] cmake minimum 3.16 Bump cmake to oldest version currently used by tier 1 or 2 supported ROS platform. https://www.ros.org/reps/rep-2000.html#humble-hawksbill-may-2022-may-2027 https://www.ros.org/reps/rep-0003.html#noetic-ninjemys-may-2020-may-2025 Signed-off-by: Alex Moriarty --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75a05bb7..b2a5a3d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.16) # General setup set(PROJ_SOVERSION 1) From 2a76e1a34b7da5b2a7c280a77312bc7e84f09dce Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 16 Jun 2023 20:39:22 -0300 Subject: [PATCH 08/10] remove PROJ_SOVERSION variable this is only used once and it makes it easier to read or grep for Signed-off-by: Alex Moriarty --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2a5a3d9..cd68d013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.16) # General setup -set(PROJ_SOVERSION 1) project(serial VERSION 1.2.1 DESCRIPTION "Cross-platform, Serial Port library written in C++" @@ -45,7 +44,7 @@ endif() add_library(${PROJECT_NAME} ${serial_SRCS}) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} - SOVERSION ${PROJ_SOVERSION} + SOVERSION 1 PUBLIC_HEADER "${serial_HEADERS}" ) From 2528dcf50cab936868e59c55d825bba2b2b61582 Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 16 Jun 2023 20:44:37 -0300 Subject: [PATCH 09/10] set project language to CXX Co-authored-by: Chris Thrasher --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd68d013..c6c7dbbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16) # General setup project(serial VERSION 1.2.1 + LANGUAGES CXX DESCRIPTION "Cross-platform, Serial Port library written in C++" HOMEPAGE_URL "http://wjwwood.io/serial/" ) From f60d49d91b0b58a2427a082e3e9ef08db8d8398d Mon Sep 17 00:00:00 2001 From: Alex Moriarty Date: Fri, 16 Jun 2023 21:04:51 -0300 Subject: [PATCH 10/10] Depend on GTest via its imported targets - Find and use GTest as imported target GTest::GTest - Note: - GTest::GTest is available from CMake 3.5 and depricated in 3.20 but still available in latest version. - GTest::gtest added in CMake 3.20 Signed-off-by: Alex Moriarty --- tests/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 196885a4..db3f7de0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,8 @@ if(UNIX) find_package(GTest REQUIRED) - include_directories(${GTEST_INCLUDE_DIRS}) add_executable(${PROJECT_NAME}-test unix_serial_tests.cc) - target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${GTEST_LIBRARIES}) + target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} GTest::GTest) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() @@ -11,7 +10,7 @@ if(UNIX) if(NOT APPLE) # these tests are unreliable on macOS add_executable(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) - target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} ${GTEST_LIBRARIES}) + target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} GTest::GTest) add_test("${PROJECT_NAME}-test-timer-gtest" ${PROJECT_NAME}-test-timer) endif() # Boost is only required for tests/proof_of_concepts which are not enabled by default