-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
285 lines (230 loc) · 12.2 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# min required cmake version
cmake_minimum_required(VERSION 3.24)
# Define the project name (ShipNetSim) and
# the programming language used (CXX for C++)
set(ShipNetSim_VERSION "0.0.1" CACHE STRING "Project version" FORCE)
set(SHIPNETSIM_NAME "ShipNetSim" CACHE STRING "Project name" FORCE)
set(SHIPNETSIM_VENDOR "(C) 2022-2023 Virginia Tech Transportation Institute - Center for Sustainable Mobility." CACHE STRING "Project vendor" FORCE)
# Get the current date and time
string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S")
# Set the BUILD_DATE variable
set(BUILD_DATE ${BUILD_DATE} CACHE STRING "Project build time" FORCE)
# Extract major, minor, and patch version from ShipNetSim_VERSION
string(REPLACE "." ";" VERSION_LIST ${ShipNetSim_VERSION})
list(GET VERSION_LIST 0 ShipNetSim_VERSION_MAJOR)
list(GET VERSION_LIST 1 ShipNetSim_VERSION_MINOR)
list(GET VERSION_LIST 2 ShipNetSim_VERSION_PATCH)
project(${SHIPNETSIM_NAME} VERSION ${ShipNetSim_VERSION} LANGUAGES CXX)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Compiler settings
# Set the C++20 standard to be used for compiling
set(CMAKE_CXX_STANDARD 23)
# Ensure that the selected C++ standard is a
# requirement for the compiler
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable Qt's Automatic User Interface Compiler (UIC)
set(CMAKE_AUTOUIC ON)
# Enable Qt's Meta-Object Compiler (MOC) which allows
# the use of Qt features such as signals and slots
set(CMAKE_AUTOMOC ON)
# Enable Qt's Resource Compiler (RCC) for compiling
# resource files into binary format
set(CMAKE_AUTORCC ON)
# Platform-specific compiler flags
if(MSVC)
# MSVC-specific flags
add_compile_options(/W4 /MP)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(/Od /Zi)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(/O2)
endif()
else()
# GCC/Clang-specific flags
add_compile_options(-Wall)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-O0 -g)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-O3)
endif()
endif()
# Add definitions based on build type
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()
# -------------------------------------------------------
# --------------------- OPTIONS -------------------------
# -------------------------------------------------------
# Option to build GUI components
option(BUILD_GUI "Build the GUI components" ON)
# Cache the option so it's stored between runs
set(BUILD_GUI ${BUILD_GUI} CACHE BOOL "Build the GUI components" FORCE)
# Option to build Server components
option(BUILD_SERVER "Build the SERVER components" ON)
# Cache the option so it's stored between runs
set(BUILD_SERVER ${BUILD_SERVER} CACHE BOOL "Build the SERVER components" FORCE)
option(BUILD_INSTALLER "Build the installer" ON)
set(BUILD_INSTALLER ${BUILD_INSTALLER} CACHE BOOL "Build the INSTALLER components" FORCE)
# -------------------------------------------------------
# --------------------- Libraries -----------------------
# --------------- Define Default Paths ------------------
# -------------------------------------------------------
# Allow the user to specify the Qt binary directory
set(QT_BIN_DIR "C:/Qt/6.4.2/msvc2019_64/bin" CACHE PATH "Path to the Qt binary directory")
if(BUILD_GUI)
# Manually specify paths for osgEarth, OpenSceneGraph, and osgQt
if(WIN32)
set(osgEarth_DIR "C:/Program Files/OSGEarth/cmake" CACHE PATH "Default path to osgEarth's cmake directory")
elseif(APPLE)
set(osgEarth_DIR "/usr/local/lib/cmake/osgEarth" CACHE PATH "Default path to osgEarth's cmake directory")
elseif(UNIX)
set(osgEarth_DIR "/usr/local/cmake" CACHE PATH "Default path to osgEarth's cmake directory")
endif()
if(WIN32)
set(OpenSceneGraph_DIR "C:/Program Files/OpenSceneGraph" CACHE PATH "Default path to OpenSceneGraph's directory")
elseif(APPLE)
set(OpenSceneGraph_DIR "/usr/local/lib/cmake/OpenSceneGraph" CACHE PATH "Default path to OpenSceneGraph's directory")
elseif(UNIX)
set(OpenSceneGraph_DIR "/usr/local/lib/cmake/OpenSceneGraph" CACHE PATH "Default path to OpenSceneGraph's directory")
endif()
if(WIN32)
set(OSGQT_INCLUDE_DIR "C:/Program Files/osgQt/include" CACHE PATH "Path to osgQt include directory")
elseif(APPLE)
set(OSGQT_INCLUDE_DIR "/usr/local/include/osgQOpenGL" CACHE PATH "Path to osgQt include directory")
elseif(UNIX)
set(OSGQT_INCLUDE_DIR "/usr/local/include/osgQOpenGL" CACHE PATH "Path to osgQt include directory")
endif()
if(WIN32)
set(OSGQOPENGL_LIB "C:/Program Files/osgQt/lib/osg145-osgQOpenGL.lib" CACHE PATH "Path to osgQt library")
elseif(APPLE)
set(OSGQOPENGL_LIB "/usr/local/include/osgQOpenGL" CACHE PATH "Path to osgQt library")
elseif(UNIX)
set(OSGQOPENGL_LIB "/usr/local/lib/libosgQOpenGLd.a" CACHE PATH "Path to osgQt library")
endif()
if(WIN32)
set(KDREPORTS_DIR "C:/Program Files/KDAB/KDReports/cmake" CACHE PATH "Path to KDReports CMake directory")
elseif(APPLE)
set(KDREPORTS_DIR "/usr/local/KDAB/KDReports-2.3.95/lib/cmake/KDReports-qt6" CACHE PATH "Path to KDReports CMake directory")
elseif(UNIX)
set(KDREPORTS_DIR "/usr/local/KDAB/KDReports-2.3.95/lib/cmake/KDReports-qt6" CACHE PATH "Path to KDReports CMake directory")
endif()
# Use these paths to find osgEarth and OpenSceneGraph
find_package(OpenSceneGraph REQUIRED COMPONENTS osg osgDB osgManipulator osgGA osgUtil osgViewer osgSim osgShadow CONFIG PATHS ${OpenSceneGraph_DIR})
find_package(osgEarth CONFIG REQUIRED PATHS ${osgEarth_DIR})
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib" ".so" ".dylib")
# Use the KDReports CMake package
find_package(KDReports-qt6 REQUIRED CONFIG PATHS ${KDREPORTS_DIR})
# If osgEarth is not found, manually specify the include and library paths
if(NOT osgEarth_FOUND)
set(osgEarth_INCLUDE_DIR "C:/Program Files/OSGEarth/include" CACHE PATH "Path to osgEarth include directory")
set(osgEarth_LIBRARY "C:/Program Files/OSGEarth/lib/osgEarth.lib" CACHE PATH "Path to osgEarth library")
if(NOT EXISTS ${osgEarth_INCLUDE_DIR})
message(FATAL_ERROR "osgEarth include directory not found. Please specify the correct path using osgEarth_INCLUDE_DIR.")
endif()
if(NOT EXISTS ${osgEarth_LIBRARY})
message(FATAL_ERROR "osgEarth library not found. Please specify the correct path using osgEarth_LIBRARY.")
endif()
# Set the variables manually for CMake to use
set(osgEarth_INCLUDE_DIRS ${osgEarth_INCLUDE_DIR})
set(osgEarth_LIBRARIES ${osgEarth_LIBRARY})
endif()
# Check if both osgEarth and OpenSceneGraph libraries were found
if(NOT osgEarth_FOUND AND (NOT EXISTS ${osgEarth_INCLUDE_DIR} OR NOT EXISTS ${osgEarth_LIBRARY}))
message(FATAL_ERROR "osgEarth not found and manual paths do not exist. Please specify the correct paths to the osgEarth installation.")
endif()
if(NOT OpenSceneGraph_FOUND)
message(FATAL_ERROR "OpenSceneGraph not found. Please specify the correct path to the OpenSceneGraph installation.")
endif()
# Manually specify osgQt include and library paths if needed
if(NOT EXISTS ${OSGQT_INCLUDE_DIR})
message(FATAL_ERROR "osgQt include directory not found. Please specify the correct path using OSGQT_INCLUDE_DIR.")
endif()
if(NOT EXISTS ${OSGQOPENGL_LIB})
message(FATAL_ERROR "osgQt library not found. Please specify the correct path using OSGQOPENGL_LIB.")
endif()
# Include osgQt directories
include_directories(${OSGQT_INCLUDE_DIR})
# Link osgQt library
set(OSGQT_LIBRARIES ${OSGQOPENGL_LIB})
message(STATUS "OpenSceneGraph_INCLUDE_DIRS: ${OpenSceneGraph_INCLUDE_DIRS}")
message(STATUS "OpenSceneGraph_LIBRARIES: ${OpenSceneGraph_LIBRARIES}")
endif()
if(BUILD_SERVER)
if(WIN32)
# Windows-specific paths
set(CONTAINER_CMAKE_DIR "C:/Program Files/Container/cmake" CACHE PATH "Default path to container's library")
set(RABBITMQ_CMAKE_DIR "C:/Program Files/rabbitmq-c/lib/cmake/rabbitmq-c" CACHE PATH "Default path to RabbitMQ-C library on Windows")
elseif(APPLE)
# macOS-specific paths
set(CONTAINER_CMAKE_DIR "/usr/local/cmake" CACHE PATH "Default path to container's library on macOS")
set(RABBITMQ_CMAKE_DIR "/usr/local/lib/rabbitmq-c/cmake" CACHE PATH "Default path to RabbitMQ-C library on macOS")
elseif(UNIX)
# Linux-specific paths
set(CONTAINER_CMAKE_DIR "/usr/local/cmake" CACHE PATH "Default path to container's library on Linux")
set(RABBITMQ_CMAKE_DIR "/usr/local/lib/cmake/rabbitmq-c" CACHE PATH "Default path to RabbitMQ-C library on Linux")
else()
message(FATAL_ERROR "Unsupported platform. Please set paths for CONTAINER_CMAKE_DIR and RABBITMQ_CMAKE_DIR manually.")
endif()
# Find the installed Container library
find_package(Container REQUIRED PATHS ${CONTAINER_CMAKE_DIR} NO_DEFAULT_PATH)
if (NOT Container_FOUND)
message(FATAL_ERROR "Container not found. Please specify the correct path to the Container Library cmake installation.")
endif()
if(WIN32)
# For Windows, use /bin
set(CONTAINER_SHRD_LIB_DIR "${CONTAINER_CMAKE_DIR}/../bin" CACHE PATH "Path to the Container library's bin directory")
elseif(UNIX AND NOT APPLE)
# For Linux, use /lib or /lib64 (adjust based on your setup)
set(CONTAINER_SHRD_LIB_DIR "${CONTAINER_CMAKE_DIR}/../lib" CACHE PATH "Path to the Container library's bin directory")
elseif(APPLE)
# For macOS, use /lib or /lib64 (adjust based on your setup)
set(CONTAINER_SHRD_LIB_DIR "${CONTAINER_CMAKE_DIR}/../lib" CACHE PATH "Path to the Container library's bin directory")
endif()
find_package(RabbitMQ-C REQUIRED CONFIG PATHS ${RABBITMQ_CMAKE_DIR})
if (NOT RabbitMQ-C_FOUND)
message(FATAL_ERROR "RabbitMQ-C not found. Please specify the correct path to the RabbitMQ-C cmake installation.")
endif()
# Set and cache the path to the RabbitMQ bin directory using RABBITMQ_CMAKE_DIR
if(WIN32)
# For Windows, use /bin
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../../bin" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
elseif(UNIX AND NOT APPLE)
# For Linux, use /lib or /lib64 (adjust based on your setup)
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
elseif(APPLE)
# For macOS, use /lib or /lib64 (adjust based on your setup)
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
endif()
endif()
# Library directories - Prompt users to set paths if libraries aren't found
set(GDAL_ROOT_HINTS "" CACHE STRING "Path to GDAL root directory")
set(GeographicLib_ROOT_HINTS "" CACHE STRING "Path to GeographicLib root directory")
# Allow users to override default paths
if (NOT "${GDAL_DIR}" STREQUAL "")
list(APPEND GDAL_ROOT_HINTS "${GDAL_DIR}")
endif()
if (NOT "${GeographicLib_DIR}" STREQUAL "")
list(APPEND GeographicLib_ROOT_HINTS "${GeographicLib_DIR}")
endif()
# Find packages with specified or default paths
find_package(GDAL REQUIRED HINTS ${GDAL_ROOT_HINTS})
find_package(GeographicLib REQUIRED HINTS ${GeographicLib_ROOT_HINTS})
# Error messages if libraries not found
if(NOT GDAL_FOUND)
message(FATAL_ERROR "GDAL not found. Please specify the path using GDAL_DIR.")
endif()
if(NOT GeographicLib_FOUND)
message(FATAL_ERROR "GeographicLib not found. Please specify the path using GeographicLib_DIR.")
endif()
# -------------------------------------------------------
# ---------------- RULES AND SUB PROJECTS ---------------
# -------------------------------------------------------
# include src directory
add_subdirectory(src)
# Installation rules
install(TARGETS ShipNetSim RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})