From 01179b17717abbc251a476fb260c59c4550d7292 Mon Sep 17 00:00:00 2001 From: Michael Klemm Date: Mon, 15 Jul 2024 10:03:49 +0200 Subject: [PATCH] Set the CACHE variable only once --- flang/runtime/CMakeLists.txt | 1 - flang/tools/f18/CMakeLists.txt | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt index dad4ca2ff0de2a..8588af7e16eeca 100644 --- a/flang/runtime/CMakeLists.txt +++ b/flang/runtime/CMakeLists.txt @@ -261,7 +261,6 @@ if (NOT DEFINED MSVC) INSTALL_WITH_TOOLCHAIN ) - target_link_libraries(FortranRuntime PRIVATE ${FORTRAN_MODULE_OBJECTS}) else() add_flang_library(FortranRuntime ${sources} diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index ea42606af30aec..862c954fa0d599 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -33,7 +33,7 @@ set(MODULES ${MODULES_WITH_IMPLEMENTATION} ${MODULES_WITHOUT_IMPLEMENTATION}) # Init variable to hold extra object files coming from the Fortran modules; # these module files will be contributed from the CMakeLists in flang/tools/f18. -unset(FORTRAN_MODULE_OBJECTS CACHE) +set(module_objects "") # Create module files directly from the top-level module source directory. # If CMAKE_CROSSCOMPILING, then the newly built flang-new executable was @@ -102,10 +102,15 @@ if (NOT CMAKE_CROSSCOMPILING) # If a module has been compiled into an object file, add the file to # the link line for the FortranRuntime library. if(include_in_link) - set(FORTRAN_MODULE_OBJECTS "${FORTRAN_MODULE_OBJECTS}" "${object_output}" CACHE INTERNAL "") + set(module_objects ${module_} ${object_output}) endif() endforeach() + # Set a CACHE variable that is visible to the CMakeLists.txt in runtime/, so that + # the compiled Fortran modules can be added to the link line of the FortranRuntime + # library. + set(FORTRAN_MODULE_OBJECTS ${module_objects} CACHE INTERNAL "") + # Special case for omp_lib.mod, because its source comes from openmp/runtime/src/include. # It also produces two module files: omp_lib.mod and omp_lib_kinds.mod. Compile these # files only if OpenMP support has been configured.