-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
145 lines (123 loc) · 4.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
cmake_minimum_required (VERSION 3.11)
project(fastcat
DESCRIPTION "C++ EtherCAT Device Command & Control Library"
VERSION 0.13.0
LANGUAGES C CXX
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_BUILD_TYPE Debug)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(BUILD_TESTS "Option to build unit and device test programs" ON)
option(DISABLE_DEBUG_PRINTS "Option to disable debug prints, default off" OFF)
if(DISABLE_DEBUG_PRINTS)
remove_definitions(-DDEBUG)
else(DISABLE_DEBUG_PRINTS)
add_definitions(-DDEBUG)
endif(DISABLE_DEBUG_PRINTS)
option(ENABLE_CPPCHECK "Enable static analysis using cppcheck" OFF)
if(ENABLE_CPPCHECK)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=warning"
"--inconclusive"
"--force"
"--inline-suppr"
"--suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/.cppcheck_suppressions.txt"
)
else()
message(
WARNING
"cppcheck was not found on this system; code static analysis will not be performed")
endif()
endif()
# @TODO(kwehage,abrinkma) Clean up missing-field-initializers warnings
add_definitions(
-Werror=all
-Wall
-Wextra
-Wno-missing-field-initializers
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
file(GLOB_RECURSE includes RELATIVE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
)
foreach(include ${includes})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/${include}"
"${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/${include}"
COPYONLY
)
endforeach()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in
"${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/config.h"
)
####### Dependencies #######
find_package(YamlCpp REQUIRED 0.6.3)
include(FetchContent)
FetchContent_Declare(jsd
GIT_REPOSITORY https://github.com/nasa-jpl/jsd.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable(jsd)
####### Build #######
add_subdirectory(src)
####### Test Suite #######
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
if(BUILD_TESTS)
enable_testing()
include(CTest)
add_subdirectory(test)
else()
message(
STATUS
"Building test suite disabled, enable testing by setting BUILD_TESTS=ON"
)
endif()
else()
message(STATUS "Not building test suite when built as submodule")
endif()
####### Install ########
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/fastcat")
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/${PROJECT_NAME} DESTINATION include)
install(TARGETS fastcat DESTINATION lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindFastcat.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindYamlCpp.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake)
endif()
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
######### "doc" target #########
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_SOURCE_DIR}/.doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/.doxyfile)
add_custom_target ( doc
COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/.doxyfile"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Creating Doxygen Documentation"
VERBATIM
)
endif()
######### "format" target #########
find_program(FOUND_CLANG_FORMAT clang-format)
if(FOUND_CLANG_FORMAT)
FILE(GLOB_RECURSE C_FILES
"${CMAKE_CURRENT_LIST_DIR}/src/*.cc"
"${CMAKE_CURRENT_LIST_DIR}/src/*.c"
"${CMAKE_CURRENT_LIST_DIR}/src/*.h"
"${CMAKE_CURRENT_LIST_DIR}/test/*.cc"
"${CMAKE_CURRENT_LIST_DIR}/test/*.h")
add_custom_target( format
COMMAND clang-format -i -style=file ${C_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMENT "Formatting all .c/.h files recursively under: ${CMAKE_CURRENT_LIST_DIR}"
VERBATIM
)
endif()
else()
message(STATUS "Not building format or doc targets when built as submodule")
endif()