<div dir="ltr">Hi there,<br><br>I'm experimenting with creating examples (& potential changes to CMake itself, if needed/useful) of building clang modules (currently using the semi-backwards compatible "header modules", with the intent of also/moving towards supporting pre-standard C++ modules in development in Clang).<br><br>The basic commands required are:<br><br>  clang++ -fmodules -xc++ -Xclang -emit-module -Xclang -fmodules-codegen -fmodule-name=foo foo.modulemap -o foo.pcm<br>  clang++ -fmodules -c -fmodule-file=foo.pcm use.cpp<br>  clang++ -c foo.pcm<br>  clang++ foo.o use.o -o a.out<br><br>My current very simplistic prototype, to build a module file, its respective module object file, and include those in the library/link for anything that depends on this library:<br><br><div><font face="monospace">  add_custom_command(</font></div><div><font face="monospace">          COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} -xc++ -c -Xclang -emit-module -fmodules -fmodule-name=Hello ${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap -o ${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm -Xclang -fmodules-codegen</font></div><div><font face="monospace">          DEPENDS module.modulemap hello.h</font></div><div><font face="monospace">          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm</font></div><div><font face="monospace">          COMMENT "Generating hello_module.pcm"</font></div><div><font face="monospace">  )</font></div><div><font face="monospace">  add_library (Hello hello.cxx ${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm)</font></div><div><font face="monospace">  target_include_directories(Hello PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})</font></div><div><font face="monospace">  target_compile_options(Hello PUBLIC -fmodules -Xclang -fmodule-file=${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm)</font><br><br>(this is based on the example in the CMake docs using Hello/Demo)<br><br>This also required one modification to CMake itself to classify a pcm file as a C++ file that needs to be compiled (to execute the 3rd line in the basic command list shown above).<br><br>But this isn't ideal - I don't /think/ I've got the dependencies quite right & things might not be rebuilding at the right times.<br>Also it involves hardcoding a bunch of things like the pcm file names, header files, etc.<br><br>Ideally, at least for a simplistic build, I wouldn't mind generating a modulemap from all the .h files (& have those headers listed in the add_library command - perhaps splitting public and private headers in some way, only including the public headers in the module file, likely). Eventually for the standards-proposal version, it's expected that there won't be any modulemap file, but maybe all headers are included in the module compilation (just pass the headers directly to the compiler).<br><br>This also doesn't start to approach the issue of how to build modules for external libraries - which I'm happy to discuss/prototype too, though interested in working to streamline the inter-library but intra-project (not inter-project) case first.<br><br>Stephen - I saw you were asking some questions about this here ( <a href="https://groups.google.com/a/isocpp.org/forum/#!topic/modules/sDIYoU8Uljw">https://groups.google.com/a/isocpp.org/forum/#!topic/modules/sDIYoU8Uljw</a> & <a href="https://github.com/steveire/ModulesExperiments">https://github.com/steveire/ModulesExperiments</a> - didn't really understand how this example applied/worked, though - I guess maybe it's a prototype syntax proposal?)<br><br>Basically: What do folks think about supporting these sort of features in CMake C++ Builds? Any pointers on how I might best implement this with or without changes to CMake?<br><br>Thanks a bunch,<br>- Dave</div></div>