V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
xiaopanzi
V2EX  ›  C++

cmake 配合 clang 使用 C++ 20 module 的最佳实践

  •  
  •   xiaopanzi · Oct 14, 2023 · 2290 views
    This topic created in 929 days ago, the information mentioned may be changed or developed.

    网上看到的一些教程,比如import CMake; C++20 Modules都要使用下面的黑魔法:

    set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
    set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
    # Default to C++ extensions being off. Clang's modules support have trouble
    # with extensions right now.
    set(CMAKE_CXX_EXTENSIONS OFF)
    

    特别是第一行的 218 那堆数字,真不禁黑人问号脸。CMake 这是正常人设计出来的工具?还不如传统的 Make 直观。

    3 replies    2023-10-14 12:56:46 +08:00
    zsxzy
        1
    zsxzy  
       Oct 14, 2023
    Features are gated behind CMAKE_EXPERIMENTAL_ variables which must be set
    to specific values in order to enable their gated behaviors. Note that the
    specific values will change over time to reinforce their experimental nature.

    cmake 特意这样设计的..
    xiaopanzi
        2
    xiaopanzi  
    OP
       Oct 14, 2023
    @zsxzy 设计成类似`CMAKE_EXPERIMENTAL_CXX_MODULE ON`也好理解吧。搞那个 218 的字符串的逻辑就很反人类。
    nightwitch
        3
    nightwitch  
       Oct 14, 2023   ❤️ 1
    因为不同的 CMake 会带不同的这个值,用来标识不同版本的实现,https://github.com/Kitware/CMake/commit/48ee946fdcb8a610653e7ba42e9b8dba6942dbfb

    本身这个特性是不稳定的,CMake 也要迭代他的实现
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   885 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 19:29 · PVG 03:29 · LAX 12:29 · JFK 15:29
    ♥ Do have faith in what you're doing.