Skip to content
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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

blabdouze
Copy link

Install target now generate a clean CMake package :

  • lib folder that contains the static library (debug and release)
  • include folder that contains the *.h
  • cmake folder that contains all the cmake related files (exported targets + version file)

This allow the package to be found by a find_package() call if you set serial_DIR var to the path of cmake folder.

# You can also specify the version if needed
find_package(serial REQUIRED)

# Don't need to specify serial include directories as the target already defines them.  
target_link_libraries(my_target PUBLIC serial)

This PR also disable Catkin dependency by default, you can restore it by setting USE_CATKIN option to ON.

Also the option BUILD_SAMPLE allow you to build or not the sample (default is ON).

This is somewhat #133 is trying to do while keeping Catkin dependency as an option if needed.

blabbe added 4 commits December 3, 2019 11:53
This commit allow the user to export the library that is compatible witha  find_package() call.
install() call on serial library was missing a proper ARCHIVE parameter, causing Unix build to fail.
@cz172638
Copy link

why not to squash all commit to one?

CMakeLists.txt Outdated
@@ -53,16 +66,18 @@ else()
endif()

## Add serial library
add_library(${PROJECT_NAME} ${serial_SRCS})
add_library(${PROJECT_NAME} STATIC ${serial_SRCS})

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)

@lukadt
Copy link

lukadt commented Mar 12, 2020

Can this pull request be fixed and merged? Having Catkin dependency as optional is a long time request

## Include headers
include_directories(include)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

The use of CMAKE_CURRENT_SOURCE_DIR is problematic when the project is used inside a bigger project via add_subdirectory , for example when using the FetchContent CMake module. Use of CMAKE_CURRENT_SOURCE_DIR should remove any ambiguity.

@moriarty moriarty mentioned this pull request Jun 7, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants