Skip to content

Commit

Permalink
Merge pull request #5 from swig-fortran/config
Browse files Browse the repository at this point in the history
CMake configuration tweaks
  • Loading branch information
sethrj authored Sep 24, 2019
2 parents 147d874 + 80a8aaf commit 16ebae5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ matrix:
- valgrind
- os: linux
env: FLIBCPP_DEV=OFF GENERATOR=make
FLIBCPP_FORTRAN_STD=f2003
FLIBCPP_FORTRAN_STD=03
GCC_VERSION=8
- os: linux
env: FLIBCPP_DEV=OFF GENERATOR=make
FLIBCPP_FORTRAN_STD=f2008
FLIBCPP_FORTRAN_STD=08
GCC_VERSION=9
# Build phases
before_install:
Expand Down
44 changes: 29 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ option(FLIBCPP_USE_SWIG "Regenerate source files using SWIG" ${FLIBCPP_DEV})
# FLAGS
#---------------------------------------------------------------------------#

# Fortran standard
set(FLIBCPP_FORTRAN_STD "03" CACHE STRING
"Fortran standard for compiling generated code (options: 03/08/15/18)")
if (FLIBCPP_FORTRAN_STD AND NOT FLIBCPP_FORTRAN_STD STREQUAL "none")
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(_FLIBCPP_STD_FLAGS "-std=f20${FLIBCPP_FORTRAN_STD}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(_FLIBCPP_STD_FLAGS "-std${FLIBCPP_FORTRAN_STD}")
else()
message(WARNING "Fortran standard flags are not known for "
"compilier '${CMAKE_Fortran_COMPILER_ID}': ignoring"
"FLIBCPP_FORTRAN_STD=${FLIBCPP_FORTRAN_STD}. Configure with "
"the FFLAGS environment variable or explicitly specify "
"CMAKE_Fortran_FLAGS")
set(_FLIBCPP_STD_FLAGS "none" CACHE FORCE STRING "")
endif()
endif()

# Build type
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if (FLIBCPP_DEV)
set(_CMAKE_BUILD_TYPE "Debug")
Expand All @@ -38,20 +57,18 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
endif()

set(FLIBCPP_FORTRAN_STD "f2003" CACHE STRING
"Fortran standard for compiling generated code")

#---------------------------------------------------------------------------#
# MODULES TO LOAD
#---------------------------------------------------------------------------#

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

if (FLIBCPP_USE_SWIG)
find_package(SWIG)
endif()

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


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

function(swig_fortran_add_module name)
function(flibcpp_add_module name)
set(src_file "${FLIBCPP_INTERFACE_DIR}/${name}.i")
# We're using C++
set_property(SOURCE "${src_file}" PROPERTY CPLUSPLUS ON)
Expand Down Expand Up @@ -165,11 +181,9 @@ function(swig_fortran_add_module name)
PRIVATE
cxx_std_11
)

if (FLIBCPP_FORTRAN_STD AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
# Compile Fortran code with given standard
if (_FLIBCPP_STD_FLAGS)
target_compile_options(${name}
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-std=${FLIBCPP_FORTRAN_STD}>
PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:${_FLIBCPP_STD_FLAGS}>
)
endif()

Expand All @@ -194,7 +208,7 @@ function(swig_fortran_add_module name)
endfunction()

# Install primary flc module, compiling version info as well
swig_fortran_add_module(flc "${FLIBCPP_VERSION_CPP}")
flibcpp_add_module(flc "${FLIBCPP_VERSION_CPP}")

# Also install 'import_flc' if using SWIG
if (FLIBCPP_USE_SWIG)
Expand All @@ -204,16 +218,16 @@ if (FLIBCPP_USE_SWIG)
)
endif()

swig_fortran_add_module(flc_algorithm)
flibcpp_add_module(flc_algorithm)
target_link_libraries(flc_algorithm flc_random flc)

swig_fortran_add_module(flc_random)
flibcpp_add_module(flc_random)
target_link_libraries(flc_random flc)

swig_fortran_add_module(flc_string)
flibcpp_add_module(flc_string)
target_link_libraries(flc_string flc)

swig_fortran_add_module(flc_vector)
flibcpp_add_module(flc_vector)
target_link_libraries(flc_vector flc flc_string)

#---------------------------------------------------------------------------#
Expand Down
2 changes: 0 additions & 2 deletions include/flc_algorithm.i
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ typedef int index_int;
// Make function pointers available as generic types
%typemap(fin) bool (*)(SWIGTYPE, SWIGTYPE)
"$1 = c_funloc($input)"
%typemap(findecl, match="fin") bool (*)(SWIGTYPE, SWIGTYPE) ""
%typemap(fout) bool (*)(CTYPE, CTYPE)
"call c_f_procpointer($1, $result)"
%typemap(foutdecl, match="fout") bool (*)(SWIGTYPE, SWIGTYPE) ""

%flc_cmp_funptr(int32_t, integer(C_INT32_T))
%flc_cmp_funptr(int64_t, integer(C_INT64_T))
Expand Down

0 comments on commit 16ebae5

Please sign in to comment.