From 4d5be00015bb1aad1017a064408e884d4af388db Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 3 Jul 2019 13:24:15 -0700 Subject: [PATCH] Convert package to a pure CMake package --- CMakeLists.txt | 38 ++++++++++++++------------------------ Makefile | 4 ++-- cmake/serialConfig.cmake | 3 +++ package.xml | 6 +++++- tests/CMakeLists.txt | 14 ++++++++++---- 5 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 cmake/serialConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad1..244d3870 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,11 @@ cmake_minimum_required(VERSION 2.8.3) project(serial) -# Find catkin -find_package(catkin REQUIRED) - if(APPLE) find_library(IOKIT_LIBRARY IOKit) find_library(FOUNDATION_LIBRARY Foundation) endif() -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 - ) -endif() - ## Sources set(serial_SRCS src/serial.cc @@ -66,15 +46,25 @@ include_directories(include) ## Install executable install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib ) ## Install headers install(FILES include/serial/serial.h include/serial/v8stdint.h - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) + DESTINATION include/serial) + +## Install CMake config +install(FILES cmake/serialConfig.cmake + DESTINATION share/serial/cmake) + + +## Install package.xml +install(FILES package.xml + DESTINATION share/serial) ## Tests -if(CATKIN_ENABLE_TESTING) +include(CTest) +if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/Makefile b/Makefile index e1720722..0f49ddc7 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ test: @mkdir -p build cd build && cmake $(CMAKE_FLAGS) .. ifneq ($(MAKE),) - cd build && $(MAKE) run_tests + cd build && $(MAKE) all test else - cd build && make run_tests + cd build && make all test endif diff --git a/cmake/serialConfig.cmake b/cmake/serialConfig.cmake new file mode 100644 index 00000000..e90bdf69 --- /dev/null +++ b/cmake/serialConfig.cmake @@ -0,0 +1,3 @@ +get_filename_component(SERIAL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(SERIAL_INCLUDE_DIRS "${SERIAL_CMAKE_DIR}/../../../include") +find_library(SERIAL_LIBRARIES serial PATHS ${SERIAL_CMAKE_DIR}/../../../lib/serial) diff --git a/package.xml b/package.xml index 27781e14..785adeb3 100644 --- a/package.xml +++ b/package.xml @@ -19,8 +19,12 @@ William Woodall John Harrison - catkin + cmake boost + gtest + + cmake + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e52a4d31..23bf283b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,18 @@ if(UNIX) - catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) - target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES}) + find_package(Boost REQUIRED) + find_package(GTest REQUIRED) + include_directories(${GTEST_INCLUDE_DIRS}) + + add_executable(${PROJECT_NAME}-test unix_serial_tests.cc) + target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES} ${GTEST_LIBRARIES}) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() + add_test("${PROJECT_NAME}-test-gtest" ${PROJECT_NAME}-test) if(NOT APPLE) # these tests are unreliable on macOS - catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) - target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) + add_executable(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) + target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} ${GTEST_LIBRARIES}) + add_test("${PROJECT_NAME}-test-timer-gtest" ${PROJECT_NAME}-test-timer) endif() endif()