Skip to content

Commit

Permalink
Merge pull request #55 from ecmwf/feature/fortran
Browse files Browse the repository at this point in the history
Feature/fortran
  • Loading branch information
tlmquintino committed Jun 5, 2023
2 parents 2db8697 + 1c99789 commit a5502ea
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmake/ecbuild_generate_fortran_interfaces.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,25 @@

function( ecbuild_generate_fortran_interfaces )

find_program( FCM_EXECUTABLE fcm REQUIRED DOC "Fortran interface generator" )
find_program( FCM_EXECUTABLE fcm DOC "Fortran interface generator"
HINTS
${CMAKE_SOURCE_DIR}/fcm
${CMAKE_BINARY_DIR}/fcm
${fcm_ROOT}
ENV fcm_ROOT
PATH_SUFFIXES bin )
if (NOT FCM_EXECUTABLE)
include(FetchContent)
set(ECBUILD_FCM_VERSION "2019.09.0" CACHE STRING "FCM version used to generate Fortran interfaces")
FetchContent_Populate(
fcm
URL "https://github.com/metomi/fcm/archive/refs/tags/${ECBUILD_FCM_VERSION}.tar.gz"
SOURCE_DIR ${CMAKE_BINARY_DIR}/fcm
BINARY_DIR ${CMAKE_BINARY_DIR}/_deps/fcm-build
SUBBUILD_DIR ${CMAKE_BINARY_DIR}/_deps/fcm-subbuild
)
set( FCM_EXECUTABLE ${CMAKE_BINARY_DIR}/fcm/bin/fcm )
endif()

if( NOT FCM_EXECUTABLE )
ecbuild_error( "ecbuild_generate_fortran_interfaces: fcm executable not found." )
Expand Down
1 change: 1 addition & 0 deletions cmake/ecbuild_system.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ if( NOT ECBUILD_SYSTEM_INITIALISED )
include( ecbuild_enable_fortran )
include( ecbuild_source_flags )
include( ecbuild_target_flags )
include( ecbuild_target_fortran_module_directory )
include( ecbuild_pkgconfig )
include( ecbuild_cache )
include( ecbuild_remove_fortran_flags )
Expand Down
38 changes: 38 additions & 0 deletions cmake/ecbuild_target_fortran_module_directory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# (C) Copyright 2022- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

macro( ecbuild_target_fortran_module_directory )
set( options NO_MODULE_DIRECTORY )
set( single_value_args TARGET MODULE_DIRECTORY INSTALL_MODULE_DIRECTORY )
set( multi_value_args "" )
cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} )

if( NOT _PAR_TARGET )
ecbuild_critical( "Missing argument TARGET" )
endif()

if( _PAR_NO_MODULE_DIRECTORY )
set_target_properties( ${_PAR_TARGET} PROPERTIES Fortran_MODULE_DIRECTORY "" )
else()
if( NOT _PAR_MODULE_DIRECTORY )
ecbuild_critical( "Missing argument MODULE_DIRECTORY" )
endif()
set_target_properties( ${_PAR_TARGET} PROPERTIES Fortran_MODULE_DIRECTORY ${_PAR_MODULE_DIRECTORY} )
target_include_directories( ${_PAR_TARGET} PUBLIC $<BUILD_INTERFACE:${_PAR_MODULE_DIRECTORY}> )
endif()

if( ECBUILD_INSTALL_FORTRAN_MODULES )
if( _PAR_INSTALL_MODULE_DIRECTORY )
target_include_directories( ${_PAR_TARGET} PUBLIC $<INSTALL_INTERFACE:${_PAR_INSTALL_MODULE_DIRECTORY}> )
install( DIRECTORY ${_PAR_MODULE_DIRECTORY}/
DESTINATION ${_PAR_INSTALL_MODULE_DIRECTORY}
COMPONENT modules )
endif()
endif()

endmacro()

0 comments on commit a5502ea

Please sign in to comment.