Skip to content

Commit

Permalink
Make minor build system optimizations (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi authored Nov 12, 2024
1 parent f83e52c commit fab2c04
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 108 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ jobs:
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> ${GITHUB_ENV}
echo "FC=ifx" >> ${GITHUB_ENV}
echo "CMAKE_FC=ifx" >> ${GITHUB_ENV}
echo "MESON_FC=ifx" >> ${GITHUB_ENV}
echo "FPM_FC=ifx" >> ${GITHUB_ENV}
# Overriding default FPM_FFLAGS as default setting contains '-standard-semantics'
# which is incompatible with intel MPI.
Expand All @@ -97,14 +98,17 @@ jobs:
- name: Setup GNU environment
if: ${{ contains(matrix.compiler, 'gnu') }}
run: |
echo "FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "FPM_FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "CMAKE_FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "MESON_FC=${{ env.FC }}" >> ${GITHUB_ENV}
if [[ ${{ matrix.interface }} == serial ]] && [[ ${{ matrix.os }} == ubuntu-* ]]; then
echo "FFLAGS=-ffree-line-length-none -Og -fsanitize=address" >> ${GITHUB_ENV}
echo "LDFLAGS=-fsanitize=address" >> ${GITHUB_ENV}
echo "CMAKE_FFLAGS=-Og -fsanitize=address" >> ${GITHUB_ENV}
echo "CMAKE_LDFLAGS=-fsanitize=address" >> ${GITHUB_ENV}
echo "MESON_FFLAGS=-fsanitize=address -ffree-line-length-none" >> ${GITHUB_ENV}
echo "MESON_LDLAGS=-fsanitize=address" >> ${GITHUB_ENV}
else
echo "FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}
echo "MESON_FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}
fi
echo "FPM_FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "FPM_FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}
- name: Setup MPICH on Ubuntu
Expand All @@ -118,8 +122,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y openmpi-common openmpi-bin libopenmpi-dev
echo "FC=mpifort" >> ${GITHUB_ENV}
echo "MPI_OPTIONS=--oversubscribe" >> ${GITHUB_ENV}
echo "CMAKE_FC=mpifort" >> ${GITHUB_ENV}
echo "MPI_RUN_OPTIONS=--oversubscribe" >> ${GITHUB_ENV}
- name: Setup MPICH on MacOS
if: ${{ contains(matrix.os, 'macos') && contains(matrix.mpi, 'mpich') }}
Expand All @@ -130,7 +134,7 @@ jobs:
if: ${{ contains(matrix.os, 'macos') && contains(matrix.mpi, 'openmpi') }}
run: |
brew install openmpi
echo "MPI_OPTIONS=--oversubscribe" >> ${GITHUB_ENV}
echo "MPI_RUN_OPTIONS=--oversubscribe" >> ${GITHUB_ENV}
- name: Setup serial interface options
if: ${{ contains(matrix.interface, 'serial') }}
Expand All @@ -148,7 +152,7 @@ jobs:
echo "MESON_OPTIONS_NOFALLBACK=" >> ${GITHUB_ENV}
echo "MESON_OPTIONS_FALLBACK=-Dfortuno:with_mpi=true" >> ${GITHUB_ENV}
echo "INTERFACE=mpi" >> ${GITHUB_ENV}
echo "RUN_PREFIX=mpirun -n 2 ${MPI_OPTIONS}" >> ${GITHUB_ENV}
echo "RUN_PREFIX=mpirun -n 2 ${MPI_RUN_OPTIONS}" >> ${GITHUB_ENV}
- name: Setup coarray interface options
if: ${{ contains(matrix.interface, 'coarray') }}
Expand All @@ -167,15 +171,15 @@ jobs:
- name: Build Fortuno
run: |
cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
FC=${CMAKE_FC} FFLAGS=${CMAKE_FFLAGS} cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
cmake --build ${BUILD_DIR} --verbose
cmake --install ${BUILD_DIR} --verbose
ctest --test-dir ${BUILD_DIR} --verbose
rm -rf ${BUILD_DIR}
- name: Test CMake export
run: |
CMAKE_PREFIX_PATH=${INSTALL_DIR} cmake -B ${BUILD_DIR} -G Ninja test/export/${INTERFACE}
CMAKE_PREFIX_PATH=${INSTALL_DIR} FC=${CMAKE_FC} FFLAGS=${CMAKE_FFLAGS} cmake -B ${BUILD_DIR} -G Ninja test/export/${INTERFACE}
cmake --build ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/app/testapp
${RUN_PREFIX} ${BUILD_DIR}/app/testapp_fpp
Expand All @@ -185,7 +189,7 @@ jobs:
- name: Test fpm export
run: |
./devel/fpm-repo/export-fpm-repo.sh ${INTERFACE} ${FPM_EXPORT_DIR}
fpm run -C ${FPM_EXPORT_DIR}/test/export/${INTERFACE} --runner "${RUN_PREFIX}" testapp testapp_fpp
FPM_FC=${FPM_FC} FPM_FFLAGS=${FPM_FFLAGS} fpm run -C ${FPM_EXPORT_DIR}/test/export/${INTERFACE} --runner "${RUN_PREFIX}" testapp testapp_fpp
rm -rf ${FPM_EXPORT_DIR}
- name: Test Meson pkgconfig export
Expand All @@ -194,7 +198,7 @@ jobs:
run: |
export PKG_CONFIG_PATH="${PWD}/${INSTALL_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH}"
cd test/export/${INTERFACE}
meson setup ${MESON_OPTIONS_NOFALLBACK} --wrap-mode nofallback ${BUILD_DIR}
FC=${MESON_FC} FFLAGS=${MESON_FFLAGS} meson setup ${MESON_OPTIONS_NOFALLBACK} --wrap-mode nofallback ${BUILD_DIR}
ninja -j1 -v -C ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/testapp
${RUN_PREFIX} ${BUILD_DIR}/testapp_fpp
Expand All @@ -210,7 +214,7 @@ jobs:
mkdir subprojects
echo -e "[wrap-git]\ndirectory=fortuno\n" > subprojects/fortuno.wrap
echo -e "url=file://${FORTUNO_DIR}\nrevision=${GIT_REV}\n" >> subprojects/fortuno.wrap
meson setup ${MESON_OPTIONS_FALLBACK} --wrap-mode forcefallback ${BUILD_DIR}
FC=${MESON_FC} FFLAGS=${MESON_FFLAGS} meson setup ${MESON_OPTIONS_FALLBACK} --wrap-mode forcefallback ${BUILD_DIR}
ninja -j1 -v -C ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/testapp
${RUN_PREFIX} ${BUILD_DIR}/testapp_fpp
Expand Down
76 changes: 0 additions & 76 deletions cmake/FortunoHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,6 @@ function (fortuno_setup_build_type default_build_type)
endfunction()


# Defines the _thread_safe_build target for the thread-safe parts
function (_fortuno_create_thread_safe_build_target)

if (NOT TARGET _thread_safe_build)
add_library(_thread_safe_build INTERFACE)
target_compile_options(_thread_safe_build INTERFACE "${FORTUNO_FFLAGS_THREADSAFE}")
target_link_options(_thread_safe_build INTERFACE "${FORTUNO_LDFLAGS_THREADSAFE}")
endif ()

endfunction ()


# Applies thread safe build flags to a target
function (fortuno_add_thread_safe_build_flags target)

_fortuno_create_thread_safe_build_target()

# TODO: Delete first branch once cmake minimum version is 3.26 or above
if (CMAKE_VERSION VERSION_LESS 3.26)
get_target_property(_compile_flags _thread_safe_build INTERFACE_COMPILE_OPTIONS)
if (_compile_flags)
target_compile_options(${target} PRIVATE ${_compile_flags})
endif ()
get_target_property(_link_flags _thread_safe_build INTERFACE_LINK_OPTIONS)
if (_link_flags)
target_link_options(${target} PRIVATE ${_link_flags})
endif ()
else ()
target_link_libraries(${target} PRIVATE $<BUILD_LOCAL_INTERFACE:_thread_safe_build>)
endif ()

endfunction ()


