11cmake_minimum_required (VERSION 3.1)
22project (msp)
33
4- set (CMAKE_CXX_STANDARD 11 )
4+ set (CMAKE_CXX_STANDARD 14 )
55set (CMAKE_CXX_STANDARD_REQUIRED ON )
66set (CMAKE_CXX_EXTENSIONS OFF )
77if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
8- add_compile_options (-Wall -Wextra -Wpedantic)
8+ add_compile_options (-Wall -Wextra -Wpedantic -Werror )
99endif ()
1010
1111if (UNIX )
@@ -18,6 +18,9 @@ if(WIN32)
1818 include_directories (${ASIO_HEADER_PATH} )
1919endif ()
2020
21+ OPTION (BUILD_EXAMPLES "Build Library with examples" ON )
22+ OPTION (BUILD_TESTS "Build Library with tests" OFF )
23+
2124find_package (Threads)
2225
2326set (MSP_SOURCE_DIR src)
@@ -28,15 +31,8 @@ include_directories(${MSP_INCLUDE_DIR})
2831################################################################################
2932### libraries
3033
31- # low-level API
32- add_library (msp ${MSP_SOURCE_DIR} /MSP.cpp)
33- target_link_libraries (msp ${CMAKE_THREAD_LIBS_INIT} )
34-
35- # printing message content
36- add_library (msp_msg_print ${MSP_SOURCE_DIR} /msg_print.cpp)
37-
3834# client library
39- add_library (mspclient ${MSP_SOURCE_DIR} /Client.cpp)
35+ add_library (mspclient ${MSP_SOURCE_DIR} /Client.cpp ${MSP_SOURCE_DIR} /PeriodicTimer.cpp )
4036target_link_libraries (mspclient ${CMAKE_THREAD_LIBS_INIT} )
4137
4238# high-level API
@@ -47,54 +43,46 @@ target_link_libraries(msp_fcu mspclient)
4743################################################################################
4844### examples / tests
4945
50- # test reading speed
51- add_executable (msp_connection_test examples/msp_connection_test.cpp)
52- target_link_libraries (msp_connection_test msp)
46+ if (BUILD_EXAMPLES)
5347
54- # test and print all requests
55- add_executable (msp_read_test examples/msp_read_test .cpp)
56- target_link_libraries (msp_read_test msp msp_msg_print )
48+ # testing publish/subscribe
49+ add_executable (fcu_test examples/fcu_test .cpp)
50+ target_link_libraries (fcu_test msp_fcu )
5751
58- # testing publish/subscribe
59- add_executable (fcu_test examples/fcu_test .cpp)
60- target_link_libraries (fcu_test msp_fcu msp_msg_print )
52+ # test arming and disarming
53+ add_executable (fcu_arm examples/fcu_arm_test .cpp)
54+ target_link_libraries (fcu_arm msp_fcu)
6155
62- # test arming and disarming
63- add_executable (fcu_arm examples/fcu_arm_test .cpp)
64- target_link_libraries (fcu_arm msp_fcu)
56+ # test setting motors directly
57+ add_executable (fcu_motors examples/fcu_motor_test .cpp)
58+ target_link_libraries (fcu_motors msp_fcu)
6559
66- # test setting motors directly
67- add_executable (fcu_motors examples/fcu_motor_test .cpp)
68- target_link_libraries (fcu_motors msp_fcu)
60+ # subscribing with custom type
61+ add_executable (fcu_custom_type examples/fcu_custom_type .cpp)
62+ target_link_libraries (fcu_custom_type msp_fcu)
6963
70- # subscribing with custom type
71- add_executable (fcu_custom_type examples/fcu_custom_type .cpp)
72- target_link_libraries (fcu_custom_type msp_fcu )
64+ # client test for asynchronous callbacks
65+ add_executable (client_async_test examples/client_async_test .cpp)
66+ target_link_libraries (client_async_test mspclient )
7367
74- # cleanflight requests
75- add_executable (cleanflight_read_test examples/cleanflight_read_test.cpp)
76- target_link_libraries (cleanflight_read_test msp msp_msg_print)
77-
78- # client test for asynchronous callbacks
79- add_executable (client_async_test examples/client_async_test.cpp)
80- target_link_libraries (client_async_test mspclient msp_msg_print)
81-
82- # client test for blocking read
83- add_executable (client_read_test examples/client_read_test.cpp)
84- target_link_libraries (client_read_test mspclient msp_msg_print)
68+ # client test for blocking read
69+ add_executable (client_read_test examples/client_read_test.cpp)
70+ target_link_libraries (client_read_test mspclient )
8571
72+ endif ()
8673
8774################################################################################
8875### installation
8976
90- install (TARGETS msp msp_msg_print msp_fcu mspclient
77+ #install(TARGETS msp msp_msg_print msp_fcu mspclient
78+ install (TARGETS msp_fcu mspclient
9179 LIBRARY DESTINATION lib
9280 ARCHIVE DESTINATION lib)
9381install (DIRECTORY ${MSP_INCLUDE_DIR} DESTINATION include / FILES_MATCHING PATTERN "*.hpp" )
9482
9583SET (PKG_CONFIG_LIBDIR "\$ {prefix}/lib" )
9684SET (PKG_CONFIG_INCLUDEDIR "\$ {prefix}/include/" )
97- SET (PKG_CONFIG_LIBS "-L\$ {libdir} -lmsp - lmsp_fcu -lmspclient -lmsp_msg_print " )
85+ SET (PKG_CONFIG_LIBS "-L\$ {libdir} -lmsp_fcu -lmspclient" )
9886SET (PKG_CONFIG_CFLAGS "-I\$ {includedir}" )
9987
10088CONFIGURE_FILE (
@@ -104,3 +92,52 @@ CONFIGURE_FILE(
10492
10593INSTALL (FILES "${CMAKE_BINARY_DIR} /${PROJECT_NAME} .pc"
10694 DESTINATION lib/pkgconfig)
95+
96+
97+
98+ ###############################################################################
99+ ### testing
100+ if (BUILD_TESTS)
101+ enable_testing ()
102+
103+ # Download and unpack googletest at configure time
104+ configure_file (CMakeLists.txt.in googletest/CMakeLists.txt)
105+ execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
106+ RESULT_VARIABLE result
107+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /googletest )
108+ if (result)
109+ message (FATAL_ERROR "CMake step for googletest failed: ${result} " )
110+ endif ()
111+ execute_process (COMMAND ${CMAKE_COMMAND} --build .
112+ RESULT_VARIABLE result
113+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /googletest )
114+ if (result)
115+ message (FATAL_ERROR "Build step for googletest failed: ${result} " )
116+ endif ()
117+
118+ # Prevent overriding the parent project's compiler/linker
119+ # settings on Windows
120+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
121+
122+ # Add googletest directly to our build. This defines
123+ # the gtest and gtest_main targets.
124+ add_subdirectory (/usr/src/gtest
125+ ${CMAKE_BINARY_DIR} /googletest-build
126+ EXCLUDE_FROM_ALL )
127+
128+ # The gtest/gtest_main targets carry header search path
129+ # dependencies automatically when using CMake 2.8.11 or
130+ # later. Otherwise we have to add them here ourselves.
131+ if (CMAKE_VERSION VERSION_LESS 2.8.11)
132+ include_directories ("${gtest_SOURCE_DIR} /include" )
133+ endif ()
134+
135+ add_executable (value_test test /value_test.cpp)
136+ target_link_libraries (value_test gtest_main)
137+ add_test (NAME value_test COMMAND value_test)
138+
139+ add_executable (bytevector_test test /ByteVector_test.cpp)
140+ target_link_libraries (bytevector_test gtest_main)
141+ add_test (NAME bytevector_test COMMAND bytevector_test)
142+
143+ endif ()
0 commit comments