Skip to content

Commit 16ebae5

Browse files
authored
Merge pull request #5 from swig-fortran/config
CMake configuration tweaks
2 parents 147d874 + 80a8aaf commit 16ebae5

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ matrix:
1919
- valgrind
2020
- os: linux
2121
env: FLIBCPP_DEV=OFF GENERATOR=make
22-
FLIBCPP_FORTRAN_STD=f2003
22+
FLIBCPP_FORTRAN_STD=03
2323
GCC_VERSION=8
2424
- os: linux
2525
env: FLIBCPP_DEV=OFF GENERATOR=make
26-
FLIBCPP_FORTRAN_STD=f2008
26+
FLIBCPP_FORTRAN_STD=08
2727
GCC_VERSION=9
2828
# Build phases
2929
before_install:

CMakeLists.txt

+29-15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ option(FLIBCPP_USE_SWIG "Regenerate source files using SWIG" ${FLIBCPP_DEV})
2828
# FLAGS
2929
#---------------------------------------------------------------------------#
3030

31+
# Fortran standard
32+
set(FLIBCPP_FORTRAN_STD "03" CACHE STRING
33+
"Fortran standard for compiling generated code (options: 03/08/15/18)")
34+
if (FLIBCPP_FORTRAN_STD AND NOT FLIBCPP_FORTRAN_STD STREQUAL "none")
35+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
36+
set(_FLIBCPP_STD_FLAGS "-std=f20${FLIBCPP_FORTRAN_STD}")
37+
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
38+
set(_FLIBCPP_STD_FLAGS "-std${FLIBCPP_FORTRAN_STD}")
39+
else()
40+
message(WARNING "Fortran standard flags are not known for "
41+
"compilier '${CMAKE_Fortran_COMPILER_ID}': ignoring"
42+
"FLIBCPP_FORTRAN_STD=${FLIBCPP_FORTRAN_STD}. Configure with "
43+
"the FFLAGS environment variable or explicitly specify "
44+
"CMAKE_Fortran_FLAGS")
45+
set(_FLIBCPP_STD_FLAGS "none" CACHE FORCE STRING "")
46+
endif()
47+
endif()
48+
49+
# Build type
3150
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3251
if (FLIBCPP_DEV)
3352
set(_CMAKE_BUILD_TYPE "Debug")
@@ -38,20 +57,18 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
3857
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
3958
endif()
4059

41-
set(FLIBCPP_FORTRAN_STD "f2003" CACHE STRING
42-
"Fortran standard for compiling generated code")
43-
4460
#---------------------------------------------------------------------------#
4561
# MODULES TO LOAD
4662
#---------------------------------------------------------------------------#
4763

64+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
65+
4866
if (FLIBCPP_USE_SWIG)
4967
find_package(SWIG)
5068
endif()
5169

5270
if (FLIBCPP_USE_SWIG AND SWIG_FOUND)
5371
# SWIG is requested and available; make sure it's the Fortran fork.
54-
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
5572
include(CheckSWIGFortran)
5673
if (CMAKE_VERSION VERSION_LESS 3.99)
5774
# TODO: This is until Fortran support gets added to the upstream cmake script
@@ -99,7 +116,6 @@ else()
99116
endif()
100117
endif()
101118

102-
103119
set(FLIBCPP_VERSION_CPP "${CMAKE_CURRENT_BINARY_DIR}/flibcpp_version.cpp")
104120
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/flibcpp_version.cpp.in"
105121
"${FLIBCPP_VERSION_CPP}" @ONLY)
@@ -120,7 +136,7 @@ set(FLIBCPP_NAMESPACE Flibcpp::)
120136
# List of libraries exported by cmake/FlibcppConfig.cmake.in
121137
set(FLIBCPP_LIBRARIES)
122138

123-
function(swig_fortran_add_module name)
139+
function(flibcpp_add_module name)
124140
set(src_file "${FLIBCPP_INTERFACE_DIR}/${name}.i")
125141
# We're using C++
126142
set_property(SOURCE "${src_file}" PROPERTY CPLUSPLUS ON)
@@ -165,11 +181,9 @@ function(swig_fortran_add_module name)
165181
PRIVATE
166182
cxx_std_11
167183
)
168-
169-
if (FLIBCPP_FORTRAN_STD AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
170-
# Compile Fortran code with given standard
184+
if (_FLIBCPP_STD_FLAGS)
171185
target_compile_options(${name}
172-
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-std=${FLIBCPP_FORTRAN_STD}>
186+
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:${_FLIBCPP_STD_FLAGS}>
173187
)
174188
endif()
175189

@@ -194,7 +208,7 @@ function(swig_fortran_add_module name)
194208
endfunction()
195209

196210
# Install primary flc module, compiling version info as well
197-
swig_fortran_add_module(flc "${FLIBCPP_VERSION_CPP}")
211+
flibcpp_add_module(flc "${FLIBCPP_VERSION_CPP}")
198212

199213
# Also install 'import_flc' if using SWIG
200214
if (FLIBCPP_USE_SWIG)
@@ -204,16 +218,16 @@ if (FLIBCPP_USE_SWIG)
204218
)
205219
endif()
206220

207-
swig_fortran_add_module(flc_algorithm)
221+
flibcpp_add_module(flc_algorithm)
208222
target_link_libraries(flc_algorithm flc_random flc)
209223

210-
swig_fortran_add_module(flc_random)
224+
flibcpp_add_module(flc_random)
211225
target_link_libraries(flc_random flc)
212226

213-
swig_fortran_add_module(flc_string)
227+
flibcpp_add_module(flc_string)
214228
target_link_libraries(flc_string flc)
215229

216-
swig_fortran_add_module(flc_vector)
230+
flibcpp_add_module(flc_vector)
217231
target_link_libraries(flc_vector flc flc_string)
218232

219233
#---------------------------------------------------------------------------#

include/flc_algorithm.i

-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ typedef int index_int;
9999
// Make function pointers available as generic types
100100
%typemap(fin) bool (*)(SWIGTYPE, SWIGTYPE)
101101
"$1 = c_funloc($input)"
102-
%typemap(findecl, match="fin") bool (*)(SWIGTYPE, SWIGTYPE) ""
103102
%typemap(fout) bool (*)(CTYPE, CTYPE)
104103
"call c_f_procpointer($1, $result)"
105-
%typemap(foutdecl, match="fout") bool (*)(SWIGTYPE, SWIGTYPE) ""
106104

107105
%flc_cmp_funptr(int32_t, integer(C_INT32_T))
108106
%flc_cmp_funptr(int64_t, integer(C_INT64_T))

0 commit comments

Comments
 (0)