forked from nasa-jpl/fastcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (104 loc) · 3.68 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
cmake_minimum_required (VERSION 3.11)
project(fastcat
DESCRIPTION "C++ EtherCAT Device Command & Control Library"
VERSION 0.4.8
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)
# @TODO(kwehage,abrinkma) Clean up missing-field-initializers warnings
add_definitions(
-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 v1.4.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 "/opt/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 /opt/cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindYamlCpp.cmake DESTINATION /opt/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()