# Preprocesses source files
#
# Args:
Expand All @@ -84,45 +50,3 @@ function (fortuno_preprocess preproc preprocopts oldext newext oldfiles newfiles
set(${newfiles} "${_newfiles}" PARENT_SCOPE)

endfunction ()


# Creates the target CoarrayBuildInterface with coarray build options
function (fortuno_create_coarray_build_target)

if (NOT TARGET CoarrayBuildInterface)
add_library(CoarrayBuildInterface INTERFACE)
target_compile_options(
CoarrayBuildInterface INTERFACE
${FORTUNO_FFLAGS_COARRAY}
)
target_link_options(
CoarrayBuildInterface INTERFACE
${FORTUNO_LDFLAGS_COARRAY}
)
endif ()

endfunction ()


# Applies coarray build flags to a target
function (fortuno_add_coarray_build_flags target)

fortuno_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)
target_compile_options(${target} PRIVATE ${_compile_flags})
endif ()
get_target_property(_link_flags CoarrayBuildInterface INTERFACE_LINK_OPTIONS)
if (_link_flags)
target_link_options(${target} PRIVATE ${_link_flags})
endif ()
else ()
target_link_libraries(${target} PRIVATE $<BUILD_LOCAL_INTERFACE:CoarrayBuildInterface>)
endif ()

endfunction ()
53 changes: 47 additions & 6 deletions config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ if (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
)
set(
FORTUNO_LDFLAGS_THREADSAFE ""
CACHE STRING "Fortuno: Flags neeeded to enforce thread-safe build during linking"
CACHE STRING "Fortuno: Flags needed to enforce thread-safe build during linking"
)
set(
FORTUNO_FFLAGS_COARRAY "-coarray"
CACHE STRING "Fortuno: Flags needed for coarray features when compling"
)
set(
FORTUNO_LDFLAGS_COARRAY "-coarray"
CACHE STRING "Fortuno: Flags neeeded for coarray features when linking"
CACHE STRING "Fortuno: Flags needed for coarray features when linking"
)
option(FORTUNO_WITH_FPP "Fortuno: whether compiler supports fpp macros" ON)
set(
FORTUNO_FFLAGS_FPP ""
CACHE STRING "Fortuno: Flags needed to process source with fpp macros"
)

elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
Expand All @@ -58,15 +63,46 @@ elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
)
set(
FORTUNO_LDFLAGS_THREADSAFE "-thread_safe"
CACHE STRING "Fortuno: Flags neeeded to enforce thread-safe build during linking"
CACHE STRING "Fortuno: Flags needed to enforce thread-safe build during linking"
)
set(
FORTUNO_FFLAGS_COARRAY "-coarray"
CACHE STRING "Fortuno: Flags needed for coarray features when compling"
)
set(
FORTUNO_LDFLAGS_COARRAY "-coarray"
CACHE STRING "Fortuno: Flags neeeded for coarray features when linking"
CACHE STRING "Fortuno: Flags needed for coarray features when linking"
)
option(FORTUNO_WITH_FPP "Fortuno: whether compiler supports fpp macros" ON)
set(
FORTUNO_FFLAGS_FPP ""
CACHE STRING "Fortuno: Flags needed to process source with fpp macros"
)

elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")

# Default settings for the GNU compiler

set(
FORTUNO_FFLAGS_THREADSAFE ""
CACHE STRING "Fortuno: Flags needed to enforce thread-safe build during compilation"
)
set(
FORTUNO_LDFLAGS_THREADSAFE ""
CACHE STRING "Fortuno: Flags needed to enforce thread-safe build during linking"
)
set(
FORTUNO_FFLAGS_COARRAY "-fcoarray=single"
CACHE STRING "Fortuno: Flags needed for coarray features when compling"
)
set(
FORTUNO_LDFLAGS_COARRAY "-fcoarray=single"
CACHE STRING "Fortuno: Flags needed for coarray features when linking"
)
option(FORTUNO_WITH_FPP "Fortuno: whether compiler supports fpp macros" ON)
set(
FORTUNO_FFLAGS_FPP "-ffree-line-length-none"
CACHE STRING "Fortuno: Flags needed to process source with fpp macros"
)

