2017-01-29 16:32:18 -04:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2015-06-04 20:10:20 -03:00
|
|
|
|
2017-01-29 16:32:18 -04:00
|
|
|
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
|
2016-04-24 19:18:32 -03:00
|
|
|
add_compile_options(-Qunused-arguments )
|
2015-08-29 21:01:07 -03:00
|
|
|
endif()
|
2017-01-29 16:32:18 -04:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2016-04-24 19:18:32 -03:00
|
|
|
add_compile_options(-Qunused-arguments)
|
2015-08-29 21:01:07 -03:00
|
|
|
endif()
|
|
|
|
|
2016-08-06 23:47:57 -03:00
|
|
|
project(px4_unittests)
|
2015-01-02 18:44:28 -04:00
|
|
|
enable_testing()
|
|
|
|
|
2016-12-31 17:34:07 -04:00
|
|
|
message(STATUS ${CONFIG})
|
|
|
|
|
2016-07-29 13:23:19 -03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -std=gnu99 -g")
|
2016-08-06 23:47:57 -03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=gnu++0x -g -fno-exceptions -fno-rtti -fno-threadsafe-statics -DCONFIG_WCHAR_BUILTIN -D__CUSTOM_FILE_IO__")
|
2015-06-04 20:10:20 -03:00
|
|
|
|
2016-12-04 20:10:24 -04:00
|
|
|
# code coverage
|
|
|
|
if ($ENV{PX4_CODE_COVERAGE} MATCHES "1")
|
|
|
|
message(STATUS "Code coverage build flags enabled")
|
2017-01-03 04:24:44 -04:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3 -fprofile-arcs -ftest-coverage --coverage")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3 -fprofile-arcs -ftest-coverage --coverage")
|
2016-12-04 20:10:24 -04:00
|
|
|
endif()
|
|
|
|
|
2016-08-18 16:37:23 -03:00
|
|
|
if (NOT PX4_SOURCE_DIR)
|
|
|
|
set(PX4_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(GTEST_DIR ${PX4_SOURCE_DIR}/unittests/googletest)
|
2015-01-02 18:44:28 -04:00
|
|
|
add_subdirectory(${GTEST_DIR})
|
|
|
|
include_directories(${GTEST_DIR}/include)
|
2015-01-06 09:50:45 -04:00
|
|
|
|
2016-08-18 16:37:23 -03:00
|
|
|
set(PX4_SRC ${PX4_SOURCE_DIR}/src)
|
2016-07-29 13:23:19 -03:00
|
|
|
set(PX4_SITL_BUILD ${PX4_SRC}/../build_posix_sitl_default)
|
2015-06-04 20:10:20 -03:00
|
|
|
|
2016-08-18 16:37:23 -03:00
|
|
|
include_directories(${PX4_SOURCE_DIR})
|
2016-04-24 19:18:32 -03:00
|
|
|
include_directories(${PX4_SITL_BUILD}/src)
|
|
|
|
include_directories(${PX4_SITL_BUILD}/src/modules)
|
|
|
|
include_directories(${PX4_SITL_BUILD}/src/modules/param)
|
|
|
|
include_directories(${PX4_SITL_BUILD}/src/modules/uORB)
|
|
|
|
include_directories(${PX4_SRC})
|
|
|
|
include_directories(${PX4_SRC}/drivers)
|
|
|
|
include_directories(${PX4_SRC}/drivers/device)
|
|
|
|
include_directories(${PX4_SRC}/lib)
|
|
|
|
include_directories(${PX4_SRC}/lib/DriverFramework/framework/include)
|
|
|
|
include_directories(${PX4_SRC}/modules)
|
|
|
|
include_directories(${PX4_SRC}/modules/uORB)
|
|
|
|
include_directories(${PX4_SRC}/platforms)
|
|
|
|
include_directories(${PX4_SRC}/platforms/posix/include)
|
|
|
|
include_directories(${PX4_SRC}/platforms/posix/px4_layer)
|
2016-07-29 13:23:19 -03:00
|
|
|
include_directories(${PX4_SRC}/platforms/posix/work_queue)
|
2015-01-02 18:44:28 -04:00
|
|
|
|
2016-07-29 13:23:19 -03:00
|
|
|
add_definitions(-D__CUSTOM_FILE_IO__)
|
2015-01-02 18:44:28 -04:00
|
|
|
add_definitions(-D__EXPORT=)
|
2016-04-24 19:18:32 -03:00
|
|
|
add_definitions(-D__PX4_POSIX)
|
2015-01-06 19:19:30 -04:00
|
|
|
add_definitions(-D__PX4_TESTS)
|
2016-07-29 13:23:19 -03:00
|
|
|
add_definitions(-D__PX4_UNIT_TESTS)
|
2016-04-24 19:18:32 -03:00
|
|
|
add_definitions(-D_UNIT_TEST=)
|
2015-02-02 16:03:19 -04:00
|
|
|
add_definitions(-DERROR=-1)
|
2016-04-24 19:18:32 -03:00
|
|
|
add_definitions(-Dmain_t=int)
|
|
|
|
add_definitions(-Dnoreturn_function=)
|
2015-02-02 16:03:19 -04:00
|
|
|
add_definitions(-DOK=0)
|
2015-01-02 18:44:28 -04:00
|
|
|
|
2016-07-29 13:23:19 -03:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
add_definitions(-D__PX4_DARWIN)
|
|
|
|
else()
|
|
|
|
add_definitions(-D__PX4_LINUX)
|
|
|
|
endif()
|
2015-01-02 18:44:28 -04:00
|
|
|
|
2016-08-06 23:47:57 -03:00
|
|
|
set(PX4_PLATFORM
|
|
|
|
${PX4_SITL_BUILD}/libmsg_gen.a
|
|
|
|
${PX4_SITL_BUILD}/src/drivers/boards/sitl/libdrivers__boards__sitl.a
|
|
|
|
${PX4_SITL_BUILD}/src/drivers/device/libdrivers__device.a
|
|
|
|
${PX4_SITL_BUILD}/src/lib/DriverFramework/framework/liblib__DriverFramework__framework.a
|
|
|
|
${PX4_SITL_BUILD}/src/lib/DriverFramework/framework/src/libdf_driver_framework.a
|
|
|
|
${PX4_SITL_BUILD}/src/platforms/common/libplatforms__common.a
|
|
|
|
${PX4_SITL_BUILD}/src/platforms/posix/px4_layer/libplatforms__posix__px4_layer.a
|
|
|
|
${PX4_SITL_BUILD}/src/platforms/posix/work_queue/libplatforms__posix__work_queue.a
|
|
|
|
)
|
2016-07-29 13:23:19 -03:00
|
|
|
|
|
|
|
# check
|
|
|
|
add_custom_target(check
|
|
|
|
COMMAND ${CMAKE_CTEST_COMMAND} -j2 --output-on-failure
|
2016-08-18 16:37:23 -03:00
|
|
|
WORKING_DIR ${PX4_BINARY_DIR}
|
2016-07-29 13:23:19 -03:00
|
|
|
USES_TERMINAL)
|
|
|
|
|
|
|
|
# add_gtest
|
|
|
|
function(add_gtest)
|
|
|
|
foreach(test_name ${ARGN})
|
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
2016-08-06 23:47:57 -03:00
|
|
|
target_link_libraries(${test_name} gtest_main pthread ${PX4_PLATFORM})
|
2016-07-29 13:23:19 -03:00
|
|
|
else()
|
2016-08-06 23:47:57 -03:00
|
|
|
target_link_libraries(${test_name} gtest_main pthread rt ${PX4_PLATFORM})
|
2016-07-29 13:23:19 -03:00
|
|
|
endif()
|
2016-12-31 17:34:07 -04:00
|
|
|
add_test(NAME ${test_name} COMMAND ${test_name} --gtest_output=xml WORKING_DIRECTORY ${PX4_BINARY_DIR})
|
2016-07-29 13:23:19 -03:00
|
|
|
add_dependencies(check ${test_name})
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
2016-04-24 19:18:32 -03:00
|
|
|
|
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
# TESTS
|
|
|
|
#######################################################################
|
|
|
|
# add_executable(example_test example_test.cpp)
|
|
|
|
# add_gtest(example_test)
|
|
|
|
|
2015-02-02 11:53:12 -04:00
|
|
|
# param_test
|
2017-02-17 05:12:08 -04:00
|
|
|
add_executable(param_test setup.cpp param_test.cpp uorb_stub.cpp
|
2016-04-24 19:18:32 -03:00
|
|
|
${PX4_SRC}/modules/systemlib/bson/tinybson.c
|
|
|
|
${PX4_SRC}/modules/systemlib/param/param.c)
|
2016-08-06 23:47:57 -03:00
|
|
|
target_link_libraries(param_test ${PX4_PLATFORM})
|
2016-04-24 19:18:32 -03:00
|
|
|
add_gtest(param_test)
|