-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change cmakelist to support cmake, ros1 and ros2
- Loading branch information
Kailin
committed
Jan 31, 2023
1 parent
2f6911b
commit 43a0f87
Showing
7 changed files
with
209 additions
and
37 deletions.
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,43 +1,79 @@ | ||
# GENERAL ======================================================================================================== | ||
cmake_minimum_required(VERSION 3.5) | ||
project(fixposition_gnss_tf LANGUAGES CXX) | ||
project(fixposition_gnss_tf VERSION 3.0.0 LANGUAGES CXX) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_BUILD_TYPE "Release") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always -Wall -Wextra -Wpedantic -Wno-unused-parameter") | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
add_definitions(-DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) | ||
|
||
# DEPENDENCIES ========================================================================================================= | ||
find_package(Eigen3 REQUIRED) | ||
find_package(catkin REQUIRED) | ||
|
||
# define catkin package for this project | ||
catkin_package( | ||
INCLUDE_DIRS include | ||
LIBRARIES ${PROJECT_NAME} | ||
CATKIN_DEPENDS | ||
) | ||
|
||
include_directories(include ${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR}) | ||
include_directories(include ${EIGEN3_INCLUDE_DIR}) | ||
|
||
# BUILD SHARED LIBRARY ================================================================================================= | ||
add_library(${PROJECT_NAME} SHARED | ||
src/gnss_tf.cpp | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE ${catkin_LIBRARIES}) | ||
# link library against dependencies | ||
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${EIGEN3_LIBRARIES}) | ||
target_link_libraries(${PROJECT_NAME} ${EIGEN3_LIBRARIES}) | ||
|
||
# TEST ================================================================================================================= | ||
if (CATKIN_ENABLE_TESTING) | ||
find_package(yaml-cpp REQUIRED) | ||
list(APPEND PACKAGE_LIBRARIES ${PROJECT_NAME}) | ||
|
||
# INSTALL ============================================================================================================== | ||
# define ament package for this project | ||
install( | ||
DIRECTORY include | ||
DESTINATION . | ||
) | ||
|
||
# Mark executables and/or libraries for installation | ||
install(TARGETS ${PACKAGE_LIBRARIES} EXPORT ${PROJECT_NAME}-targets DESTINATION lib) | ||
|
||
install(TARGETS ${PROJECT_NAME} | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin | ||
) | ||
|
||
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake/${PROJECT_NAME}) | ||
|
||
catkin_add_gtest(gnss_test test/gnss_test.cpp) | ||
target_compile_definitions(gnss_test PRIVATE TEST_DIR="${CMAKE_CURRENT_LIST_DIR}/test/") | ||
target_link_libraries(gnss_test ${PROJECT_NAME} ${catkin_LIBRARIES} yaml-cpp) | ||
# Mark cpp header files for installation | ||
install(DIRECTORY include/${PROJECT_NAME} | ||
DESTINATION include | ||
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.hxx" | ||
) | ||
|
||
install(FILES package.xml DESTINATION share/${PROJECT_NAME}) | ||
|
||
# Create cmake config files | ||
# See doc: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#example-generating-package-files | ||
include(CMakePackageConfigHelpers) | ||
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}-config.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake | ||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME} | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO) | ||
|
||
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake | ||
VERSION ${PROJECT_VERSION} COMPATIBILITY ExactVersion) | ||
|
||
install(FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" | ||
DESTINATION lib/cmake/${PROJECT_NAME}) | ||
|
||
include(GoogleTest) | ||
gtest_discover_tests(gnss_test) | ||
endif() | ||
|
||
export(EXPORT ${PROJECT_NAME}-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake) | ||
|
||
# TEST ================================================================================================================= | ||
include(${PROJECT_SOURCE_DIR}/cmake/testing.cmake) | ||
find_package(yaml-cpp REQUIRED) | ||
|
||
add_gtest( | ||
TARGET gnss_test | ||
SOURCES test/gnss_test.cpp | ||
LINK_LIBS ${PROJECT_NAME} yaml-cpp | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/test | ||
) |
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
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,8 @@ | ||
@PACKAGE_INIT@ | ||
|
||
set(@PROJECT_NAME@_FOUND ON) | ||
set_and_check(@PROJECT_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include") | ||
set_and_check(@PROJECT_NAME@_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib") | ||
set(@PROJECT_NAME@_LIBRARIES "@PACKAGE_LIBRARIES@") | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") |
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,78 @@ | ||
# Global vars ---------------------------------------------------------------------------------------------------------- | ||
set(GTEST_PREFIX "gtest") | ||
set(BUILD_TEST_TARGET "build_test") | ||
|
||
enable_testing() | ||
|
||
if(NOT CATKIN_DEVEL_PREFIX) # not using ROS1 | ||
# Deps ------------------------------------------------------------------------------------------------------------- | ||
find_package(GTest REQUIRED) | ||
include_directories(${GTEST_INCLUDE_DIRS}) | ||
|
||
# CMake modules ---------------------------------------------------------------------------------------------------- | ||
include(GoogleTest) | ||
|
||
add_custom_target(${BUILD_TEST_TARGET}) | ||
endif() | ||
|
||
# Macros --------------------------------------------------------------------------------------------------------------- | ||
macro(add_gtest) | ||
# Arg parse | ||
set(options) | ||
set(one_value_args TARGET WORKING_DIRECTORY) | ||
set(multi_value_args SOURCES INCLUDE_DIRS LINK_DIRS LINK_LIBS) | ||
cmake_parse_arguments(ADD_GTEST "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) | ||
|
||
if(CATKIN_DEVEL_PREFIX AND CATKIN_ENABLE_TESTING) # using ROS1 with catkin | ||
# Call catkin macro instead | ||
catkin_add_gtest( | ||
${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
${ADD_GTEST_SOURCES} | ||
WORKING_DIRECTORY ${ADD_GTEST_WORKING_DIRECTORY} | ||
) | ||
target_link_libraries(${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
${catkin_LIBRARIES} | ||
${ADD_GTEST_LINK_LIBS} | ||
) | ||
elseif((DEFINED ENV{COLCON}) AND BUILD_TESTING) # ROS2 / build with colcon | ||
# Call ament_add_gtest macro | ||
find_package(ament_cmake_gtest REQUIRED) | ||
|
||
ament_add_gtest( | ||
${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
${ADD_GTEST_SOURCES} | ||
WORKING_DIRECTORY ${ADD_GTEST_WORKING_DIRECTORY}) | ||
|
||
target_link_libraries( | ||
${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
${ADD_GTEST_LINK_LIBS} | ||
) | ||
elseif(NOT CATKIN_DEVEL_PREFIX AND NOT(DEFINED ENV{COLCON})) # plain CMake | ||
# Make targets | ||
add_executable(${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
${ADD_GTEST_SOURCES} | ||
) | ||
|
||
target_include_directories(${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
PRIVATE ${ADD_GTEST_INCLUDE_DIRS} | ||
) | ||
target_link_directories(${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
PRIVATE ${ADD_GTEST_LINK_DIRS} | ||
) | ||
target_link_libraries(${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
PRIVATE | ||
GTest::gtest_main | ||
${ADD_GTEST_LINK_LIBS} | ||
) | ||
|
||
# Discover tests | ||
gtest_add_tests( | ||
TARGET ${GTEST_PREFIX}_${ADD_GTEST_TARGET} | ||
SOURCES ${ADD_GTEST_SOURCES} | ||
WORKING_DIRECTORY ${ADD_GTEST_WORKING_DIRECTORY} | ||
) | ||
|
||
# Add to global custom target | ||
add_dependencies(${BUILD_TEST_TARGET} ${GTEST_PREFIX}_${ADD_GTEST_TARGET}) | ||
endif() | ||
endmacro() |
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
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,13 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<package format="3"> | ||
<name>fixposition_gnss_tf</name> | ||
<version>2.0.0</version> | ||
<version>3.0.0</version> | ||
<description>Fixposition GNSS coordinates transformation</description> | ||
|
||
<maintainer email="[email protected]">Fixposition AG</maintainer> | ||
|
||
<license>MIT</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<depend>roscpp</depend> | ||
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend> | ||
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend> | ||
<test_depend condition="$ROS_VERSION == 2">ament_cmake_gtest</test_depend> | ||
|
||
<export> | ||
<build_type>cmake</build_type> | ||
</export> | ||
</package> |
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