How to install CXX_MODULES_BMI right without strange errors?

with this code

#
# module with partitions
#
add_library(mod3 SHARED)
# cmake-format: off
target_sources(
  mod3
  PRIVATE mod3/mod3price.cpp mod3/mod3io.cpp
  PUBLIC FILE_SET cxx_modules3
         TYPE CXX_MODULES
         FILES
         mod3/mod3.cppm
         mod3/mod3customer.cppm # interface partition
         mod3/mod3order.cppm # internal partition
)
# cmake-format: on
target_compile_features(mod3 PUBLIC cxx_std_20)
target_link_libraries(mod3 PUBLIC fmt::fmt)
if(CMAKE_SKIP_INSTALL_RULES AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  target_link_libraries(mod3 PUBLIC $<BUILD_INTERFACE:project_warnings project_options>)
endif()
add_executable(testmod3 mod3/testmod3.cpp)
target_link_libraries(testmod3 mod3)
add_test(NAME testmod3 COMMAND testmod3)

if(CMAKE_SKIP_INSTALL_RULES)
  return()
endif()

# cmake-format: off
install(
  TARGETS modsimple # TODO(CK) mod1 mod2
          mod3
  EXPORT mymodules
  RUNTIME # Following options apply to runtime artifacts.
          COMPONENT Runtime
  LIBRARY # Following options apply to library artifacts.
          COMPONENT Runtime #
          NAMELINK_COMPONENT Development
  ARCHIVE # Following options apply to archive artifacts.
          COMPONENT Development
          DESTINATION lib/static
  CXX_MODULES_BMI   # FIXME CXX_MODULES
          COMPONENT Development
          DESTINATION lib/bmi
  FILE_SET # Following options apply to file set HEADERS.
          HEADERS
          COMPONENT Development
)
# cmake-format: on

install(
  EXPORT mymodules
  NAMESPACE modules
  DESTINATION lib/mymodules
  CXX_MODULES_DIRECTORY lib/bmi
)

I get the following error:

CMake Error at modules/CMakeLists.txt:109 (install):
  install TARGETS target mod3 is exported but not all of its interface file
  sets are installed


-- Configuring incomplete, errors occurred!

this works, but it seems complicated to me:

#
# module with partitions
#
add_library(mod3 SHARED)
# cmake-format: off
target_sources(
  mod3
  PRIVATE mod3/mod3price.cpp mod3/mod3io.cpp
  PUBLIC FILE_SET cxx_modules3
         TYPE CXX_MODULES
         # BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/mod3
         FILES
         mod3/mod3.cppm
         mod3/mod3customer.cppm # interface partition
         mod3/mod3order.cppm # internal partition
)
# cmake-format: on
target_compile_features(mod3 PUBLIC cxx_std_20)
target_link_libraries(mod3 PUBLIC fmt::fmt)
if(CMAKE_SKIP_INSTALL_RULES AND CMAKE_BUILD_TYPE STREQUAL "Debug")
  target_link_libraries(mod3 PUBLIC $<BUILD_INTERFACE:project_warnings project_options>)
endif()
add_executable(testmod3 mod3/testmod3.cpp)
target_link_libraries(testmod3 mod3)
add_test(NAME testmod3 COMMAND testmod3)

if(CMAKE_SKIP_INSTALL_RULES)
  return()
endif()

install(TARGETS modsimple)

# cmake-format: off
install(
  TARGETS mod3 # TODO(CK): mod2 mod1
  EXPORT CXXModules
  FILE_SET cxx_modules3
          COMPONENT Development
          DESTINATION lib/cxx/miu
  CXX_MODULES_BMI
          COMPONENT Development
          DESTINATION lib/cxx/bmi
)
# cmake-format: on

install(
  EXPORT CXXModules
  NAMESPACE mymodules::
  DESTINATION lib/cmake/mod3
  FILE mod3-targets.cmake
  CXX_MODULES_DIRECTORY mod3-cxx-modules
)

file(
  WRITE "${CMAKE_CURRENT_BINARY_DIR}/mod3-config.cmake"
  "include(\"\${CMAKE_CURRENT_LIST_DIR}/mod3-targets.cmake\")
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
"
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mod3-config.cmake" DESTINATION "lib/cmake/mod3")
cmake --build --preset Release --target install
[0/1] Install the project...
-- Install configuration: "Release"
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/libfmt.10.1.0.dylib
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/libfmt.10.dylib
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/libfmt.dylib
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/args.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/chrono.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/color.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/compile.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/core.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/format.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/format-inl.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/os.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/ostream.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/printf.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/ranges.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/std.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/include/fmt/xchar.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/fmt/fmt-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/fmt/fmt-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/fmt/fmt-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/fmt/fmt-targets-release.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/pkgconfig/fmt.pc
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/bin/modsimple
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/libmod3.dylib
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: no LC_RPATH load command with path: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/build/Release/_deps/fmt-build found in: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/libmod3.dylib (for architecture x86_64), required for specified option "-delete_rpath /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/build/Release/_deps/fmt-build"
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/miu/mod3/mod3.cppm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/miu/mod3/mod3customer.cppm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/miu/mod3/mod3order.cppm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/bmi/Mod3.pcm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/bmi/Mod3-Customer.pcm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cxx/bmi/Mod3-Order.pcm
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-targets-release.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-cxx-modules/cxx-modules.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-cxx-modules/cxx-modules-Release.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-cxx-modules/target-mod3-Release.cmake
-- Installing: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/stagedir/lib/cmake/mod3/mod3-config.cmake
bash-5.2$ 

When targets with non-PRIVATE FILE_SETs are exported, the generated export files refer to these files. That is why they must be installed when the target itself is installed.

Note that BMI installation is possible, but nothing will do anything with them at the moment (reusing them is…a future endeavor that will likely need compiler assistance). I would avoid BMI installation for now.

1 Like

Thanks Ben for the heads up. Is it still the same situation now (a year-ish later)? Should BMI installation (or to be precise, reusing/depending on it) still be avoided?

See Error install cxx-module on VS 2022 - #2 by ClausKlein