Makefile: Missing CD command for text-based stubs rule for Apple
Hi,
when I'm using the Makefile generator on macOS, the rule that generates the text-based stubs for my shared library is missing a CD
command which results in the tapi
command failing because it can't find the shared library.
Makefile contents:
lib/libnag_kernel_shared.dylib: components/kernel/core/CMakeFiles/nag_kernel_shared.dir/link.txt
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --green --bold --progress-dir=/Users/simonm/git/modular-library/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Linking Fortran shared library ../../../lib/libnag_kernel_shared.dylib"
cd /Users/simonm/git/modular-library/build/components/kernel/core && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/nag_kernel_shared.dir/link.txt --verbose=$(VERBOSE)
lib/libnag_kernel_shared.tbd: lib/libnag_kernel_shared.dylib
/Library/Developer/CommandLineTools/usr/bin/tapi stubify -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk -o ../../../lib/libnag_kernel_shared.tbd ../../../lib/libnag_kernel_shared.dylib
Terminal output from make -j1 VERBOSE=1
:
[ 13%] Linking Fortran shared library ../../../lib/libnag_kernel_shared.dylib
cd /Users/simonm/git/modular-library/build/components/kernel/core && /opt/homebrew/Cellar/cmake/3.28.3/bin/cmake -E cmake_link_script CMakeFiles/nag_kernel_shared.dir/link.txt --verbose=1
/opt/homebrew/bin/gfortran-13 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk -dynamiclib -Wl,-headerpad_max_install_names -o ../../../lib/libnag_kernel_shared.dylib -install_name @rpath/libnag_kernel_shared.dylib ../getcons/CMakeFiles/nag_engine_consts.dir/modules/nag_core_consts.f90.o CMakeFiles/nag_kernel_mods.dir/modules/nag_core_data_consts.f90.o CMakeFiles/nag_kernel_mods.dir/modules/nag_core_data_type.f90.o CMakeFiles/nag_kernel_mods.dir/modules/nag_core_enum_consts.f90.o
/Library/Developer/CommandLineTools/usr/bin/tapi stubify -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk -o ../../../lib/libnag_kernel_shared.tbd ../../../lib/libnag_kernel_shared.dylib
error: no such file or directory: '../../../lib/libnag_kernel_shared.dylib'
The library exists and if I run the command manually from the correct directory, it works.
Possible solution:
In cmMakefileLibraryTargetGenerator.cxx:973
we create the command:
// Add rule to generate text-based stubs, if required
if (this->GeneratorTarget->IsApple() &&
this->GeneratorTarget->HasImportLibrary(this->GetConfigName())) {
auto genStubsRule =
this->Makefile->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
cmList genStubs_commands{ genStubsRule };
and if I add the following it works as expected:
// Add rule to generate text-based stubs, if required
if (this->GeneratorTarget->IsApple() &&
this->GeneratorTarget->HasImportLibrary(this->GetConfigName())) {
auto genStubsRule =
this->Makefile->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
cmList genStubs_commands{ genStubsRule };
this->LocalGenerator->CreateCDCommand(
genStubs_commands, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
I'm not sure if that is the correct place to add the CD command or if I'm missing something else. I'm happy to create a MR if this is an acceptable solution.
Best, Simon