Module support for G++ and Clang

I am trying to work on improving the HPX build system to support modules.

I have tried following the guide in the CMake repo. I have received the following errors.

g++: error: unrecognized command-line option ‘-fdep-file=CMakeFiles/simple.dir/a.cpp.o.ddi’
g++: error: unrecognized command-line option ‘-fdep-output=CMakeFiles/simple.dir/a.cpp.o’

The following is the CMakeLists.txt file

set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
message(STATUS "${CMAKE_CXX_COMPILER}")


cmake_minimum_required(VERSION 3.23)
project(simple CXX)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
  "${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
  "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE>"
  " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
  " ${flags_to_scan_deps}" 
  " -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT>"
  )

add_library(simple)
target_sources(simple
 PRIVATE
 FILE_SET cxx_modules TYPE CXX_MODULES FILES
 a.cpp b.cpp
)

I have faced the same issue with g++ and clang compiler.

Are you using the patches to GCC? They’ve been sent upstream, but have not yet landed.

Hi, I did try building the version suggested. Unfortunately I still receive the same errors.

/home/hhn/makes/gcc-install/usr/local/bin/g++   -std=gnu++20 -E -x c++ /home/hhn/cs/practice/modules/cxx_modules-main/std_example/t3.cxx -MT CMakeFiles/std_module_example.dir/t3.cxx.o.ddi -MD -MF CMakeFiles/std_module_example.dir/t3.cxx.o.ddi.d -fmodules-ts -fdep-file=CMakeFiles/std_module_example.dir/t3.cxx.o.ddi -fdep-output=CMakeFiles/std_module_example.dir/t3.cxx.o -fdep-format=trtbd -o CMakeFiles/std_module_example.dir/t3.cxx.o.ddi.i
g++: error: unrecognized command-line option ‘-fdep-file=CMakeFiles/std_module_example.dir/t3.cxx.o.ddi’
g++: error: unrecognized command-line option ‘-fdep-output=CMakeFiles/std_module_example.dir/t3.cxx.o’
g++: error: unrecognized command-line option ‘-fdep-format=trtbd’

That seems to not be a correct gcc… Does it work with the build in our CI image, kitware/cmake:ci-gcc_cxx_modules-x86_64-2022-06-21?

For instructions on how to build gcc and get the right version see this blog: https://www.kitware.com/import-cmake-c20-modules/

The CI image works, I might have initially messed up the various builds of GCC I had on my machine. The patches you have suggested have worked for me. Apologies.