GEOS-ESM / MAPL

MAPL is a foundation layer of the GEOS architecture, whose original purpose is to supplement the Earth System Modeling Framework (ESMF)
https://geos-esm.github.io/MAPL/
Apache License 2.0
25 stars 18 forks source link

Build MAPL without executables #1694

Closed rmontuoro closed 2 years ago

rmontuoro commented 2 years ago

A MAPL build without executables (libraries-only) is requested for deployment on operational systems at NOAA.

This could be accomplished by adding a build flag (e.g. BUILD_WITH_EXE).

Below is an example of a patch implementing the build flag above:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa272a79..b5d9fdce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,6 +117,8 @@ if (BUILD_WITH_FLAP)
   find_package(FLAP REQUIRED)
 endif ()

+option(BUILD_WITH_EXE "Build executables" ON)
+
 ecbuild_declare_project()

 if (NOT Baselibs_FOUND)
@@ -176,9 +178,11 @@ if (BUILD_WITH_FLAP)
    add_subdirectory (tutorial)
 endif()

-if (PFUNIT_FOUND)
-  include (add_pfunit_ctest)
-  add_subdirectory (pfunit EXCLUDE_FROM_ALL)
+if (BUILD_WITH_EXE)
+  if (PFUNIT_FOUND)
+    include (add_pfunit_ctest)
+    add_subdirectory (pfunit EXCLUDE_FROM_ALL)
+  endif ()
 endif ()

 # Support for automated code generation
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 216bcf16..1856729e 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -8,6 +8,7 @@ set (srcs
     VarspecDescription.F90
     )

+if (BUILD_WITH_EXE)
 if (BUILD_WITH_FLAP)

   ecbuild_add_executable (TARGET ExtDataDriver.x SOURCES ${srcs})
@@ -29,3 +30,4 @@ if (BUILD_WITH_FLAP)
   add_subdirectory(ExtData_Testing_Framework EXCLUDE_FROM_ALL)

 endif ()
+endif ()
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt
index 26ca0b22..02358930 100644
--- a/base/CMakeLists.txt
+++ b/base/CMakeLists.txt
@@ -80,13 +80,15 @@ foreach(dir ${OSX_EXTRA_LIBRARY_PATH})
   target_link_libraries(${this} PUBLIC "-Xlinker -rpath -Xlinker ${dir}")
 endforeach()

-ecbuild_add_executable (TARGET cub2latlon.x SOURCES cub2latlon_regridder.F90 DEPENDS esmf MAPL.shared)
-target_link_libraries (cub2latlon.x PRIVATE ${this} MAPL.pfio ${MPI_Fortran_LIBRARIES})
-# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
-if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
-   target_link_libraries(cub2latlon.x PRIVATE OpenMP::OpenMP_Fortran)
-endif ()
-set_target_properties(cub2latlon.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+if (BUILD_WITH_EXE)
+  ecbuild_add_executable (TARGET cub2latlon.x SOURCES cub2latlon_regridder.F90 DEPENDS esmf MAPL.shared)
+  target_link_libraries (cub2latlon.x PRIVATE ${this} MAPL.pfio ${MPI_Fortran_LIBRARIES})
+  # CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
+  if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
+     target_link_libraries(cub2latlon.x PRIVATE OpenMP::OpenMP_Fortran)
+  endif ()
+  set_target_properties(cub2latlon.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+endif()

 if (EXTENDED_SOURCE)
   esma_fortran_generator_list (${this} ${EXTENDED_SOURCE})
diff --git a/generic/CMakeLists.txt b/generic/CMakeLists.txt
index 04b34fb8..a76f9f0b 100644
--- a/generic/CMakeLists.txt
+++ b/generic/CMakeLists.txt
@@ -76,6 +76,8 @@ if (PFUNIT_FOUND)
   add_subdirectory(tests EXCLUDE_FROM_ALL)
 endif ()

+if (BUILD_WITH_EXE)
 add_executable(demo driver.F90 UserComponent.F90)
 target_link_libraries(demo PRIVATE ${this})
 set_target_properties(demo PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+endif ()
diff --git a/griddedio/CMakeLists.txt b/griddedio/CMakeLists.txt
index 44fd7a6e..4eaa2a4b 100644
--- a/griddedio/CMakeLists.txt
+++ b/griddedio/CMakeLists.txt
@@ -22,6 +22,7 @@ target_include_directories (${this} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/

 set_target_properties (${this} PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})

+if (BUILD_WITH_EXE)
 ecbuild_add_executable (TARGET Regrid_Util.x SOURCES Regrid_Util.F90 DEPENDS esmf )
 target_link_libraries (Regrid_Util.x PRIVATE ${this} MAPL.pfio ${MPI_Fortran_LIBRARIES})
 # CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
@@ -29,3 +30,4 @@ if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
            target_link_libraries(Regrid_Util.x PRIVATE OpenMP::OpenMP_Fortran)
    endif ()
    set_target_properties(Regrid_Util.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+endif()
diff --git a/pfio/CMakeLists.txt b/pfio/CMakeLists.txt
index f0e85631..bdadee4a 100644
--- a/pfio/CMakeLists.txt
+++ b/pfio/CMakeLists.txt
@@ -106,37 +106,39 @@ foreach(dir ${OSX_EXTRA_LIBRARY_PATH})
   target_link_libraries(${this} PRIVATE "-Xlinker -rpath -Xlinker ${dir}")
 endforeach()

-ecbuild_add_executable (
-   TARGET pfio_open_close.x
-   SOURCES pfio_open_close.F90
-   LIBS ${this} )
-set_target_properties (pfio_open_close.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
-
-ecbuild_add_executable (
-   TARGET pfio_server_demo.x
-   SOURCES pfio_server_demo.F90
-   LIBS ${this} MPI::MPI_Fortran)
-set_target_properties (pfio_server_demo.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
-# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
-if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
-   target_link_libraries(pfio_server_demo.x OpenMP::OpenMP_Fortran)
-endif ()
-
-ecbuild_add_executable (
-   TARGET pfio_collective_demo.x
-   SOURCES pfio_collective_demo.F90
-   LIBS ${this} MPI::MPI_Fortran)
-set_target_properties (pfio_collective_demo.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
-# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
-if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
-   target_link_libraries(pfio_collective_demo.x OpenMP::OpenMP_Fortran)
-endif ()
-
-ecbuild_add_executable (
-  TARGET pfio_writer.x
-  SOURCES pfio_writer.F90
-  LIBS ${this} NetCDF::NetCDF_Fortran NetCDF::NetCDF_C MPI::MPI_Fortran)
-set_target_properties (pfio_writer.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+if (BUILD_WITH_EXE)
+  ecbuild_add_executable (
+     TARGET pfio_open_close.x
+     SOURCES pfio_open_close.F90
+     LIBS ${this} )
+  set_target_properties (pfio_open_close.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+  
+  ecbuild_add_executable (
+     TARGET pfio_server_demo.x
+     SOURCES pfio_server_demo.F90
+     LIBS ${this} MPI::MPI_Fortran)
+  set_target_properties (pfio_server_demo.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+  # CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
+  if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
+     target_link_libraries(pfio_server_demo.x OpenMP::OpenMP_Fortran)
+  endif ()
+  
+  ecbuild_add_executable (
+     TARGET pfio_collective_demo.x
+     SOURCES pfio_collective_demo.F90
+     LIBS ${this} MPI::MPI_Fortran)
+  set_target_properties (pfio_collective_demo.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+  # CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
+  if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
+     target_link_libraries(pfio_collective_demo.x OpenMP::OpenMP_Fortran)
+  endif ()
+  
+  ecbuild_add_executable (
+    TARGET pfio_writer.x
+    SOURCES pfio_writer.F90
+    LIBS ${this} NetCDF::NetCDF_Fortran NetCDF::NetCDF_C MPI::MPI_Fortran)
+  set_target_properties (pfio_writer.x PROPERTIES Fortran_MODULE_DIRECTORY ${include_${this}})
+endif()

 #--------------------
 # Copy include files that are used by other libraries.
diff --git a/profiler/CMakeLists.txt b/profiler/CMakeLists.txt
index b3d17fce..5d96dd2b 100644
--- a/profiler/CMakeLists.txt
+++ b/profiler/CMakeLists.txt
@@ -57,7 +57,9 @@ if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
    target_link_libraries(${this} PRIVATE OpenMP::OpenMP_Fortran)
 endif ()

+if (BUILD_WITH_EXE)
 add_subdirectory (demo EXCLUDE_FROM_ALL)
 if (PFUNIT_FOUND)
   add_subdirectory (tests EXCLUDE_FROM_ALL)
 endif ()
+endif ()
mathomp4 commented 2 years ago

I might implement this as -DLIBRARY_ONLY but I'll discuss with @tclune today

mathomp4 commented 2 years ago

@rmontuoro Do you build with pFUnit usually? I'm wondering how much I need to cover.

tclune commented 2 years ago

I discussed this issue briefly with others. How does NOAA deal with other packages that produce executables? Presumably they must have a script that deletes the executables from the install dirs?

rmontuoro commented 2 years ago

@mathomp4 - We don't use pFUnit. Below are our current MAPL build flags:

      -DBUILD_WITH_FLAP=OFF \
      -DBUILD_WITH_PFLOGGER=OFF \
      -DESMA_USE_GFE_NAMESPACE=ON \
      -DBUILD_SHARED_MAPL=OFF \
      -DUSE_EXTDATA2G=OFF \
rmontuoro commented 2 years ago

@tclune - Don't know what the procedure is. Each package is examined on a case by case basis.

tclune commented 2 years ago

I think I would like to push back gently on this request. At the very least it might be more useful to refactor all of the various configuration options for NOAA into a single option. But the parallel request to eliminate the dependency on ecbuild is also leading me to push back more firmly on changes that do not align with GMAOs plans.

Since operations is presumably able to deal with binaries in other 3rd party packages, I would like to understand why such processes are not appropriate in the case of MAPL.

There is also the matter of interpretation as to what constitutes a binary. Currently our cmake package builds a number of small Fortran executables to test the capabilities of the compiler. We will not be circumventing this logic, so if the problem is "any" executable, it must be solved on NOAA's end.

tclune commented 2 years ago

This issue has now morphed into a request to remove URLs and email addresses from the source. We are ready to do this, but we need @rmontuoro to respond to these two aspects:

  1. Which version of MAPL do you want a hotfix for?
  2. Are "encoded" URLs acceptble. E.g., "my dot name at nasa dot gov"?
mathomp4 commented 2 years ago
  1. Are "encoded" URLs acceptble. E.g., "my dot name at nasa dot gov"?

As a concrete example is data@gmao.gsfc.nasa.govdata_AT_gmao_DOT_gsfc_DOT_nasa_DOT_gov and acceptable translation?

rmontuoro commented 2 years ago

Thank you for looking into our request. Here is our feedback:

  1. No need for a hotfix at this time, but it would be helpful to incorporate these changes in future releases
  2. Unfortunately, "encoding" URLs and email addresses as proposed is not acceptable.
tclune commented 2 years ago

OK - so don't tell them that I'm going to write a procedure generate_url that takes a string vector and joins the strings with "." and prefaces a "https://" in front. I'll have disguise that bit as two separate strings.

Just kidding. But the temptation is real. :-)