So I’m running Geant4 10.6 and 10.7 on an older MacBook Pro. At some point, Mac decided to remove the /usr/include directory; I’m not sure where it went. Since then, I’ve had problems with using CMake to build applications with the find_package(Geant4 ...) directive. When I try to build against 10.6 it complains:
CMake Error in library/CMakeLists.txt:
Imported target "Geant4::G4Tree" includes non-existent path
"/usr/include"
in its INTERFACE_INCLUDE_DIRECTORIES.
I believe I’ve isolated this to my long ago use of GEANT4_USE_SYSTEM_EXPAT=ON for 10.6, which appears to have triggered the setting EXPAT_INCLUDE_DIR=/usr/include (back when /usr/include existed).
I’m running into other problems when I try to rebuild 10.06.p03 now with that changed (which I won’t go into here). In the mean time, does anyone know where the EXPAT .h files might have been put on an old Mac?
And also (probably a question for @bmorgan ) what I could manually edit in my existing 10.06.p03 install area to change this so that find_package(Geant4) doesn’t get hung up?
What version on macOS were you running before/now (or rather, which Xcode)? I’m not totally sure, but most of the system headers now tend to appear under the SDK folders, like /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/expat.h and/or /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/expat.h
There are two places the paths might show up, in the files next to Geant4Config.cmake:
Geant4LibraryDepends*.cmake
Geant4PackageCache.cmake
There might be a mix between the two, but Geant4PackageCache.cmake is the likely culprit here. At least for system packages like EXPAT/Zlib, you can probably safely remove any lines relating to those, though it’s possible you might get link/runtime errors if the new libs are binary incompatible with the old if we’re talking massive differences in macOS version.
Longer story - skip what follows if you’re not interested in the gory details:
We’ve tried to move fully to using CMake’s target mechanism for transporting “usage requirements” like include paths, libraries. Geant4Config.cmake and CMake’s find_package/find_dependency are then responsible for re-finding needed packages as part of find_package(Geant4 ...). Over time, this has meant that Geant4LibraryDepends*.cmake has contained fewer (and now no) hard-coded paths, but left a dilemma on making things “just work” which the hard-coded paths allowed. That’s where the Geant4PackageCache.cmake file comes in. It caches these paths and uses them in preference to CMAKE_PREFIX_PATH, largely reproducing the hard-coded path behaviour.
Geant4 can be installed with or without Geant4PackageCache.cmake, which covers two use cases:
With: Simple installs that just work on a single machine
Without: Package Manager/Production installs that are fully relocatable. I.e. you can create a package, or mount a remote FS, and wherever it is unpacked/mounted, it will just work - providedCMAKE_PREFIX_PATH is set up appropriately to contain paths to the needed dependencies.
Thank you for the suggestions, Ben! And for the gory details (which might help me when I have to make my own CMake support). I’ll try what you’ve suggested, and flag “Solution” if it works.
I’ve kept my machine stuck on end-of-life 10.14.6, because that’s the last version compatible with my “March 2012 MacBook Pro.” It’s running XCode 10.1.
Thank you again, Ben! I found expat.h exactly where you recommended, /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include. I modified Geant4PackageCache.cmake, and modified the relevant line to read:
geant4_set_and_check_package_variable(EXPAT_INCLUDE_DIR "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" PATH "Path to a file.")
Now I get a new error from CMake in my application build directory:
CMake Warning at /Applications/GEANT4/geant4.10.06.p03/lib/Geant4-10.6.3/Geant4PackageCache.cmake:9 (message):
Value of 'EXPAT_INCLUDE_DIR' is already set and does not match value set at
Geant4 build-time
Call Stack (most recent call first):
/Applications/GEANT4/geant4.10.06.p03/lib/Geant4-10.6.3/Geant4PackageCache.cmake:18 (geant4_set_and_check_package_variable)
/Applications/GEANT4/geant4.10.06.p03/lib/Geant4-10.6.3/Geant4Config.cmake:241 (include)
FindGeant4.cmake:22 (find_package)
CMakeLists.txt:14 (include)
I don’t understand this, since there’s no where else I could find in the Geant4 *.cmake files where either EXPAT_INCLUDE_DIRS is set, or even where the string “/usr/include” shows up!
Having said that, following the above complaint I still get the previous error:
CMake Error in library/CMakeLists.txt:
Imported target "Geant4::G4Tree" includes non-existent path
"/usr/include"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
I’ll continue to chase this, but I wanted to update you with where I am so far.
Found it! My application’s own CMakeCache.txt had picked up the EXPAT_INCLUDE_DIR setting of /usr/include from Geant4 and stashed it in three places. I edited that file and ran cmake . in my build directory, and it succeeded. I was then able to run make install as usual.