Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify coarray build target logic #6

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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