Skip to content

Commit

Permalink
Simplify coarray build target logic (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed May 19, 2024
1 parent 0f25712 commit d89af07
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions {{ cookiecutter.project_slug }}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ set(
{% if cookiecutter.parallelization == "coarray" -%}
set(
{{cookiecutter.__project_slug_upper}}_COARRAY_COMPILE_FLAGS
""
"-coarray"
CACHE STRING
"{{cookiecutter.project_name}}: Extra flags to use for compiling coarray source files"
)
set(
{{cookiecutter.__project_slug_upper}}_COARRAY_LINK_FLAGS
""
"-coarray"
CACHE STRING
"{{cookiecutter.project_name}}: Extra flags to use for linking coarray object files"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,32 @@ endfunction ()


{% if cookiecutter.__coarray_code == "True" -%}
# Applies coarray build flags to the target
function ({{cookiecutter.project_slug}}_add_coarray_build_flags target)
# Creates the target CoarrayBuildInterface with coarray build options
function ({{cookiecutter.project_slug}}_create_coarray_build_target)

if (NOT TARGET CoarrayBuildInterface)
if ({{cookiecutter.__project_slug_upper}}_COARRAY_COMPILE_FLAGS)
set(_coarray_compile_flags "${{'{'}}{{cookiecutter.__project_slug_upper}}_coarray_compile_flags}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_coarray_compile_flags "-coarray")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
set(_coarray_compile_flags "-coarray")
endif ()

if ({{cookiecutter.__project_slug_upper}}_COARRAY_LINK_FLAGS)
set(_coarray_link_flags "${{'{'}}{{cookiecutter.__project_slug_upper}}_COARRAY_LINK_FLAGS}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_coarray_link_flags "-coarray")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
set(_coarray_link_flags "-coarray")
endif ()

add_library(CoarrayBuildInterface INTERFACE)
target_compile_options(CoarrayBuildInterface INTERFACE ${_coarray_compile_flags})
target_link_options(CoarrayBuildInterface INTERFACE ${_coarray_link_flags})
target_compile_options(
CoarrayBuildInterface INTERFACE
${{'{'}}{{cookiecutter.__project_slug_upper}}_COARRAY_COMPILE_FLAGS}
)
target_link_options(
CoarrayBuildInterface INTERFACE
${{'{'}}{{cookiecutter.__project_slug_upper}}_COARRAY_LINK_FLAGS}
)
endif ()

endfunction ()


# Applies coarray build flags to a target
function ({{cookiecutter.project_slug}}_add_coarray_build_flags target)

{{cookiecutter.project_slug}}_create_coarray_build_target()

# TODO: Delete first branch once cmake minimum version is 3.26 or above
# Older CMake versions have problems during installation if the CoarrayBuildInterface target is
# linked directly with any target, therefore applying a workaround.
if (CMAKE_VERSION VERSION_LESS 3.26)
get_target_property(_compile_flags CoarrayBuildInterface INTERFACE_COMPILE_OPTIONS)
if (_compile_flags)
Expand Down

0 comments on commit d89af07

Please sign in to comment.