-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
239 lines (193 loc) · 7.9 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
# mahi::daq CMakeLists.txt
# Evan Pezent ([email protected])
# Updated: 3/2020
cmake_minimum_required(VERSION 3.13.0)
#===============================================================================
# USER OPTIONS
#===============================================================================
# General
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(MAHI_DAQ_EXAMPLES "Turn ON to build example executable(s)" ON)
else()
option(MAHI_DAQ_EXAMPLES "Turn ON to build example executable(s)" OFF)
endif()
#===============================================================================
# FRONT MATTER
#===============================================================================
# create the project
project(mahi-daq VERSION 1.0.0 LANGUAGES C CXX)
# tell user they can't have shared version if they try
if (BUILD_SHARED_LIBS)
message(FATAL_ERROR "mahi::daq does not support shared libaries")
endif()
# add ./cmake to CMake module path so our .cmake files can be found
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(GNUInstallDirs) # defines conventional GNU isntallation directories
# Enable IDE folders and set them for predefined CMake projects
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3") # ALL WARNINGS
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # MULTICORE BUILDS
endif()
#===============================================================================
# MAHI UTIL
#===============================================================================
include(FetchContent)
FetchContent_Declare(mahi-util GIT_REPOSITORY https://github.com/mahilab/mahi-util.git)
FetchContent_MakeAvailable(mahi-util)
#===============================================================================
# CREATE LIBRARY
#===============================================================================
add_library(daq "")
add_library(mahi::daq ALIAS daq)
set_target_properties(daq PROPERTIES DEBUG_POSTFIX -d)
target_compile_features(daq PUBLIC cxx_std_11)
set_target_properties(daq PROPERTIES OUTPUT_NAME "mahi-daq")
# defines
target_compile_definitions(daq PUBLIC MAHI_DAQ) # for compatibility checks
# add source files
add_subdirectory(src/mahi/daq)
# add include files
file(GLOB_RECURSE MAHI_DAQ_HEADERS "include/*.hpp" "include/*.h" "include/*.inl")
target_sources(daq PRIVATE ${MAHI_DAQ_HEADERS}) # for intellisense
target_include_directories(daq
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# link libraries
target_link_libraries(daq PUBLIC mahi::util)
#===============================================================================
# WINDOWS ONLY
#===============================================================================
if(WIN32)
target_compile_definitions(daq
PUBLIC
-D_CRT_SECURE_NO_WARNINGS # remove secure warnings (e.g sprinft_s)
-DNOMINMAX # remove min/max macros
-D_WINSOCK_DEPRECATED_NO_WARNINGS # remove winsock deprecated warnings
)
# the following only compile under MSVC
if (MSVC)
#=======================================================================
# HIL / QUANSER
#=======================================================================
find_package(HIL)
if (HIL_FOUND)
option(MAHI_QUANSER "Turn ON to build Quanser support" ON)
else()
option(MAHI_QUANSER "Turn ON to build Quanser support" OFF)
endif()
if (MAHI_QUANSER)
add_subdirectory(src/mahi/daq/Quanser)
endif()
#=======================================================================
# SENSORAY 826
#=======================================================================
find_package(Sensoray826)
if (Sensoray826_FOUND)
option(MAHI_SENSORAY826 "Turn ON to build Sensoray 826 support" ON)
else()
option(MAHI_SENSORAY826 "Turn ON to build Sensoray 826 support" OFF)
endif()
if (MAHI_SENSORAY826)
add_subdirectory(src/mahi/daq/Sensoray)
endif()
#=======================================================================
# NI DAQMX
#=======================================================================
find_package(NIDAQmx)
if (NIDAQmx_FOUND)
option(MAHI_NIDAQMX "Turn ON to build NI DAQmx support" ON)
else()
option(MAHI_NIDAQMX "Turn ON to build NI DAQmx support" OFF)
endif()
if(MAHI_NIDAQMX)
message("mahi::daq does not yet support NI DAQmx. This option serves as placeholder for future work.")
endif()
endif(MSVC)
endif(WIN32)
#===============================================================================
# NI LINUX REAL-TIME ONLY
#===============================================================================
if (NI_LRT)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
target_link_libraries(daq
PRIVATE
dl # Dynamic Linking Library
rt # Realtime Extensions library
)
if (CMAKE_SYSTEM_PROCESSOR MATCHES ARM)
set(MAHI_MYRIO ON)
add_subdirectory(src/mahi/daq/NI/MyRio)
endif()
endif()
#===============================================================================
# EXAMPLE EXECUTABLES
#===============================================================================
if(MAHI_DAQ_EXAMPLES)
message("Building mahi::daq examples")
add_subdirectory(examples)
endif()
#===============================================================================
# INSTALL
#===============================================================================
install(TARGETS daq EXPORT mahi-daq-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (MSVC)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MAHI_INSTALL_POSTFIX "") # 64 bit Windows is default
else()
set(MAHI_INSTALL_POSTFIX "-x86")
endif()
elseif(NI_LRT AND CMAKE_SYSTEM_PROCESSOR MATCHES ARM)
set(MAHI_INSTALL_POSTFIX "-nilrt-arm")
elseif(NI_LRT AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MAHI_INSTALL_POSTFIX "-nilrt-x64")
endif()
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}${MAHI_INSTALL_POSTFIX}")
# install headers
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# set where we want to install our config
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/mahi-daq)
# export the targets to a script
install(EXPORT mahi-daq-targets
FILE
mahi-daq-targets.cmake
NAMESPACE
mahi::
DESTINATION
${INSTALL_CONFIGDIR}
)
# include helper functions for creating config files that can be included by other projects to find and use a package
include(CMakePackageConfigHelpers)
# generate a package configuration file and a package version file
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/mahi-daq-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/mahi-daq-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/mahi-daq-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# install the config and configversion modules
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mahi-daq-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/mahi-daq-config-version.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
# install find modules
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindHIL.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSensoray826.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindNIDAQmx.cmake
DESTINATION ${INSTALL_CONFIGDIR}/Modules
)
# export from the build tree
export(EXPORT mahi-daq-targets
NAMESPACE mahi::
FILE ${CMAKE_CURRENT_BINARY_DIR}/mahi-daq-targets.cmake)