2015-01-02 18:44:28 -04:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2015-06-04 20:10:20 -03:00
|
|
|
|
|
|
|
include( CMakeForceCompiler )
|
|
|
|
#set( CMAKE_SYSTEM_NAME px4_posix_clang )
|
|
|
|
CMAKE_FORCE_C_COMPILER( clang Clang )
|
|
|
|
CMAKE_FORCE_CXX_COMPILER( clang++ Clang )
|
|
|
|
#set( CMAKE_C_COMPILER /opt/clang-3.4.2/bin/clang )
|
|
|
|
#set( CMAKE_CXX_COMPILER /opt/clang-3.4.2/bin/clang++ )
|
|
|
|
#set( CMAKE_FIND_ROOT_PATH /opt/clang-3.4.2/ )
|
|
|
|
#set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM_NEVER )
|
|
|
|
#set( CMAKE_FIND_ROOT_PATH_MODE_LIBARARY_ONLY )
|
|
|
|
#set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE_ONLY )
|
|
|
|
|
2015-08-29 21:01:07 -03:00
|
|
|
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
add_compile_options(-Qunused-arguments)
|
|
|
|
endif()
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
add_compile_options(-Qunused-arguments)
|
|
|
|
endif()
|
|
|
|
|
2015-01-02 18:44:28 -04:00
|
|
|
project(unittests)
|
|
|
|
enable_testing()
|
|
|
|
|
2015-06-04 20:10:20 -03:00
|
|
|
|
2015-01-06 09:38:08 -04:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
|
|
if(COMPILER_SUPPORTS_CXX11)
|
2015-06-04 20:10:20 -03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics -D__CUSTOM_FILE_IO__ -g -Wall")
|
2015-01-06 09:38:08 -04:00
|
|
|
elseif(COMPILER_SUPPORTS_CXX0X)
|
2015-06-04 20:10:20 -03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fno-exceptions -fno-rtti -fno-threadsafe-statics -D__CUSTOM_FILE_IO__ -g -Wall")
|
2015-01-06 09:38:08 -04:00
|
|
|
else()
|
|
|
|
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
|
|
|
endif()
|
2015-06-04 20:10:20 -03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g")
|
|
|
|
|
|
|
|
#set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem" )
|
|
|
|
#set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem" )
|
2015-01-06 09:38:08 -04:00
|
|
|
|
2015-01-02 18:44:28 -04:00
|
|
|
set(GTEST_DIR gtest)
|
|
|
|
add_subdirectory(${GTEST_DIR})
|
|
|
|
include_directories(${GTEST_DIR}/include)
|
2015-01-06 09:50:45 -04:00
|
|
|
|
|
|
|
set(PX_SRC ${CMAKE_SOURCE_DIR}/../src)
|
2015-01-02 18:44:28 -04:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR})
|
2015-01-06 09:50:45 -04:00
|
|
|
include_directories(${PX_SRC})
|
|
|
|
include_directories(${PX_SRC}/modules)
|
2015-06-04 20:10:20 -03:00
|
|
|
include_directories(${PX_SRC}/modules/uORB)
|
2015-01-06 09:50:45 -04:00
|
|
|
include_directories(${PX_SRC}/lib)
|
2015-02-02 16:03:19 -04:00
|
|
|
include_directories(${PX_SRC}/drivers)
|
2015-04-21 04:23:36 -03:00
|
|
|
include_directories(${PX_SRC}/platforms)
|
2015-06-04 20:10:20 -03:00
|
|
|
include_directories(${PX_SRC}/platforms/posix/include)
|
|
|
|
include_directories(${PX_SRC}/platforms/posix/px4_layer)
|
|
|
|
include_directories(${PX_SRC}/drivers/device )
|
|
|
|
|
2015-01-02 18:44:28 -04:00
|
|
|
|
|
|
|
add_definitions(-D__EXPORT=)
|
2015-01-06 19:19:30 -04:00
|
|
|
add_definitions(-D__PX4_TESTS)
|
2015-01-07 03:20:35 -04:00
|
|
|
add_definitions(-Dnoreturn_function=)
|
|
|
|
add_definitions(-Dmain_t=int)
|
2015-02-02 16:03:19 -04:00
|
|
|
add_definitions(-DERROR=-1)
|
|
|
|
add_definitions(-DOK=0)
|
2015-02-03 05:35:20 -04:00
|
|
|
add_definitions(-D_UNIT_TEST=)
|
2015-05-19 17:36:13 -03:00
|
|
|
add_definitions(-D__PX4_POSIX)
|
2015-01-02 18:44:28 -04:00
|
|
|
|
2015-01-05 19:34:13 -04:00
|
|
|
# check
|
2015-01-05 19:55:38 -04:00
|
|
|
add_custom_target(unittests COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
2015-01-05 19:34:13 -04:00
|
|
|
|
2015-01-02 18:44:28 -04:00
|
|
|
function(add_gtest)
|
|
|
|
foreach(test_name ${ARGN})
|
2015-06-13 06:07:17 -03:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
target_link_libraries(${test_name} gtest_main pthread )
|
|
|
|
add_definitions(-D__PX4_DARWIN)
|
|
|
|
else()
|
|
|
|
target_link_libraries(${test_name} gtest_main pthread rt )
|
|
|
|
add_definitions(-D__PX4_LINUX)
|
|
|
|
endif()
|
2015-01-05 19:43:26 -04:00
|
|
|
add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
2015-01-05 19:55:38 -04:00
|
|
|
add_dependencies(unittests ${test_name})
|
2015-01-02 18:44:28 -04:00
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2015-06-04 20:10:20 -03:00
|
|
|
add_library( px4_platform
|
|
|
|
# ${PX_SRC}/platforms/common/px4_getopt.c
|
2015-08-26 01:59:01 -03:00
|
|
|
${PX_SRC}/platforms/posix/px4_layer/px4_log.c
|
2015-06-04 20:10:20 -03:00
|
|
|
${PX_SRC}/platforms/posix/px4_layer/px4_posix_impl.cpp
|
|
|
|
${PX_SRC}/platforms/posix/px4_layer/px4_posix_tasks.cpp
|
2015-07-29 00:48:51 -03:00
|
|
|
${PX_SRC}/platforms/posix/work_queue/work_lock.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/hrt_queue.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/work_queue.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/queue.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/work_cancel.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/hrt_work_cancel.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/hrt_thread.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/work_thread.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/dq_rem.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/sq_addlast.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/sq_addafter.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/dq_remfirst.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/sq_remfirst.c
|
|
|
|
${PX_SRC}/platforms/posix/work_queue/dq_addlast.c
|
2015-06-04 20:10:20 -03:00
|
|
|
${PX_SRC}/platforms/posix/px4_layer/lib_crc32.c
|
|
|
|
${PX_SRC}/platforms/posix/px4_layer/drv_hrt.c
|
|
|
|
${PX_SRC}/drivers/device/device_posix.cpp
|
|
|
|
${PX_SRC}/drivers/device/vdev.cpp
|
|
|
|
${PX_SRC}/drivers/device/vfile.cpp
|
|
|
|
${PX_SRC}/drivers/device/vdev_posix.cpp
|
|
|
|
${PX_SRC}/drivers/device/i2c_posix.cpp
|
|
|
|
${PX_SRC}/drivers/device/sim.cpp
|
|
|
|
${PX_SRC}/drivers/device/ringbuffer.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
#target_include_directories( px4_platform PUBLIC ${PX_SRC}/platforms )
|
|
|
|
|
|
|
|
|
2015-01-02 18:44:28 -04:00
|
|
|
|
|
|
|
# add each test
|
2015-01-06 09:50:45 -04:00
|
|
|
add_executable(autodeclination_test autodeclination_test.cpp ${PX_SRC}/lib/geo_lookup/geo_mag_declination.c)
|
2015-01-02 18:44:28 -04:00
|
|
|
add_gtest(autodeclination_test)
|
2015-01-05 19:18:47 -04:00
|
|
|
|
|
|
|
# mixer_test
|
2015-01-06 09:50:45 -04:00
|
|
|
add_custom_command(OUTPUT ${PX_SRC}/modules/systemlib/mixer/mixer_multirotor.generated.h
|
|
|
|
COMMAND ${PX_SRC}/modules/systemlib/mixer/multi_tables.py > ${PX_SRC}/modules/systemlib/mixer/mixer_multirotor.generated.h)
|
2015-01-05 19:18:47 -04:00
|
|
|
add_executable(mixer_test mixer_test.cpp hrt.cpp
|
2015-01-06 09:50:45 -04:00
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer.cpp
|
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer_group.cpp
|
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer_load.c
|
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer_multirotor.cpp
|
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer_multirotor.generated.h
|
|
|
|
${PX_SRC}/modules/systemlib/mixer/mixer_simple.cpp
|
|
|
|
${PX_SRC}/modules/systemlib/pwm_limit/pwm_limit.c
|
|
|
|
${PX_SRC}/systemcmds/tests/test_mixer.cpp)
|
2015-08-29 21:01:07 -03:00
|
|
|
target_link_libraries( mixer_test px4_platform )
|
2015-06-04 20:10:20 -03:00
|
|
|
|
|
|
|
|
2015-02-03 06:49:34 -04:00
|
|
|
add_gtest(mixer_test)
|
2015-01-05 19:18:47 -04:00
|
|
|
|
|
|
|
# conversion_test
|
2015-01-06 09:50:45 -04:00
|
|
|
add_executable(conversion_test conversion_test.cpp ${PX_SRC}/systemcmds/tests/test_conv.cpp)
|
2015-06-17 22:05:04 -03:00
|
|
|
target_link_libraries( conversion_test px4_platform )
|
2015-01-05 19:18:47 -04:00
|
|
|
add_gtest(conversion_test)
|
2015-01-05 19:34:13 -04:00
|
|
|
|
2015-01-05 19:43:26 -04:00
|
|
|
# sbus2_test
|
|
|
|
add_executable(sbus2_test sbus2_test.cpp hrt.cpp)
|
2015-06-17 22:05:04 -03:00
|
|
|
target_link_libraries( sbus2_test px4_platform )
|
2015-01-05 19:50:26 -04:00
|
|
|
add_gtest(sbus2_test)
|
2015-01-05 19:34:13 -04:00
|
|
|
|
2015-01-05 19:50:26 -04:00
|
|
|
# st24_test
|
2015-01-06 09:50:45 -04:00
|
|
|
add_executable(st24_test st24_test.cpp hrt.cpp ${PX_SRC}/lib/rc/st24.c)
|
2015-06-17 22:05:04 -03:00
|
|
|
target_link_libraries( st24_test px4_platform )
|
2015-01-05 19:50:26 -04:00
|
|
|
add_gtest(st24_test)
|
2015-01-05 19:43:26 -04:00
|
|
|
|
2015-03-06 17:26:32 -04:00
|
|
|
# sumd_test
|
|
|
|
add_executable(sumd_test sumd_test.cpp hrt.cpp ${PX_SRC}/lib/rc/sumd.c)
|
2015-06-17 22:05:04 -03:00
|
|
|
target_link_libraries( sumd_test px4_platform )
|
2015-03-06 17:26:32 -04:00
|
|
|
add_gtest(sumd_test)
|
|
|
|
|
2015-01-05 19:55:38 -04:00
|
|
|
# sf0x_test
|
2015-01-06 09:50:45 -04:00
|
|
|
add_executable(sf0x_test sf0x_test.cpp ${PX_SRC}/drivers/sf0x/sf0x_parser.cpp)
|
2015-06-17 22:05:04 -03:00
|
|
|
target_link_libraries( sf0x_test px4_platform )
|
2015-01-05 19:55:38 -04:00
|
|
|
add_gtest(sf0x_test)
|
2015-02-02 11:53:12 -04:00
|
|
|
|
|
|
|
# param_test
|
|
|
|
add_executable(param_test param_test.cpp
|
|
|
|
hrt.cpp
|
2015-02-03 05:35:20 -04:00
|
|
|
uorb_stub.cpp
|
2015-02-02 11:53:12 -04:00
|
|
|
${PX_SRC}/modules/systemlib/param/param.c
|
|
|
|
${PX_SRC}/modules/systemlib/bson/tinybson.c
|
|
|
|
)
|
2015-06-04 20:10:20 -03:00
|
|
|
target_link_libraries( param_test px4_platform )
|
|
|
|
|
2015-02-02 11:53:12 -04:00
|
|
|
add_gtest(param_test)
|
2015-06-04 20:10:20 -03:00
|
|
|
|
|
|
|
# uorb test
|
|
|
|
add_executable(uorb_tests uorb_unittests/uORBCommunicator_gtests.cpp
|
|
|
|
uorb_unittests/uORBCommunicatorMock.cpp
|
|
|
|
uorb_unittests/uORBCommunicatorMockLoopback.cpp
|
|
|
|
${PX_SRC}/modules/uORB/uORBDevices_posix.cpp
|
|
|
|
${PX_SRC}/modules/uORB/uORBManager_posix.cpp
|
|
|
|
${PX_SRC}/modules/uORB/objects_common.cpp
|
|
|
|
${PX_SRC}/modules/uORB/uORBUtils.cpp
|
|
|
|
${PX_SRC}/modules/uORB/uORB.cpp
|
|
|
|
)
|
|
|
|
target_link_libraries( uorb_tests px4_platform )
|
|
|
|
|
|
|
|
add_gtest(uorb_tests)
|