-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install target generates a clean CMake package (+ Catkin dependency is now optional) #215
Open
blabdouze
wants to merge
8
commits into
wjwwood:main
Choose a base branch
from
blabdouze:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
690990c
feat: Catkin dependancy is now optional
61a914c
cmake: Add option to build sample
e3516cd
feat: CMake library export
bb938f7
fix: install(ARCHIVE) call fail on Linux
82fc4a7
fix: Enable Catkin use by default
c3c8ae2
fix: Don't force STATIC on serail library
34a4475
Merge branch 'master' into master
blabdouze a0ff363
fix: restore rt and pthread set for katkin
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The use of |
||||||
|
||||||
|
||||||
## 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 '<PROJECT-NAME>ConfigVersion.cmake' | ||||||
write_basic_package_version_file(${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/${PROJECT_NAME}Config-version.cmake | ||||||
# <AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion> | ||||||
# Careful : SameMinorVersion and ExactVersion were introduced in CMake 3.11 | ||||||
COMPATIBILITY SameMajorVersion | ||||||
) | ||||||
|
||||||
# Configure '<PROJECT-NAME>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 $<INSTALL_INTERFACE:include/> | ||||||
ARCHIVE DESTINATION ${__dest} COMPONENT ${TARGET_NAME} | ||||||
) | ||||||
endif() | ||||||
|
||||||
|
||||||
|
||||||
## Tests | ||||||
if(CATKIN_ENABLE_TESTING) | ||||||
add_subdirectory(tests) | ||||||
endif() | ||||||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@PACKAGE_INIT@ | ||
|
||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
|
||
check_required_components("@PROJECT_NAME@") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why forcing static?
better would be to use -DBUILD_SHARED_LIBS=OFF (see https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html)