8
8
cmake_minimum_required (VERSION 3.8 )
9
9
project (Flibcpp VERSION 0.1.0 LANGUAGES CXX Fortran )
10
10
11
+ #---------------------------------------------------------------------------#
12
+ # OPTIONS
13
+ #---------------------------------------------------------------------------#
14
+
15
+ if (NOT DEFINED (FLIBCPP_DEV ))
16
+ set (FLIBCPP_DEV OFF CACHE STRING
17
+ "Default to using development-centered options" )
18
+ endif ()
19
+
20
+ if (NOT DEFINED (CMAKER_BUILD_SHARED ))
21
+ set (FLIBCPP_DEV OFF CACHE STRING
22
+ "Default to using development-centered options" )
23
+ endif ()
24
+
25
+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
26
+ if (FLIBCPP_DEV )
27
+ set (_CMAKE_BUILD_TYPE "Debug" )
28
+ else ()
29
+ set (_CMAKE_BUILD_TYPE "RelWithDebInfo" )
30
+ endif ()
31
+ message (STATUS "No build type selected, default to ${_CMAKE_BUILD_TYPE} " )
32
+ set (CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE} " CACHE STRING "Build type" FORCE )
33
+ endif ()
34
+
35
+ option (BUILD_SHARED_LIBS "Build shared libraries" ON )
36
+
11
37
#---------------------------------------------------------------------------#
12
38
# SWIG setup
13
39
#---------------------------------------------------------------------------#
14
40
15
- option (USE_SWIG "Enable SWIG generation" OFF )
16
- if (USE_SWIG )
41
+ option (FLIBCPP_USE_SWIG "Enable SWIG generation" ${FLIBCPP_DEV} )
42
+ if (FLIBCPP_USE_SWIG )
17
43
find_package (SWIG )
18
44
endif ()
19
45
20
- if (USE_SWIG AND SWIG_FOUND )
46
+ if (FLIBCPP_USE_SWIG AND SWIG_FOUND )
21
47
# SWIG is requested and available; make sure it's the Fortran fork.
22
48
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
23
49
include (CheckSWIGFortran )
@@ -30,18 +56,27 @@ if (USE_SWIG AND SWIG_FOUND)
30
56
include (UseSWIG )
31
57
endif ()
32
58
else ()
33
- set (USE_SWIG FALSE )
59
+ set (FLIBCPP_USE_SWIG FALSE )
34
60
endif ()
35
61
62
+ #---------------------------------------------------------------------------#
63
+ # GIT
64
+ #---------------------------------------------------------------------------#
65
+
66
+ set (FLIBCPP_VERSION_CPP "${CMAKE_CURRENT_BINARY_DIR} /flibcpp_version.cpp" )
67
+ configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /cmake/flibcpp_version.cpp.in"
68
+ "${FLIBCPP_VERSION_CPP} " @ONLY )
69
+
36
70
#---------------------------------------------------------------------------#
37
71
# LIBRARY
38
72
#---------------------------------------------------------------------------#
73
+
39
74
include (GNUInstallDirs )
40
75
41
- set (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /module )
42
- set (FLIBCPP_GENERATE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/generated )
43
- set (FLIBCPP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR} /cmake/Flibcpp )
44
- set (FLIBCPP_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR} )
76
+ set (CMAKE_Fortran_MODULE_DIRECTORY " ${CMAKE_CURRENT_BINARY_DIR} /module" )
77
+ set (FLIBCPP_GENERATE_DIR " ${CMAKE_CURRENT_SOURCE_DIR} /src/generated" )
78
+ set (FLIBCPP_INSTALL_CONFIGDIR " ${CMAKE_INSTALL_LIBDIR} /cmake/Flibcpp" )
79
+ set (FLIBCPP_INSTALL_MODULEDIR " ${CMAKE_INSTALL_INCLUDEDIR} " )
45
80
set (FLIBCPP_NAMESPACE Flibcpp:: )
46
81
47
82
set (FLIBCPP_LIBRARIES )
@@ -53,7 +88,9 @@ function(swig_fortran_add_module name)
53
88
set_property (SOURCE src/${name}.i
54
89
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON )
55
90
56
- if (USE_SWIG )
91
+ message (STATUS "Extra sources for ${name} : ${ARGN} " )
92
+
93
+ if (FLIBCPP_USE_SWIG )
57
94
# SWIG is available; actually generate the library dynamically.
58
95
# Create the library
59
96
swig_add_library (${name}
@@ -98,7 +135,7 @@ function(swig_fortran_add_module name)
98
135
endfunction ()
99
136
100
137
# Four SWIG libraries
101
- swig_fortran_add_module (flc )
138
+ swig_fortran_add_module (flc " ${FLIBCPP_VERSION_CPP} " )
102
139
swig_fortran_add_module (flc_random )
103
140
target_link_libraries (flc_random flc )
104
141
swig_fortran_add_module (flc_algorithm )
@@ -144,21 +181,27 @@ install(
144
181
# TESTING
145
182
#---------------------------------------------------------------------------#
146
183
147
- enable_testing ()
148
- add_subdirectory (test )
184
+ option (FLIBCPP_BUILD_TESTS "Build unit tests" ${FLIBCPP_DEV} )
185
+ if (FLIBCPP_BUILD_TESTS )
186
+ enable_testing ()
187
+ add_subdirectory (test )
188
+ endif ()
149
189
150
190
#---------------------------------------------------------------------------#
151
191
# EXECUTABLES
152
192
#---------------------------------------------------------------------------#
153
193
154
- add_subdirectory (example )
194
+ option (FLIBCPP_BUILD_EXAMPLES "Build examples" ON )
195
+ if (FLIBCPP_BUILD_EXAMPLES )
196
+ add_subdirectory (example )
197
+ endif ()
155
198
156
199
#---------------------------------------------------------------------------#
157
200
# DOCUMENTATION
158
201
#---------------------------------------------------------------------------#
159
202
160
- option (ENABLE_DOC "Build documentation" OFF )
161
- if (ENABLE_DOC )
203
+ option (FLIBCPP_BUILD_DOCS "Build documentation" ${FLIBCPP_DEV} )
204
+ if (FLIBCPP_BUILD_DOCS )
162
205
add_subdirectory (doc )
163
206
endif ()
164
207
0 commit comments