[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    [CMake] Experiments in CMake support for Clang (header & standard) modules
From:       David Blaikie <dblaikie () gmail ! com>
Date:       2018-04-20 0:39:32
Message-ID: CAENS6EsNOqOS-tB=7CmDtgDTFiy0jxD8X9VS3ADBc7G5P0DLcQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

[Attachment #5 (text/html)]

<div dir="ltr">Hi there,<br><br>I&#39;m experimenting with creating examples (&amp; \
potential changes to CMake itself, if needed/useful) of building clang modules \
(currently using the semi-backwards compatible &quot;header modules&quot;, 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 &quot;Generating \
hello_module.pcm&quot;</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&#39;t ideal - I don&#39;t /think/ I&#39;ve got the \
dependencies quite right &amp; 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&#39;t \
mind generating a modulemap from all the .h files (&amp; 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&#39;s expected that there won&#39;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&#39;t start to approach the \
issue of how to build modules for external libraries - which I&#39;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> \
&amp; <a href="https://github.com/steveire/ModulesExperiments">https://github.com/steveire/ModulesExperiments</a> \
- didn&#39;t really understand how this example applied/worked, though - I guess \
maybe it&#39;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>



-- 

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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic