Skip to content

compileCmesh mutates dependency geant4 installation #2

@c-dilks

Description

@c-dilks

Consumers should never mutate dependencies unless absolutely necessary; the mutation happens here:

mlibrary/compileCmesh

Lines 22 to 39 in cf4b506

# Switch based on the OS type
case "$os_type" in
Linux)
echo "Patching ${G4INSTALL}/lib/Geant4-${G4_VERSION}/Geant4PackageCache.cmake in Linux using sed"
[[ -f "${G4INSTALL}/lib/Geant4-${G4_VERSION}/Geant4PackageCache.cmake" ]] && \
sed -i '/geant4_set_and_check_package_variable(EXPAT_LIBRARY "" "")/s/^/#/' "${G4INSTALL}/lib/Geant4-${G4_VERSION}/Geant4PackageCache.cmake"
[[ -f "${G4INSTALL}/lib64/Geant4-${G4_VERSION}/Geant4PackageCache.cmake" ]] && \
sed -i '/geant4_set_and_check_package_variable(EXPAT_LIBRARY "" "")/s/^/#/' "${G4INSTALL}/lib64/Geant4-${G4_VERSION}/Geant4PackageCache.cmake"
;;
Darwin)
echo "Patching ${G4INSTALL}/lib/Geant4-${G4_VERSION}/Geant4PackageCache.cmake in Darwin using /usr/bin/sed"
/usr/bin/sed -i '' '/geant4_set_and_check_package_variable(EXPAT_LIBRARY "" "")/s/^/#/' "${G4INSTALL}/lib/Geant4-${G4_VERSION}/Geant4PackageCache.cmake"
;;
*)
echo "Unsupported OS: $os_type"
exit 1
;;
esac

The correct approach is to patch geant4 at build time. This issue was fixed in geant4 v11.2.0, and may be backported to v10 with the following patch:

diff --git i/cmake/Modules/G4CMakeUtilities.cmake w/cmake/Modules/G4CMakeUtilities.cmake
index 511c4d9991..4d40bf0659 100644
--- i/cmake/Modules/G4CMakeUtilities.cmake
+++ w/cmake/Modules/G4CMakeUtilities.cmake
@@ -220,6 +220,24 @@ function(geant4_export_package_variables _file)
       get_property(__var_value CACHE ${__var} PROPERTY VALUE)
       get_property(__var_type CACHE ${__var} PROPERTY TYPE)
       get_property(__var_help CACHE ${__var} PROPERTY HELPSTRING)
+      ##################################################################################
+      # PATCH: backport from v11.2.0
+      ##################################################################################
+      # Variable may not be in cache, only local (canonical case being EXPAT_LIBRARY since CMake 3.27)
+      # We still need to account for these because they may be required to be in the CACHE at least set in
+      # earlier versions.
+      # 1. Variable may not be in cache, only local (canonical case being EXPAT_LIBRARY since CMake 3.27)
+      #    We still need to account for these because they may be required to be in the CACHE at least set in
+      #    earlier versions.
+      # 2. Depending on CMake version, variable may be in cache but unitialized, here we want the local value
+      if(((NOT __var_value) AND (NOT __var_type) AND (NOT __var_help)) OR (__var_type STREQUAL "UNINITIALIZED"))
+        set(__var_value ${${__var}})
+        # TODO: set type based on whether it looks like a bool or path, but PATH almost invariably what we save
+        # Only important in cmake GUI and if value needs to be changed, which we don't if package cache is used
+        set(__var_type PATH)
+        set(__var_help "no documentation, not a cache value")
+      endif()
+
       list(APPEND __local_build_setting "geant4_set_and_check_package_variable(${__var} \"${__var_value}\" ${__var_type} \"${__var_help}\")")
     endforeach()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions