Skip to content

Commit 4d5be00

Browse files
committed
Convert package to a pure CMake package
1 parent 683e12d commit 4d5be00

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

CMakeLists.txt

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(serial)
33

4-
# Find catkin
5-
find_package(catkin REQUIRED)
6-
74
if(APPLE)
85
find_library(IOKIT_LIBRARY IOKit)
96
find_library(FOUNDATION_LIBRARY Foundation)
107
endif()
118

12-
if(UNIX AND NOT APPLE)
13-
# If Linux, add rt and pthread
14-
set(rt_LIBRARIES rt)
15-
set(pthread_LIBRARIES pthread)
16-
catkin_package(
17-
LIBRARIES ${PROJECT_NAME}
18-
INCLUDE_DIRS include
19-
DEPENDS rt pthread
20-
)
21-
else()
22-
# Otherwise normal call
23-
catkin_package(
24-
LIBRARIES ${PROJECT_NAME}
25-
INCLUDE_DIRS include
26-
)
27-
endif()
28-
299
## Sources
3010
set(serial_SRCS
3111
src/serial.cc
@@ -66,15 +46,25 @@ include_directories(include)
6646

6747
## Install executable
6848
install(TARGETS ${PROJECT_NAME}
69-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
70-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
49+
ARCHIVE DESTINATION lib
50+
LIBRARY DESTINATION lib
7151
)
7252

7353
## Install headers
7454
install(FILES include/serial/serial.h include/serial/v8stdint.h
75-
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
55+
DESTINATION include/serial)
56+
57+
## Install CMake config
58+
install(FILES cmake/serialConfig.cmake
59+
DESTINATION share/serial/cmake)
60+
61+
62+
## Install package.xml
63+
install(FILES package.xml
64+
DESTINATION share/serial)
7665

7766
## Tests
78-
if(CATKIN_ENABLE_TESTING)
67+
include(CTest)
68+
if(BUILD_TESTING)
7969
add_subdirectory(tests)
8070
endif()

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test:
5656
@mkdir -p build
5757
cd build && cmake $(CMAKE_FLAGS) ..
5858
ifneq ($(MAKE),)
59-
cd build && $(MAKE) run_tests
59+
cd build && $(MAKE) all test
6060
else
61-
cd build && make run_tests
61+
cd build && make all test
6262
endif

cmake/serialConfig.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
get_filename_component(SERIAL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
2+
set(SERIAL_INCLUDE_DIRS "${SERIAL_CMAKE_DIR}/../../../include")
3+
find_library(SERIAL_LIBRARIES serial PATHS ${SERIAL_CMAKE_DIR}/../../../lib/serial)

package.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
<author email="[email protected]">William Woodall</author>
2020
<author email="[email protected]">John Harrison</author>
2121

22-
<buildtool_depend>catkin</buildtool_depend>
22+
<buildtool_depend>cmake</buildtool_depend>
2323

2424
<test_depend>boost</test_depend>
25+
<test_depend>gtest</test_depend>
2526

27+
<export>
28+
<build_type>cmake</build_type>
29+
</export>
2630
</package>

tests/CMakeLists.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
if(UNIX)
2-
catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc)
3-
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES})
2+
find_package(Boost REQUIRED)
3+
find_package(GTest REQUIRED)
4+
include_directories(${GTEST_INCLUDE_DIRS})
5+
6+
add_executable(${PROJECT_NAME}-test unix_serial_tests.cc)
7+
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES} ${GTEST_LIBRARIES})
48
if(NOT APPLE)
59
target_link_libraries(${PROJECT_NAME}-test util)
610
endif()
11+
add_test("${PROJECT_NAME}-test-gtest" ${PROJECT_NAME}-test)
712

813
if(NOT APPLE) # these tests are unreliable on macOS
9-
catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc)
10-
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME})
14+
add_executable(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc)
15+
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} ${GTEST_LIBRARIES})
16+
add_test("${PROJECT_NAME}-test-timer-gtest" ${PROJECT_NAME}-test-timer)
1117
endif()
1218
endif()

0 commit comments

Comments
 (0)