Skip to content

Commit 62f6c4d

Browse files
author
SidneyCogdill
committed
Take CPM into consideration for C++ modules doc
1 parent 2f27ec9 commit 62f6c4d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

docs/cpp20_modules_support.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ As of 2025-05-11, CMake lacks support for forward compatibility when consuming C
77
```cmake
88
find_package(proxy REQUIRED)
99
10-
if(NOT DEFINED proxy_INCLUDE_DIR) # [1]
11-
message(FATAL_ERROR "proxy_INCLUDE_DIR must be defined to use this script.")
10+
if(NOT DEFINED proxy_INCLUDE_DIR) # (1)
11+
if(NOT DEFINED proxy_SOURCE_DIR)
12+
message(FATAL_ERROR "proxy_INCLUDE_DIR or proxy_SOURCE_DIR must be defined to use this script.")
13+
endif()
14+
set(proxy_INCLUDE_DIR ${proxy_SOURCE_DIR}/include)
1215
endif()
1316
1417
message(STATUS "Declaring `msft_proxy::module` target for include path ${proxy_INCLUDE_DIR}")
@@ -28,11 +31,11 @@ target_sources(msft_proxy_module PUBLIC
2831
FILES
2932
${proxy_INCLUDE_DIR}/proxy/proxy.ixx
3033
)
31-
target_compile_features(msft_proxy_module PUBLIC cxx_std_20) # [2]
34+
target_compile_features(msft_proxy_module PUBLIC cxx_std_20) # (2)
3235
target_link_libraries(msft_proxy_module PUBLIC msft_proxy)
3336
```
3437

35-
- (1) `proxy_INCLUDE_DIR` is automatically declared after `find_package(proxy)`
38+
- (1) `proxy_INCLUDE_DIR` is automatically declared after `find_package(proxy)`. CPM uses a slightly different convention where `proxy_SOURCE_DIR` is declared after `CPMAddPackage`.
3639
- (2) The C++ standard version for `msft_proxy_module` target should be the same or higher than the consumer CMake target. For example if your project is using C++23 mode, this line should be changed to `cxx_std_23` or `cxx_std_26` / newer standards.
3740

3841
It can then be consumed like this:

0 commit comments

Comments
 (0)