Skip to content

Commit

Permalink
Squashed Commit:
Browse files Browse the repository at this point in the history
* change cmakelist to support cmake, ros1 and ros2
  • Loading branch information
Kailin committed Jan 31, 2023
1 parent 2f6911b commit 43a0f87
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 37 deletions.
80 changes: 58 additions & 22 deletions CMakeLists.txt
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
)
60 changes: 53 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,86 @@ This is a simple C++ library for geodetic coordinate transformations. This shoul

- [Eigen3](https://eigen.tuxfamily.org/index.php?title=Main_Page), tested with version [3.3.7](https://gitlab.com/libeigen/eigen/-/releases/3.3.7)
- [CMake](https://cmake.org/)
- [Catkin](http://wiki.ros.org/catkin)
- [Yaml-Cpp](https://yaml-cpp.docsforge.com/)

For the tests:

- [Googletest](https://github.com/google/googletest)

## Build
Build system:
- Plain CMake
- catkin (for ROS1)
- colcon (for ROS2)
## Installing dependencies on Ubuntu system

### Using [catkin_tools](https://catkin-tools.readthedocs.io/en/latest/) (_recommended_):
```
sudo apt update
sudo apt install -y wget
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt install -y build-essential cmake
sudo apt install -y libeigen3-dev
sudo apt install -y libyaml-cpp-dev
```

- Create a catkin workspace with the structure:
## Build

### Using catkin (ROS1):
- Create a ament workspace with the structure:

```
catkin_ws
└── src
└── gnsstransformationlib
└── <Other Catkin Pacakges>
└── fixposition_gnss_tf
└── <Other Pacakges>
```

- in the workspace do:

```bash
catkin build fixposition_gnss_tf
```
- and to build and run unit tests

### Using CMake:
```bash
catkin run_tests fixposition_gnss_tf
```

### Using colcon (ROS2):
- Create a ament workspace with the structure:

```
ament_ws
└── src
└── fixposition_gnss_tf
└── <Other Pacakges>
```

- in the workspace do:

```bash
colcon build --packages-select fixposition_gnss_tf
```
- and to build and run unit tests

```bash
colcon test --packages-select fixposition_gnss_tf
```

### Using CMake:
- build
```bash
mkdir build
cd build
cmake ..
make
```

- run tests
```bash
make test
```

## Example Usage

See `test/gnss_test.cpp` for examples of how to use these functions
Expand Down
8 changes: 8 additions & 0 deletions cmake/fixposition_gnss_tf-config.cmake.in
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]")
78 changes: 78 additions & 0 deletions cmake/testing.cmake
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()
3 changes: 1 addition & 2 deletions include/fixposition_gnss_tf/gnss_tf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ Eigen::Vector3d TfEnuEcef(const Eigen::Vector3d &ecef, const Eigen::Vector3d &wg
*/
Eigen::Vector3d TfEcefEnu(const Eigen::Vector3d &enu, const Eigen::Vector3d &wgs84llh_ref);


Eigen::Vector3d TfNedEcef(const Eigen::Vector3d &ecef, const Eigen::Vector3d &wgs84llh_ref);
Eigen::Vector3d TfEcefNed(const Eigen::Vector3d &ned, const Eigen::Vector3d &wgs84llh_ref);

Expand Down Expand Up @@ -162,4 +161,4 @@ inline Eigen::Vector3d RotToEul(const Eigen::Matrix3d &rot) {

} // namespace gnss_tf

#endif
#endif
13 changes: 9 additions & 4 deletions package.xml
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>
4 changes: 2 additions & 2 deletions test/gnss_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace {

static const double ecef_err = 5e-4;
static const double rad_err = 1e-8;
static const std::string gnss_test_config_path = TEST_DIR + std::string("gnss_test.yaml");
static const std::string geometry_test_config_path = TEST_DIR + std::string("geometry_test.yaml");
static const std::string gnss_test_config_path = std::string("gnss_test.yaml");
static const std::string geometry_test_config_path = std::string("geometry_test.yaml");

/**
* @brief Convert degrees to radians
Expand Down

0 comments on commit 43a0f87

Please sign in to comment.