diff --git a/cmake/ecbuild_target_fortran_module_directory.cmake b/cmake/ecbuild_target_fortran_module_directory.cmake index d83986ad..726b2343 100644 --- a/cmake/ecbuild_target_fortran_module_directory.cmake +++ b/cmake/ecbuild_target_fortran_module_directory.cmake @@ -6,7 +6,7 @@ # 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 ) +function( ecbuild_target_fortran_module_directory ) set( options NO_MODULE_DIRECTORY ) set( single_value_args TARGET MODULE_DIRECTORY INSTALL_MODULE_DIRECTORY ) set( multi_value_args "" ) @@ -35,4 +35,4 @@ macro( ecbuild_target_fortran_module_directory ) endif() endif() -endmacro() +endfunction() diff --git a/cmake/project-config.cmake.in b/cmake/project-config.cmake.in index b41db6e9..229135c7 100644 --- a/cmake/project-config.cmake.in +++ b/cmake/project-config.cmake.in @@ -41,7 +41,12 @@ if(EXISTS ${@PROJECT_NAME@_CMAKE_DIR}/@CONF_IMPORT_FILE@) endif() ### insert definitions for IMPORTED targets -if(NOT @PROJECT_NAME@_BINARY_DIR) +# Guard: for install-tree exports (@PROJECT_NAME@_IS_BUILD_DIR_EXPORT=OFF) we must +# always load the targets file. For build-tree exports the targets are already +# defined by the build system, so we only skip when we are genuinely inside that +# build (i.e. the variable was set by ecbuild's own project() hook, not by an +# unrelated project that happens to share the same name). +if(NOT (@PROJECT_NAME@_IS_BUILD_DIR_EXPORT AND @PROJECT_NAME@_BINARY_DIR)) find_file(@PROJECT_NAME@_TARGETS_FILE NAMES @PROJECT_NAME@-targets.cmake HINTS @PACKAGE_TARGETS_DIRS@