forked from nasa-jpl/jsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
131 lines (112 loc) · 3.54 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
cmake_minimum_required(VERSION 3.11)
project(jsd
DESCRIPTION "JPL SOEM Drivers"
VERSION 2.3.7
LANGUAGES C CXX
)
set(CMAKE_BUILD_TYPE Debug)
add_compile_options(
-Wall
-Wextra
-Werror
-Wno-missing-field-initializers
)
if(DISABLE_DEBUG_PRINTS)
remove_definitions(-DDEBUG)
else(DISABLE_DEBUG_PRINTS)
add_definitions(-DDEBUG)
endif(DISABLE_DEBUG_PRINTS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# for pretty printing
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(Yellow "${Esc}[33m")
set(Green "${Esc}[32m")
# install project headers to binary directory
file(GLOB_RECURSE includes RELATIVE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp
)
foreach(include ${includes})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/${include}"
"${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/${include}"
COPYONLY
)
endforeach()
####### Dependencies ########
remove_definitions(-DEC_VER1)
add_definitions(-DEC_VER2)
add_definitions(-D_GNU_SOURCE)
include(FetchContent)
# Updated 2022-09-18
FetchContent_Declare(soem
GIT_REPOSITORY https://github.com/OpenEtherCATsociety/SOEM.git
GIT_TAG 26fc5dd8e3c8981b4e8f83d736e691417bebacdb
)
FetchContent_MakeAvailable(soem)
set(SOEM_INCLUDE_DIRS
${soem_SOURCE_DIR}/soem
${soem_SOURCE_DIR}/osal
)
if(WIN32)
set(OS "win32")
elseif(UNIX AND NOT APPLE)
set(OS "linux")
elseif(APPLE)
set(OS "macosx")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel")
set(OS "rtk")
list(APPEND SOEM_INCLUDE_DIRS ${soem_SOURCE_DIR}/oshw/${OS}/${ARCH})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems")
set(OS "rtems")
endif()
list(APPEND SOEM_INCLUDE_DIRS
${soem_SOURCE_DIR}/osal/${OS}
${soem_SOURCE_DIR}/oshw/${OS}
)
add_subdirectory(src)
add_subdirectory(tools)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
enable_testing()
add_subdirectory(test)
else()
message(STATUS "Not building jsd tests when built as a submodule")
endif()
######### Install Rules #########
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_INSTALL_PREFIX /opt/jsd)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/jsd DESTINATION include)
install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION bin)
install(TARGETS jsd-lib DESTINATION lib)
install(TARGETS jsd_slaveinfo DESTINATION bin)
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/*.[ch]"
"${CMAKE_CURRENT_LIST_DIR}/tools/*.[ch]"
"${CMAKE_CURRENT_LIST_DIR}/test/*.[ch]")
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()
endif()