2020-07-14 07:02:35 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
|
|
|
project(ctestapp VERSION 0.1.0) # TODO: replace the name `cpptestapp` at every occurrence in this file!
|
|
|
|
|
|
|
|
# # Only do these if this is the main project, and not if it is included through add_subdirectory
|
|
|
|
# if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|
|
|
# include(CTest)
|
|
|
|
# endif()
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
|
|
|
|
# configure clang-tidy
|
|
|
|
set(CLANG_TIDY_HEADER_FILTER "src/")
|
|
|
|
set(CLANG_TIDY_CHECKS "-*,bugprone-*,cert-*,modernize-*,-modernize-use-trailing-return-type,readability-*,performance-*,llvm-*,-llvm-header-guard,google-*,-google-readability-todo,cppcoreguidelines-*,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes")
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
# run clang-tidy on Release builds, disable with `set_target_properties(lib_foobar PROPERTIES CXX_CLANG_TIDY "")`
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
set(CMAKE_CXX_CLANG_TIDY
|
|
|
|
clang-tidy;
|
|
|
|
-header-filter=${CLANG_TIDY_HEADER_FILTER};
|
|
|
|
-checks=${CLANG_TIDY_CHECKS};
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
## CONFIGURE LIBRARIES
|
|
|
|
|
|
|
|
# # example for a header only library: https://github.com/nlohmann/json
|
|
|
|
# add_library(lib_json INTERFACE)
|
|
|
|
# target_include_directories(lib_json INTERFACE ${PROJECT_SOURCE_DIR}/thirdparty/nlohmann_json)
|
|
|
|
|
|
|
|
# # example for a compiled only library: https://github.com/emilk/loguru
|
|
|
|
# find_package(Threads)
|
|
|
|
# add_library(lib_loguru STATIC
|
|
|
|
# ${PROJECT_SOURCE_DIR}/thirdparty/loguru/loguru.cpp
|
|
|
|
# ${PROJECT_SOURCE_DIR}/thirdparty/loguru/loguru.hpp
|
|
|
|
# )
|
|
|
|
# target_include_directories(lib_loguru PUBLIC ${PROJECT_SOURCE_DIR}/thirdparty/loguru)
|
|
|
|
# target_link_libraries(lib_loguru PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) # add libraries required by loguru
|
|
|
|
# set_target_properties(lib_loguru PROPERTIES CXX_CLANG_TIDY "") # do not run clang-tidy here
|
|
|
|
|
|
|
|
|
|
|
|
## CONFIGURE MAIN EXECUTABLE
|
|
|
|
|
|
|
|
# add our own files
|
|
|
|
set(SOURCES
|
|
|
|
${PROJECT_SOURCE_DIR}/src/main.cpp
|
|
|
|
# add additional sources here
|
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(ctestapp ${SOURCES})
|
|
|
|
|
|
|
|
# add libraries
|
2020-11-05 13:08:15 +00:00
|
|
|
# target_link_libraries(ctestapp PRIVATE lib_json)
|
|
|
|
# target_link_libraries(ctestapp PRIVATE lib_loguru)
|
2020-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
# define which compile target should be installed with `make install`
|
|
|
|
install(TARGETS ctestapp
|
|
|
|
RUNTIME DESTINATION bin)
|
|
|
|
|
|
|
|
|
|
|
|
## CONFIGURE TESTS
|
|
|
|
|
|
|
|
# # Testing only available if this is the main app
|
|
|
|
# if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) AND BUILD_TESTING)
|
|
|
|
# if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
# set(CMAKE_CXX_CLANG_TIDY "") # do not run clang-tidy for the tests
|
|
|
|
# endif()
|
|
|
|
# add_subdirectory(test)
|
|
|
|
# endif()
|
|
|
|
|
|
|
|
|
|
|
|
## CONFIGURE ADDITIONAL DEVELOPMENT TARGETS
|
|
|
|
|
|
|
|
# add a manual clang-tidy make target (run with `make tidy`)
|
|
|
|
# Caveat: This only works well, when all sources are added to the SOURCES variable.
|
|
|
|
# If your project is separated into multiple (internal) libraries, use the integrated
|
|
|
|
# clang-tidy runner of CMake, which is already enabled on Release builds.
|
|
|
|
find_program(CLANG_TIDY "clang-tidy")
|
|
|
|
if(CLANG_TIDY)
|
|
|
|
# get include directories and convert them to compiler flags (prepend "-I")
|
|
|
|
get_property(TIDY_INCLUDE_DIRS TARGET ctestapp PROPERTY INCLUDE_DIRECTORIES)
|
|
|
|
foreach(X IN ITEMS ${TIDY_INCLUDE_DIRS})
|
|
|
|
list(APPEND TIDY_INCLUDE_DIRS_ARG "-I${X}")
|
|
|
|
endforeach()
|
2020-11-05 13:08:15 +00:00
|
|
|
|
2020-07-14 07:02:35 +00:00
|
|
|
# add a Make target named "tidy" (to run clang-tidy manually)
|
|
|
|
add_custom_target(tidy
|
|
|
|
COMMAND ${CLANG_TIDY}
|
|
|
|
-header-filter=${CLANG_TIDY_HEADER_FILTER}
|
|
|
|
-checks=${CLANG_TIDY_CHECKS}
|
|
|
|
-p=${PROJECT_BINARY_DIR}
|
|
|
|
${SOURCES}
|
|
|
|
--
|
|
|
|
${TIDY_INCLUDE_DIRS_ARG}
|
|
|
|
)
|
|
|
|
endif()
|