else ()
Expand All @@ -79,15 +115,20 @@ else ()
)
set(
FORTUNO_LDFLAGS_THREADSAFE ""
CACHE STRING "Fortuno: Flags neeeded to enforce thread-safe build during linking"
CACHE STRING "Fortuno: Flags needed to enforce thread-safe build during linking"
)
set(
FORTUNO_FFLAGS_COARRAY ""
CACHE STRING "Fortuno: Flags needed for coarray features when compling"
)
set(
FORTUNO_LDFLAGS_COARRAY ""
CACHE STRING "Fortuno: Flags neeeded for coarray features when linking"
CACHE STRING "Fortuno: Flags needed for coarray features when linking"
)
option(FORTUNO_WITH_FPP "Fortuno: whether compiler supports fpp macros" OFF)
set(
FORTUNO_FFLAGS_FPP ""
CACHE STRING "Fortuno: Flags needed to process source with fpp macros"
)

endif ()
12 changes: 9 additions & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ list(APPEND CMAKE_MESSAGE_CONTEXT Example)

if (FORTUNO_WITH_SERIAL)
add_subdirectory(serial)
add_subdirectory(serial-fpp)
if (FORTUNO_WITH_FPP)
add_subdirectory(serial-fpp)
endif ()
if (FYPP)
add_subdirectory(serial-fypp)
endif ()
endif ()

if (FORTUNO_WITH_MPI)
add_subdirectory(mpi)
add_subdirectory(mpi-fpp)
if (FORTUNO_WITH_FPP)
add_subdirectory(mpi-fpp)
endif ()
if (FYPP)
add_subdirectory(mpi-fypp)
endif ()
endif ()

if (FORTUNO_WITH_COARRAY)
add_subdirectory(coarray)
add_subdirectory(coarray-fpp)
if (FORTUNO_WITH_FPP)
add_subdirectory(coarray-fpp)
endif ()
if (FYPP)
add_subdirectory(coarray-fypp)
endif ()
Expand Down
7 changes: 5 additions & 2 deletions example/coarray-fpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ target_sources(
fortuno_example_coarray_fpp_mylib PRIVATE
mylib.f90
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_fpp_mylib)
target_compile_options(fortuno_example_coarray_fpp_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_fpp_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})

add_executable(fortuno_example_coarray_fpp_testapp)
set_target_properties(
Expand All @@ -25,9 +26,11 @@ target_sources(
test_simple_fpp.F90
testapp.f90
)
target_compile_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
target_link_libraries(
fortuno_example_coarray_fpp_testapp PRIVATE
fortuno_example_coarray_fpp_mylib
Fortuno::fortuno_coarray
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_fpp_testapp)
target_compile_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
6 changes: 4 additions & 2 deletions example/coarray-fypp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ target_sources(
fortuno_example_coarray_fypp_mylib PRIVATE
mylib.f90
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_fypp_mylib)
target_compile_options(fortuno_example_coarray_fypp_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_fypp_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})

add_executable(fortuno_example_coarray_fypp_testapp)
set_target_properties(
Expand Down Expand Up @@ -47,4 +48,5 @@ target_link_libraries(
PRIVATE
fortuno_example_coarray_fypp_mylib Fortuno::fortuno_coarray
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_fypp_testapp)
target_compile_options(fortuno_example_coarray_fypp_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_fypp_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
6 changes: 4 additions & 2 deletions example/coarray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ target_sources(
fortuno_example_coarray_mylib PRIVATE
mylib.f90
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_mylib)
target_compile_options(fortuno_example_coarray_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})

add_executable(fortuno_example_coarray_testapp)
set_target_properties(
Expand All @@ -29,4 +30,5 @@ target_link_libraries(
fortuno_example_coarray_testapp PRIVATE
fortuno_example_coarray_mylib Fortuno::fortuno_coarray
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_testapp)
target_compile_options(fortuno_example_coarray_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
target_link_options(fortuno_example_coarray_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
1 change: 1 addition & 0 deletions example/mpi-fpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ target_sources(
test_simple_fpp.F90
testapp.f90
)
target_compile_options(fortuno_example_mpi_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
target_link_libraries(
fortuno_example_mpi_fpp_testapp
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions example/serial-fpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_sources(
test_parametrized_fpp.F90
test_simple_fpp.F90
)
target_compile_options(fortuno_example_serial_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
target_link_libraries(
fortuno_example_serial_fpp_testapp
PRIVATE
Expand Down
Loading

0 comments on commit fab2c04

Please sign in to comment.