-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
174 lines (138 loc) · 5.76 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
# mahi::com CMakeLists.txt
# Evan Pezent ([email protected])
# Updated: 2/2020
cmake_minimum_required(VERSION 3.13.0)
#===============================================================================
# USER OPTIONS
#===============================================================================
# General
option(MAHI_COM_EXAMPLES "Turn ON to build example executable(s)" ON)
#===============================================================================
# FRONT MATTER
#===============================================================================
# create the project
project(mahi-com 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::com 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(com "")
add_library(mahi::com ALIAS com)
set_target_properties(com PROPERTIES DEBUG_POSTFIX -d)
target_compile_features(com PUBLIC cxx_std_11)
install(TARGETS com EXPORT mahi-com-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
set_target_properties(com PROPERTIES OUTPUT_NAME "mahi-com")
target_link_libraries(com mahi::util)
# defines
target_compile_definitions(com PUBLIC MAHI_COM) # for compatibility checks
# add source files
add_subdirectory(src/Mahi/Com)
# add include files
file(GLOB_RECURSE MAHI_COM_HEADERS "include/*.hpp" "include/*.h" "include/*.inl")
target_sources(com PRIVATE ${MAHI_COM_HEADERS}) # for intellisense
target_include_directories(com
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src # DIFFERENT THEN ADD_SUBDIRECTORY ABOVE?
)
#===============================================================================
# WINDOWS ONLY
#===============================================================================
if(WIN32)
target_compile_definitions(com
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
)
target_link_libraries(com ws2_32)
endif(WIN32)
#===============================================================================
# NI LINUX REAL-TIME ONLY
#===============================================================================
if (NI_LRT)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
target_link_libraries(com
dl # Dynamic Linking Library
rt # Realtime Extensions library
)
endif()
#===============================================================================
# EXAMPLE EXECUTABLES
#===============================================================================
if(MAHI_COM_EXAMPLES)
message("Building mahi::com examples")
add_subdirectory(examples)
endif()
#===============================================================================
# INSTALL
#===============================================================================
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_SYSTEM_PROCESSOR MATCHES ARM)
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-com)
# export the targets to a script
install(EXPORT mahi-com-targets
FILE
mahi-com-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-com-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/mahi-com-config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/mahi-com-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# install the config and configversion modules
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mahi-com-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/mahi-com-config-version.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
# export from the build tree
export(EXPORT mahi-com-targets
NAMESPACE mahi::
FILE ${CMAKE_CURRENT_BINARY_DIR}/mahi-com-targets.cmake)