From 690990ccb0dbc092171445264bec4f0f0cdc4009 Mon Sep 17 00:00:00 2001 From: blabbe Date: Tue, 3 Dec 2019 11:53:40 +0100 Subject: [PATCH 1/7] feat: Catkin dependancy is now optional --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad1..6ea36e6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,35 @@ cmake_minimum_required(VERSION 2.8.3) project(serial) +## Options +# Use Catkin (disabled by default) +option(USE_CATKIN off) # Find catkin -find_package(catkin REQUIRED) +if(USE_CATKIN) + find_package(catkin REQUIRED) -if(APPLE) - find_library(IOKIT_LIBRARY IOKit) - find_library(FOUNDATION_LIBRARY Foundation) -endif() - -if(UNIX AND NOT APPLE) + 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 - ) + else() + # Otherwise normal call + catkin_package( + LIBRARIES ${PROJECT_NAME} + INCLUDE_DIRS include + ) + endif() endif() + + +if(APPLE) + find_library(IOKIT_LIBRARY IOKit) + find_library(FOUNDATION_LIBRARY Foundation) +endif() ## Sources set(serial_SRCS src/serial.cc @@ -64,15 +68,20 @@ target_link_libraries(serial_example ${PROJECT_NAME}) ## Include headers include_directories(include) -## Install executable -install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -) +if(USE_CATKIN) + ## Install headers + install(FILES include/serial/serial.h include/serial/v8stdint.h + DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) + ## Install executable + install(TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + ) ## Install headers install(FILES include/serial/serial.h include/serial/v8stdint.h DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) +endif() ## Tests if(CATKIN_ENABLE_TESTING) From 61a914cd88f2ba70298bf37c4bac113b17725b30 Mon Sep 17 00:00:00 2001 From: blabbe Date: Tue, 3 Dec 2019 13:14:28 +0100 Subject: [PATCH 2/7] cmake: Add option to build sample --- CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea36e6c..9b8944c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ project(serial) ## Options # Use Catkin (disabled by default) option(USE_CATKIN off) +# Build serial sample +option(BUILD_SAMPLE on) # Find catkin if(USE_CATKIN) @@ -60,10 +62,15 @@ else() target_link_libraries(${PROJECT_NAME} setupapi) endif() -## Uncomment for example -add_executable(serial_example examples/serial_example.cc) -add_dependencies(serial_example ${PROJECT_NAME}) -target_link_libraries(serial_example ${PROJECT_NAME}) +## Include headers + + +## Example +if(BUILD_SAMPLE) + add_executable(serial_example examples/serial_example.cc) + add_dependencies(serial_example ${PROJECT_NAME}) + target_link_libraries(serial_example ${PROJECT_NAME}) +endif() ## Include headers include_directories(include) From e3516cd431d1a1a038e636746583e002d5c4973f Mon Sep 17 00:00:00 2001 From: blabbe Date: Tue, 3 Dec 2019 13:16:55 +0100 Subject: [PATCH 3/7] feat: CMake library export This commit allow the user to export the library that is compatible witha find_package() call. --- CMakeLists.txt | 85 +++++++++++++++++++++++++++++++------ cmake/serialConfig.cmake.in | 6 +++ 2 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 cmake/serialConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b8944c7..2290b1b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,20 @@ cmake_minimum_required(VERSION 2.8.3) -project(serial) + +# Either this or bump cmake_minimum_required to 3.0+ +# Allow us to use Version in project() call : https://cmake.org/cmake/help/v3.0/policy/CMP0048.html#policy:CMP0048 +cmake_policy(SET CMP0048 NEW) + +project(serial VERSION 1.2.1) + + ## Options + # Use Catkin (disabled by default) option(USE_CATKIN off) # Build serial sample option(BUILD_SAMPLE on) + # Find catkin if(USE_CATKIN) find_package(catkin REQUIRED) @@ -32,16 +41,20 @@ if(APPLE) find_library(IOKIT_LIBRARY IOKit) find_library(FOUNDATION_LIBRARY Foundation) endif() + + + ## Sources set(serial_SRCS src/serial.cc include/serial/serial.h include/serial/v8stdint.h ) + if(APPLE) - # If OSX - list(APPEND serial_SRCS src/impl/unix.cc) - list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc) + # If OSX + list(APPEND serial_SRCS src/impl/unix.cc) + list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc) elseif(UNIX) # If unix list(APPEND serial_SRCS src/impl/unix.cc) @@ -53,16 +66,18 @@ else() endif() ## Add serial library -add_library(${PROJECT_NAME} ${serial_SRCS}) +add_library(${PROJECT_NAME} STATIC ${serial_SRCS}) + if(APPLE) - target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) + target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) elseif(UNIX) - target_link_libraries(${PROJECT_NAME} rt pthread) + target_link_libraries(${PROJECT_NAME} rt pthread) else() - target_link_libraries(${PROJECT_NAME} setupapi) + target_link_libraries(${PROJECT_NAME} setupapi) endif() ## Include headers +target_include_directories(${PROJECT_NAME} PUBLIC $) ## Example @@ -72,8 +87,16 @@ if(BUILD_SAMPLE) target_link_libraries(serial_example ${PROJECT_NAME}) endif() -## Include headers -include_directories(include) + +## Export + +# Set postfix names for exporting +set_target_properties(${PROJECT_NAME} PROPERTIES + RELEASE_POSTFIX "" + RELWITHDEBINFO_POSTFIX "-rd" + MINSIZEREL_POSTFIX "-mr" + DEBUG_POSTFIX "-d") + if(USE_CATKIN) ## Install headers @@ -84,13 +107,47 @@ if(USE_CATKIN) ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} ) +else() + set(EXPORT_TARGET_NAME serialTargets) + + install(EXPORT ${EXPORT_TARGET_NAME} DESTINATION cmake/) + # Include module with fuction 'write_basic_package_version_file' and 'configure_package_config_file' + include(CMakePackageConfigHelpers) + + set(OUTPUT_CMAKE_EXPORT_GENERATED_FILES ${CMAKE_BINARY_DIR}/CMakeExportConfig) + # Configure 'ConfigVersion.cmake' + write_basic_package_version_file(${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/${PROJECT_NAME}Config-version.cmake + # + # Careful : SameMinorVersion and ExactVersion were introduced in CMake 3.11 + COMPATIBILITY SameMajorVersion + ) + + # Configure 'Config.cmake' + configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" + ) + + # Install config file generated + install(DIRECTORY ${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/ + DESTINATION cmake/) + -## Install headers -install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) + ## Install headers + install(FILES include/serial/serial.h include/serial/v8stdint.h + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/serial) + + ## Install executable + install(TARGETS ${PROJECT_NAME} EXPORT ${EXPORT_TARGET_NAME} + INCLUDES DESTINATION $ + ARCHIVE DESTINATION ${__dest} COMPONENT ${TARGET_NAME} + ) endif() + + ## Tests if(CATKIN_ENABLE_TESTING) add_subdirectory(tests) -endif() +endif() \ No newline at end of file diff --git a/cmake/serialConfig.cmake.in b/cmake/serialConfig.cmake.in new file mode 100644 index 00000000..e001142a --- /dev/null +++ b/cmake/serialConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + + +include("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_TARGET_NAME@.cmake") + +check_required_components("@PROJECT_NAME@") \ No newline at end of file From bb938f758a1d5dd2f339f154e8090d60f98068f2 Mon Sep 17 00:00:00 2001 From: blabbe Date: Wed, 4 Dec 2019 14:24:04 +0100 Subject: [PATCH 4/7] fix: install(ARCHIVE) call fail on Linux install() call on serial library was missing a proper ARCHIVE parameter, causing Unix build to fail. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2290b1b0..4826fd2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ else() ## Install executable install(TARGETS ${PROJECT_NAME} EXPORT ${EXPORT_TARGET_NAME} INCLUDES DESTINATION $ - ARCHIVE DESTINATION ${__dest} COMPONENT ${TARGET_NAME} + ARCHIVE DESTINATION "lib" COMPONENT ${PROJECT_NAME} ) endif() From 82fc4a7650cd10da10677f5f16ef8f795d25e7fb Mon Sep 17 00:00:00 2001 From: blabbe Date: Fri, 13 Mar 2020 09:55:00 +0100 Subject: [PATCH 5/7] fix: Enable Catkin use by default Prevents CI issues for now --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4826fd2f..8c6c3b5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ project(serial VERSION 1.2.1) ## Options -# Use Catkin (disabled by default) -option(USE_CATKIN off) +# Use Catkin +option(USE_CATKIN on) # Build serial sample option(BUILD_SAMPLE on) From c3c8ae22970c0831172ca705bc5cd30cd4568b20 Mon Sep 17 00:00:00 2001 From: blabbe Date: Fri, 13 Mar 2020 09:55:23 +0100 Subject: [PATCH 6/7] fix: Don't force STATIC on serail library --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c6c3b5b..881f17ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ else() endif() ## Add serial library -add_library(${PROJECT_NAME} STATIC ${serial_SRCS}) +add_library(${PROJECT_NAME} ${serial_SRCS}) if(APPLE) target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) From a0ff363f02d05c418da3831a49973bf99a24c44f Mon Sep 17 00:00:00 2001 From: blabbe Date: Fri, 13 Mar 2020 10:32:53 +0100 Subject: [PATCH 7/7] fix: restore rt and pthread set for katkin --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e53e809d..0a57dd76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ if(USE_CATKIN) 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 @@ -37,12 +39,6 @@ endif() -if(APPLE) - find_library(IOKIT_LIBRARY IOKit) - find_library(FOUNDATION_LIBRARY Foundation) -endif() - - ## Sources set(serial_SRCS @@ -69,6 +65,9 @@ endif() add_library(${PROJECT_NAME} ${serial_SRCS}) if(APPLE) + find_library(IOKIT_LIBRARY IOKit) + find_library(FOUNDATION_LIBRARY Foundation) + target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) elseif(UNIX) target_link_libraries(${PROJECT_NAME} rt pthread)