generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
267 lines (233 loc) · 7.25 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.13)
project(S2E
LANGUAGES CXX
DESCRIPTION "S2E: Spacecraft Simulation Environment"
VERSION 8.0.0
)
# build config
option(USE_HILS "Use HILS" OFF)
option(USE_C2A "Use C2A" OFF)
option(USE_C2A_COMMAND_SENDER "Use command sender to C2A" OFF)
option(BUILD_64BIT "Build 64bit" OFF)
option(GOOGLE_TEST "Execute GoogleTest" OFF)
# Mac user setting
option(APPLE_SILICON "Build with Apple Silicon" OFF)
# Force build with 64bit for APPLE
if(APPLE)
option(BUILD_64BIT "Build 64bit" ON)
endif()
# preprocessor
if(WIN32)
add_definitions(-DWIN32)
endif()
## set directory path
if(NOT DEFINED EXT_LIB_DIR)
set(EXT_LIB_DIR ../ExtLibraries)
endif()
set(CSPICE_DIR ${EXT_LIB_DIR}/cspice)
set(NRLMSISE00_DIR ${EXT_LIB_DIR}/nrlmsise00)
if(NOT DEFINED FLIGHT_SW_DIR)
set(FLIGHT_SW_DIR ../FlightSW)
endif()
if(NOT DEFINED C2A_NAME)
set(C2A_NAME "c2a_oss")
endif()
## Directory path for ini files
if(NOT DEFINED SETTINGS_DIR_FROM_EXE)
set(SETTINGS_DIR_FROM_EXE ../../settings)
endif()
if(NOT DEFINED EXT_LIB_DIR_FROM_EXE)
set(EXT_LIB_DIR_FROM_EXE ../../${EXT_LIB_DIR})
endif()
if(NOT DEFINED CORE_DIR_FROM_EXE)
set(CORE_DIR_FROM_EXE ../../../s2e-core)
endif()
## options to use C2A
if(USE_C2A)
option(BUILD_64BIT OFF) # force to build with 32bit
set(C2A_DIR ${FLIGHT_SW_DIR}/${C2A_NAME})
message("C2A dir: ${C2A_DIR}")
add_definitions(-DUSE_C2A)
add_definitions(-DSILS_FW)
#include_directories
include_directories(${C2A_DIR}/src)
#add subdirectory
add_subdirectory(${C2A_DIR} C2A)
endif()
## options to use HILS
if(USE_HILS AND WIN32)
add_definitions(-DUSE_HILS)
## winsock2
SET (CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
find_library(WS2_32_LIB ws2_32.lib)
message("path for winsock2 is")
message(${WS2_32_LIB})
endif()
set(S2E_DIR ${CMAKE_CURRENT_SOURCE_DIR})
## include directories
include_directories(${CSPICE_DIR}/include)
include_directories(${NRLMSISE00_DIR}/src)
## add_subdirectories
add_subdirectory(src/simulation)
add_subdirectory(src/environment/global)
add_subdirectory(src/environment/local)
add_subdirectory(src/dynamics)
add_subdirectory(src/disturbances)
add_subdirectory(src/components)
add_subdirectory(src/math_physics)
add_subdirectory(src/setting_file_reader)
add_subdirectory(src/logger)
add_subdirectory(src/utilities)
add_subdirectory(ExtLibraries/inih)
set(SOURCE_FILES
src/s2e.cpp
src/simulation_sample/case/sample_case.cpp
src/simulation_sample/spacecraft/sample_spacecraft.cpp
src/simulation_sample/spacecraft/sample_components.cpp
src/simulation_sample/ground_station/sample_ground_station_components.cpp
src/simulation_sample/ground_station/sample_ground_station.cpp
)
## cspice library
if(APPLE)
if(APPLE_SILICON)
# APPLE Silicon
set(CSPICE_LIB_DIR ${CSPICE_DIR}/cspice_apple_silicon64/lib)
else()
# APPLE Intel
set(CSPICE_LIB_DIR ${CSPICE_DIR}/cspice_apple_intel64/lib)
endif()
elseif(CYGWIN)
SET (CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
set(CSPICE_LIB_DIR ${CSPICE_DIR}/cspice_cygwin/lib)
elseif(UNIX)
if(BUILD_64BIT)
set(CSPICE_LIB_DIR ${CSPICE_DIR}/cspice_unix64/lib)
else()
set(CSPICE_LIB_DIR ${CSPICE_DIR}/cspice_unix/lib)
endif()
endif()
if(WIN32)
SET (CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
if(BUILD_64BIT)
find_library(CSPICE_LIB
NAMES cspice.lib csupport.lib
PATHS ${CSPICE_DIR}/cspice_msvs64/lib)
else()
find_library(CSPICE_LIB
NAMES cspice.lib csupport.lib
PATHS ${CSPICE_DIR}/cspice_msvs/lib)
endif()
else()
find_library(CSPICE_LIB
NAMES cspice.a csupport.a
PATHS ${CSPICE_LIB_DIR})
endif()
if(NOT CSPICE_LIB)
message(FATAL_ERROR "cspice not found in ${CSPICE_LIB_DIR}")
endif()
#target_link_libraries(${PROJECT_NAME} ${CSPICE_LIB})
## nrlmsise00 library
if(CYGWIN)
SET (CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_library(NRLMSISE00_LIB
NAMES libnrlmsise00.a
PATHS ${NRLMSISE00_DIR}/lib)
elseif(UNIX)
if(BUILD_64BIT)
find_library(NRLMSISE00_LIB
NAMES libnrlmsise00.a
PATHS ${NRLMSISE00_DIR}/lib64)
else()
find_library(NRLMSISE00_LIB
NAMES libnrlmsise00.a
PATHS ${NRLMSISE00_DIR}/lib)
endif()
elseif(WIN32)
SET (CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
if(BUILD_64BIT)
find_library(NRLMSISE00_LIB
NAMES libnrlmsise00.lib
PATHS ${NRLMSISE00_DIR}/lib64)
else()
find_library(NRLMSISE00_LIB
NAMES libnrlmsise00.lib
PATHS ${NRLMSISE00_DIR}/lib)
endif()
endif()
if(NOT NRLMSISE00_LIB)
message(FATAL_ERROR "nrlmsise00 not found in ${EXT_LIB_DIR}")
endif()
# link hack for MSVC link.exe
add_library(lib${PROJECT_NAME}
$<TARGET_OBJECTS:LOGGER>
$<TARGET_OBJECTS:SETTING_FILE_READER>
$<TARGET_OBJECTS:INIH>
$<TARGET_OBJECTS:UTILITIES>
$<TARGET_OBJECTS:COMPONENT>
$<TARGET_OBJECTS:DISTURBANCE>
$<TARGET_OBJECTS:DYNAMICS>
$<TARGET_OBJECTS:GLOBAL_ENVIRONMENT>
$<TARGET_OBJECTS:LOCAL_ENVIRONMENT>
$<TARGET_OBJECTS:MATH_PHYSICS>
$<TARGET_OBJECTS:SIMULATION>
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME}
lib${PROJECT_NAME}
# ExtLibraries
${NRLMSISE00_LIB}
${CSPICE_LIB}
)
## C2A integration
if(USE_C2A)
target_link_libraries(${PROJECT_NAME} C2A)
endif()
## HILS
if(USE_HILS)
target_link_libraries(${PROJECT_NAME} ${WS2_32_LIB})
set_target_properties(${PROJECT_NAME} PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(COMPONENT PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(DYNAMICS PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(DISTURBANCE PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(SIMULATION PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(GLOBAL_ENVIRONMENT PROPERTIES COMMON_LANGUAGE_RUNTIME "")
set_target_properties(LOCAL_ENVIRONMENT PROPERTIES COMMON_LANGUAGE_RUNTIME "")
endif()
## GoogleTest settings
if (NOT BUILD_64BIT)
option(GOOGLE_TEST OFF) # GoogleTest supports 64bit only
endif()
if(GOOGLE_TEST)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
if(WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_MakeAvailable(googletest)
# Unit test
set(TEST_PROJECT_NAME ${PROJECT_NAME}_TEST)
# Add all test_*.cpp files as SOURCE_FILES
file(GLOB_RECURSE TEST_FILES ${CMAKE_CURRENT_LIST_DIR}/src/test_*.cpp)
# Uncomment the following line to exclude any files that match the REGEX from TEST_FILES
# list(FILTER TEST_FILES EXCLUDE REGEX ${CMAKE_CURRENT_LIST_DIR}/src/test_example.cpp)
include_directories(${TEST_PROJECT_NAME})
add_executable(${TEST_PROJECT_NAME} ${TEST_FILES})
target_link_libraries(${TEST_PROJECT_NAME} gtest gtest_main gmock)
target_link_libraries(${TEST_PROJECT_NAME} MATH_PHYSICS ${NRLMSISE00_LIB})
add_test(NAME s2e-test COMMAND ${TEST_PROJECT_NAME})
enable_testing()
# Settings
set_target_properties(${TEST_PROJECT_NAME} PROPERTIES LANGUAGE CXX)
set_target_properties(${TEST_PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
set_target_properties(${TEST_PROJECT_NAME} PROPERTIES CXX_EXTENSIONS FALSE)
target_compile_definitions(${TEST_PROJECT_NAME} PRIVATE "CORE_DIR_FROM_EXE=\"${CORE_DIR_FROM_EXE}\"")
endif()
## Cmake debug
message("Cspice_LIB: " ${CSPICE_LIB})
message("nrlmsise00_LIB: " ${NRLMSISE00_LIB})
include(common.cmake)