1
- #---------------------------------------------------------------------------#
2
- # \file CMakeLists.txt
3
- #
4
- # Copyright (c) 2019 Oak Ridge National Laboratory, UT-Battelle, LLC.
5
- # Distributed under an MIT open source license: see LICENSE for details.
1
+ #---------------------------------*-CMake-*----------------------------------#
2
+ # Copyright (c) 2019-2021 Oak Ridge National Laboratory, UT-Battelle, LLC.
3
+ # License-Filename: LICENSE
4
+ # SPDX-License-Identifier: MIT
6
5
#---------------------------------------------------------------------------#
7
6
8
7
cmake_minimum_required (VERSION 3.8)
@@ -14,6 +13,9 @@ cgv_find_version(Flibcpp)
14
13
project (Flibcpp VERSION "${Flibcpp_VERSION} " LANGUAGES CXX Fortran)
15
14
cmake_policy (VERSION 3.8...3.19)
16
15
16
+ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
17
+ include (FlibUtils)
18
+
17
19
#---------------------------------------------------------------------------#
18
20
# OPTIONS
19
21
#---------------------------------------------------------------------------#
@@ -40,23 +42,8 @@ endif()
40
42
# FLAGS
41
43
#---------------------------------------------------------------------------#
42
44
43
- # Fortran standard
44
- set (FLIBCPP_FORTRAN_STD "03" CACHE STRING
45
- "Fortran standard for compiling generated code (options: 03/08/15/18/none)" )
46
- if (FLIBCPP_FORTRAN_STD AND NOT FLIBCPP_FORTRAN_STD STREQUAL "none" )
47
- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
48
- set (_FLIBCPP_STD_FLAGS "-std=f20${FLIBCPP_FORTRAN_STD} " )
49
- elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
50
- set (_FLIBCPP_STD_FLAGS "-std${FLIBCPP_FORTRAN_STD} " )
51
- else ()
52
- message (WARNING "Fortran standard flags are not known for "
53
- "compilier '${CMAKE_Fortran_COMPILER_ID} ': ignoring"
54
- "FLIBCPP_FORTRAN_STD=${FLIBCPP_FORTRAN_STD} . Configure with "
55
- "the FFLAGS environment variable or explicitly specify "
56
- "CMAKE_Fortran_FLAGS" )
57
- set (FLIBCPP_FORTRAN_STD "none" CACHE FORCE STRING "" )
58
- endif ()
59
- endif ()
45
+ # Define FLIBCPP_Fortran_STANDARD and add as Fortran compile options
46
+ flib_fortran_standard(FLIBCPP "03" )
60
47
61
48
# Build type
62
49
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
@@ -73,34 +60,8 @@ endif()
73
60
# MODULES TO LOAD
74
61
#---------------------------------------------------------------------------#
75
62
76
- list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
77
- if (CMAKE_VERSION VERSION_LESS 3.18)
78
- list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake/backport-cmake-318" )
79
- endif ()
80
-
81
- if (FLIBCPP_USE_SWIG)
82
- if (NOT SWIG_fortran_FOUND)
83
- find_package (SWIG COMPONENTS fortran REQUIRED)
84
- endif ()
85
-
86
- if (CMAKE_VERSION VERSION_LESS 3.12)
87
- message (FATAL_ERROR "CMake 3.12 or higher is required to regenerate the "
88
- "Fortran bindings using SWIG. Set FLIBCPP_USE_SWIG to OFF "
89
- "and reconfigure." )
90
- endif ()
91
-
92
- if (CMAKE_VERSION GREATER_EQUAL 3.13)
93
- cmake_policy (SET CMP0078 "NEW" )
94
- else ()
95
- set (FLIBCPP_CMP0078 "NEW" )
96
- endif ()
97
- if (CMAKE_VERSION GREATER_EQUAL 3.14)
98
- cmake_policy (SET CMP0086 "NEW" )
99
- else ()
100
- set (FLIBCPP_CMP0086 "NEW" )
101
- endif ()
102
- include (UseSWIG)
103
- endif ()
63
+ # Load SWIG if FLIBCPP_USE_SWIG is true
64
+ flib_find_and_use_swig(FLIBCPP)
104
65
105
66
# Load CTest if applicable
106
67
if (FLIBCPP_BUILD_TESTS OR FLIBCPP_BUILD_EXAMPLES)
@@ -113,60 +74,14 @@ endif()
113
74
114
75
include (GNUInstallDirs)
115
76
116
- set (CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /module" )
117
- set (FLIBCPP_INTERFACE_DIR "${CMAKE_CURRENT_SOURCE_DIR} /include" )
118
- set (FLIBCPP_GENERATE_DIR "${CMAKE_CURRENT_SOURCE_DIR} /src" )
119
- set (FLIBCPP_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR} /cmake/Flibcpp" )
120
- set (FLIBCPP_INSTALL_MODULEDIR "${CMAKE_INSTALL_INCLUDEDIR} " )
121
77
set (FLIBCPP_NAMESPACE "Flibcpp::" )
78
+ flib_dir_variables(FLIBCPP)
122
79
123
80
# List of libraries exported by cmake/FlibcppConfig.cmake.in
124
81
set (FLIBCPP_LIBRARIES)
125
82
126
83
function (flibcpp_add_module name )
127
- if (FLIBCPP_USE_SWIG)
128
- # SWIG is available; actually generate the library dynamically.
129
-
130
- set (src_file "${FLIBCPP_INTERFACE_DIR} /${name} .i" )
131
- # We're using C++
132
- set_property (SOURCE "${src_file} " PROPERTY CPLUSPLUS ON )
133
- # We need to include the source directory
134
- set_property (SOURCE "${src_file} " PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON )
135
-
136
- # Create the library
137
- swig_add_library(${name}
138
- LANGUAGE Fortran
139
- TYPE USE_BUILD_SHARED_LIBS
140
- OUTPUT_DIR "${FLIBCPP_GENERATE_DIR} "
141
- SOURCES "${src_file} " ${ARGN}
142
- )
143
-
144
- # Add SWIG headers
145
- target_include_directories (${name}
146
- PUBLIC
147
- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
148
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
149
- )
150
-
151
- # Install the interface file for downstream libraries to use
152
- install (FILES
153
- "${src_file} "
154
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
155
- )
156
-
157
- else ()
158
- # SWIG is *not* being used: compile the code committed in the repository,
159
- # generated by the developer with SWIG.
160
- add_library (${name}
161
- "${FLIBCPP_GENERATE_DIR} /${name} .f90"
162
- "${FLIBCPP_GENERATE_DIR} /${name} FORTRAN_wrap.cxx"
163
- ${ARGN}
164
- )
165
- endif ()
166
-
167
- # Allow the library to be referred to by its namespaced version, for use by
168
- # downstream projects that *directly* compile flibcpp
169
- add_library (${FLIBCPP_NAMESPACE}${name} ALIAS ${name} )
84
+ flib_add_fortran_module(FLIBCPP ${name} "cxx" "f90" ${ARGN} )
170
85
171
86
# Compile C++ code with C++11
172
87
target_compile_features (${name}
@@ -176,20 +91,9 @@ function(flibcpp_add_module name)
176
91
# Compile with e.g. std=c++11 instead of =gnu++11
177
92
set_property (TARGET ${name} PROPERTY CXX_EXTENSIONS OFF )
178
93
179
- if (_FLIBCPP_STD_FLAGS)
180
- # Compile Fortran code with a particular standard
181
- target_compile_options (${name}
182
- PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:${_FLIBCPP_STD_FLAGS} >
183
- )
184
- endif ()
185
-
186
- target_include_directories (${name}
187
- PUBLIC
188
- # Fortran modules
189
- $<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY} >
190
- $<INSTALL_INTERFACE:${FLIBCPP_INSTALL_MODULEDIR} >
191
- )
192
-
94
+ # Allow the library to be referred to by its namespaced version, for use by
95
+ # downstream projects that *directly* compile flibcpp
96
+ add_library (${FLIBCPP_NAMESPACE}${name} ALIAS ${name} )
193
97
# Set up installation
194
98
install (TARGETS
195
99
${name}
@@ -239,6 +143,9 @@ target_link_libraries(flc_vector flc flc_string)
239
143
# INSTALLATION
240
144
#---------------------------------------------------------------------------#
241
145
146
+ set (FLIBCPP_INSTALL_CONFIGDIR
147
+ "${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} " )
148
+
242
149
# Install module files
243
150
install (DIRECTORY
244
151
"${CMAKE_Fortran_MODULE_DIRECTORY} /"
0 commit comments