wrmath/CMakeLists.txt

113 lines
3.3 KiB
CMake
Raw Normal View History

2019-08-06 17:41:26 +00:00
if (DEFINED ENV{CMAKE_GCOV})
2019-08-05 05:22:27 +00:00
cmake_minimum_required(VERSION 3.15)
2019-08-06 17:41:26 +00:00
else()
cmake_minimum_required(VERSION 3.10)
endif()
2019-08-03 02:03:44 +00:00
cmake_policy(SET CMP0048 NEW)
## CONFIG
project(wrmath VERSION 0.0.1 LANGUAGES CXX)
2019-08-03 02:03:44 +00:00
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2019-08-08 03:51:22 +00:00
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
2019-08-03 02:03:44 +00:00
2019-08-06 01:03:30 +00:00
# Don't warn on unused functions, because this is a library and not all
# functions might be used.
add_compile_options(-Werror -Wno-unused-function -Wall -g -O0)
2019-08-03 02:03:44 +00:00
2019-08-06 17:41:26 +00:00
if (DEFINED ENV{CMAKE_GCOV})
2019-08-03 02:03:44 +00:00
add_compile_options(-fprofile-arcs -ftest-coverage)
# Need CMake 3.15+.
add_link_options(-fprofile-arcs -ftest-coverage)
2019-08-05 05:44:06 +00:00
add_custom_target(coverage COMMAND lcov -d . -t wrmath -o wrmath.info -c -i
2019-08-06 01:03:30 +00:00
COMMAND lcov -d . -t wrmath -o wrmath.info -c
COMMAND lcov -d . -t wrmath -o wrmath.info -r wrmath.info *gtest*
COMMAND genhtml -o coverage-report wrmath.info)
message(STATUS, "Code coverage enabled.")
2019-08-03 02:03:44 +00:00
endif()
include_directories(include)
file(GLOB_RECURSE ${PROJECT_NAME}_HEADERS include/**.h)
file(GLOB_RECURSE ${PROJECT_NAME}_SOURCES src/*.cc)
2019-08-03 02:03:44 +00:00
2019-08-06 05:50:28 +00:00
2019-08-03 02:03:44 +00:00
## BUILD
2019-08-06 07:46:02 +00:00
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})
2019-08-08 03:51:22 +00:00
2019-08-06 07:46:02 +00:00
add_executable(euler2quat tools/euler2quat.cc)
target_link_libraries(euler2quat ${PROJECT_NAME})
2019-08-07 05:49:20 +00:00
set_target_properties(euler2quat PROPERTIES
FOLDER bin
RUNTIME_OUTPUT_DIRECTORY bin)
2019-08-08 03:51:22 +00:00
2019-08-07 05:49:20 +00:00
add_executable(quaternion tools/quaternion.cc)
target_link_libraries(quaternion ${PROJECT_NAME})
set_target_properties(quaternion PROPERTIES
2019-08-06 07:46:02 +00:00
FOLDER bin
RUNTIME_OUTPUT_DIRECTORY bin)
2019-08-03 02:03:44 +00:00
## INSTALL
2019-08-08 03:51:22 +00:00
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(TARGETS euler2quat DESTINATION bin)
install(TARGETS quaternion DESTINATION bin)
2019-08-03 02:03:44 +00:00
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION include/
FILES_MATCHING PATTERN "*.h")
2019-08-08 03:51:22 +00:00
install(DIRECTORY docs/sphinx/_build/html/
DESTINATION share/doc/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.html")
2019-08-03 02:03:44 +00:00
## TEST
# From Modern CMake:
# https://cliutils.gitlab.io/modern-cmake/chapters/testing/googletest.html
2019-08-08 03:51:22 +00:00
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/googletest" "extern/googletest" EXCLUDE_FROM_ALL)
include_directories("${gtest_SOURCE_DIR}/include")
mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)
set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)
set_target_properties(gmock PROPERTIES FOLDER extern)
set_target_properties(gmock_main PROPERTIES FOLDER extern)
2019-08-03 02:03:44 +00:00
include(CTest)
set(TEST_EXECS)
macro(package_add_gtest TESTNAME)
add_executable(${TESTNAME} ${ARGN})
2019-08-06 07:46:02 +00:00
target_link_libraries(${TESTNAME} gtest_main ${PROJECT_NAME})
2019-08-03 02:03:44 +00:00
target_compile_options(${TESTNAME} PUBLIC ${GTEST_CFLAGS})
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
set_target_properties(${TESTNAME} PROPERTIES
FOLDER tests
RUNTIME_OUTPUT_DIRECTORY tests)
list(APPEND TEST_EXECS ${TESTNAME})
endmacro()
# define the tests
2019-08-05 07:12:03 +00:00
package_add_gtest(vector_test test/vector_test.cc)
package_add_gtest(orientation_test test/orientation_test.cc)
package_add_gtest(quaternion_test test/quaternion_test.cc)
2019-08-07 05:49:20 +00:00
package_add_gtest(madgwick_test test/madgwick_test.cc)
2019-08-03 02:03:44 +00:00
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose DEPENDS ${TEST_EXECS})
## DEPLOY
include(CMakePack.txt)
## DOCUMENTATE
add_subdirectory ("docs")