-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
210 lines (166 loc) · 8.14 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
# +---------------------------------------------------------------------------+
# | OpenBeam - C++ Finite Element Analysis library |
# | |
# | Copyright (C) 2010-2011 Jose Luis Blanco Claraco, University of Malaga |
# | 2012-2022 Jose Luis Blanco Claraco, University of Almeria |
# | |
# | OpenBeam is free software: you can redistribute it and/or modify |
# | it under the terms of the GNU General Public License as published by |
# | the Free Software Foundation, either version 3 of the License, or |
# | (at your option) any later version. |
# | |
# | OpenBeam is distributed in the hope that it will be useful, |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# | GNU General Public License for more details. |
# | |
# | You should have received a copy of the GNU General Public License |
# | along with OpenBeam. If not, see <http://www.gnu.org/licenses/>. |
# | |
# +---------------------------------------------------------------------------+
project(OpenBeam)
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 14)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()
# Loads the current version number:
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/libopenbeam/include/openbeam/openbeam_version.h" STR_OPENBEAM_VERSION_FILE)
string(REGEX MATCH "OPENBEAM_MAJOR_VERSION[ ]+[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_MAJOR "${STR_OPENBEAM_VERSION_FILE}")
string(REGEX MATCH "[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_MAJOR "${CMAKE_OPENBEAM_VERSION_NUMBER_MAJOR}")
string(REGEX MATCH "OPENBEAM_MINOR_VERSION[ ]+[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_MINOR "${STR_OPENBEAM_VERSION_FILE}")
string(REGEX MATCH "[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_MINOR "${CMAKE_OPENBEAM_VERSION_NUMBER_MINOR}")
string(REGEX MATCH "OPENBEAM_PATCH_VERSION[ ]+[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_PATCH "${STR_OPENBEAM_VERSION_FILE}")
string(REGEX MATCH "[0-9]+" CMAKE_OPENBEAM_VERSION_NUMBER_PATCH "${CMAKE_OPENBEAM_VERSION_NUMBER_PATCH}")
set(OPENBEAM_VERSION "${CMAKE_OPENBEAM_VERSION_NUMBER_MAJOR}.${CMAKE_OPENBEAM_VERSION_NUMBER_MINOR}.${CMAKE_OPENBEAM_VERSION_NUMBER_PATCH}")
message(STATUS "Openbeam version: ${OPENBEAM_VERSION}")
# --------------------------
# Build options
# --------------------------
if (UNIX AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
set(DEFAULT_SHARED_LIBS ON)
else()
set(DEFAULT_SHARED_LIBS OFF)
endif()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
set(BUILD_SHARED_LIBS ${DEFAULT_SHARED_LIBS} CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
set(BUILD_EXAMPLES ON CACHE BOOL "Build examples?")
# Save all libs and executables in the same place
set(LIBRARY_OUTPUT_PATH ${${PROJECT_NAME}_BINARY_DIR}/lib CACHE PATH "Output directory for libraries" )
set(EXECUTABLE_OUTPUT_PATH ${${PROJECT_NAME}_BINARY_DIR}/bin CACHE PATH "Output directory for applications" )
# --------------------------
# Dependencies
# --------------------------
set(OPENBEAM_LINK_LIBS "")
# Cairo
# ----------------------------
set(OPENBEAM_HAS_CAIRO 0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OpenBeam_SOURCE_DIR})
find_package(Cairo)
# MRPT for opengl rendering:
find_package(mrpt-opengl REQUIRED)
find_package(mrpt-gui REQUIRED)
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
find_package(Threads) # Threads::Threads
find_package(Filesystem MODULE)
add_library(mrpt_libfyaml STATIC IMPORTED GLOBAL)
add_dependencies(mrpt_libfyaml mrpt_liblibfyaml)
find_library(LIBFYAML_LIB fyaml)
find_path(LIBFYAML_INCLUDES fyaml.h)
set_target_properties(mrpt_libfyaml PROPERTIES IMPORTED_LOCATION ${LIBFYAML_LIB})
set_target_properties(mrpt_libfyaml PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBFYAML_INCLUDES})
set(MRPT_STATIC_LINK_DEPS
Threads::Threads
CXX::Filesystem
mrpt_libfyaml
)
endif()
# pangommcairo
# Save vars (for some reason they are overwriten by another pkg_check_modules() call):
set(MY_CAIRO_VERSION ${Cairo_VERSION})
set(MY_CAIRO_LIBRARIES ${Cairo_LIBRARIES})
set(MY_CAIRO_INCLUDE_DIRS ${Cairo_INCLUDE_DIRS})
set(MY_CAIRO_CFLAGS ${Cairo_CFLAGS})
# "cairomm" svg lib
if(NOT WIN32)
include(FindPkgConfig)
pkg_check_modules(CAIROMM cairomm-svg-1.0)
endif()
if(CAIRO_FOUND AND CAIROMM_FOUND)
message(STATUS "cairo found: ${MY_CAIRO_VERSION}")
message(STATUS "cairomm found: ${CAIROMM_VERSION}")
if($ENV{VERBOSE})
message(STATUS " CAIRO_LIBRARIES = ${MY_CAIRO_LIBRARIES}")
message(STATUS " CAIRO_INCLUDE_DIR = ${MY_CAIRO_INCLUDE_DIRS}")
message(STATUS " CAIRO_CFLAGS = ${MY_CAIRO_CFLAGS}")
message(STATUS " CAIROMM_LIBRARIES = ${CAIROMM_LIBRARIES}")
message(STATUS " CAIROMM_INCLUDE_DIRS = ${CAIROMM_INCLUDE_DIRS}")
message(STATUS " CAIROMM_CFLAGS = ${CAIROMM_CFLAGS}")
endif()
include_directories(${MY_CAIRO_INCLUDE_DIRS})
include_directories(${CAIROMM_INCLUDE_DIRS})
add_definitions(${MY_CAIRO_CFLAGS})
add_definitions(${CAIROMM_CFLAGS})
set(OPENBEAM_LINK_LIBS ${OPENBEAM_LINK_LIBS} ${MY_CAIRO_LIBRARIES} ${CAIROMM_LIBRARIES})
set(OPENBEAM_HAS_CAIRO 1)
else()
message(STATUS " Cairo and/or cairomm were *not* found: These packages are optional, but SVG rendering will be not available.")
endif()
add_definitions(-DOPENBEAM_HAS_CAIRO=${OPENBEAM_HAS_CAIRO})
# --------------------------
# Global compiler flags
# --------------------------
include_directories("${${PROJECT_NAME}_SOURCE_DIR}/libopenbeam/include/")
include_directories("${${PROJECT_NAME}_SOURCE_DIR}/libopenbeam/internationalization/")
# Force usage of UNICODE projects, which is not the default in MSVC:
if(MSVC)
add_definitions(-DUNICODE -D_UNICODE -D_CRT_NONSTDC_NO_WARNINGS)
endif()
# Set optimized building:
if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
# --------------------------
# The library
# --------------------------
add_subdirectory(libopenbeam)
# --------------------------
# Apps
# --------------------------
add_subdirectory(apps)
# --------------------------
# Examples
# --------------------------
if(BUILD_EXAMPLES)
add_subdirectory(examples-code)
endif()
# --------------------------
# web apps:
# --------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
add_subdirectory(web-apps)
add_custom_target(web
DEPENDS web_apps_all
COMMAND ${CMAKE_COMMAND}
-DWEB_OUTPUT_DIR=${CMAKE_BINARY_DIR}/html
-DOPENBEAM_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-DOPENBEAM_BINARY_DIR=${CMAKE_BINARY_DIR}
-P ${CMAKE_SOURCE_DIR}/script_deploy_web.cmake
)
add_custom_target(web-and-serve
DEPENDS web
COMMAND python3 -m http.server 8080
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/html
)
endif()
# -------------------------------------------------------------------------------------------
# ${BIN_DIR}/OpenBeamConfig.cmake -> For use *without* "make install"
# -------------------------------------------------------------------------------------------
#TODO: Update to use modern cmake exported targets
# Set CMAKE_INCLUDE_DIRS_CONFIGCMAKE to the list of include directories:
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${CMAKE_CURRENT_SOURCE_DIR}/include\" ")
set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenBeamConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenBeamConfig.cmake" IMMEDIATE @ONLY)