Hi there, 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).
The basic commands required are: clang++ -fmodules -xc++ -Xclang -emit-module -Xclang -fmodules-codegen -fmodule-name=foo foo.modulemap -o foo.pcm clang++ -fmodules -c -fmodule-file=foo.pcm use.cpp clang++ -c foo.pcm clang++ foo.o use.o -o a.out 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: add_custom_command( 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 DEPENDS module.modulemap hello.h OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm COMMENT "Generating hello_module.pcm" ) add_library (Hello hello.cxx ${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm) target_include_directories(Hello PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_options(Hello PUBLIC -fmodules -Xclang -fmodule-file=${CMAKE_CURRENT_BINARY_DIR}/hello_module.pcm) (this is based on the example in the CMake docs using Hello/Demo) 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). 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. Also it involves hardcoding a bunch of things like the pcm file names, header files, etc. 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). 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. Stephen - I saw you were asking some questions about this here ( https://groups.google.com/a/isocpp.org/forum/#!topic/modules/sDIYoU8Uljw & https://github.com/steveire/ModulesExperiments - didn't really understand how this example applied/worked, though - I guess maybe it's a prototype syntax proposal?) 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? Thanks a bunch, - Dave
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake