Skip to content

Commit cf6c633

Browse files
SidneyCogdillSidneyCogdill
and
SidneyCogdill
authored
make package name matches namespace name (#307)
Co-authored-by: SidneyCogdill <no@localhost>
1 parent 33fb7aa commit cf6c633

11 files changed

+66
-68
lines changed

CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
cmake_minimum_required(VERSION 3.28)
22

3-
project(msft_proxy4 VERSION 3.3.0 LANGUAGES CXX)
3+
project(msft_proxy4 VERSION 4.0.0 LANGUAGES CXX)
44
add_library(msft_proxy4 INTERFACE)
5-
set_target_properties(msft_proxy4 PROPERTIES EXPORT_NAME proxy4)
6-
add_library(msft_proxy::proxy4 ALIAS msft_proxy4)
5+
set_target_properties(msft_proxy4 PROPERTIES EXPORT_NAME proxy)
6+
add_library(msft_proxy4::proxy ALIAS msft_proxy4)
77

88
# Do not enable building tests if proxy is consumed as
99
# subdirectory (e.g. by CMake FetchContent_Declare).
@@ -42,53 +42,53 @@ target_include_directories(msft_proxy4 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRE
4242

4343
# Do not set the module target if proxy is consumed as a subdirectory.
4444
if(PROJECT_IS_TOP_LEVEL)
45-
set(proxy4_INCLUDE_DIR include)
45+
set(msft_proxy4_INCLUDE_DIR include)
4646
if(PROXY_BUILD_MODULES)
47-
include(cmake/proxy4ModuleTargets.cmake)
47+
include(cmake/msft_proxy4ModuleTargets.cmake)
4848
endif()
4949
else()
5050
# Propagate the variable to the parent project
51-
set(proxy4_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
51+
set(msft_proxy4_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
5252
endif()
5353

5454
# install and export the project. project name - proxy
5555

5656
include(GNUInstallDirs)
5757

5858
install(TARGETS msft_proxy4
59-
EXPORT proxy4Targets
59+
EXPORT msft_proxy4Targets
6060
FILE_SET public_headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
6161
)
6262

6363
install(
64-
EXPORT proxy4Targets
65-
NAMESPACE msft_proxy::
66-
DESTINATION ${CMAKE_INSTALL_DATADIR}/proxy
64+
EXPORT msft_proxy4Targets
65+
NAMESPACE msft_proxy4::
66+
DESTINATION ${CMAKE_INSTALL_DATADIR}/msft_proxy4
6767
)
6868
export(
6969
TARGETS msft_proxy4
70-
NAMESPACE msft_proxy::
71-
FILE proxy4Targets.cmake
70+
NAMESPACE msft_proxy4::
71+
FILE msft_proxy4Targets.cmake
7272
)
7373

7474
include(CMakePackageConfigHelpers)
7575
configure_package_config_file(
76-
cmake/proxy4Config.cmake.in
77-
${CMAKE_CURRENT_BINARY_DIR}/cmake/proxy4Config.cmake
78-
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/proxy
76+
cmake/msft_proxy4Config.cmake.in
77+
${CMAKE_CURRENT_BINARY_DIR}/cmake/msft_proxy4Config.cmake
78+
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/msft_proxy4
7979
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
8080
)
8181

8282
include(CMakePackageConfigHelpers)
83-
write_basic_package_version_file(cmake/proxy4ConfigVersion.cmake
83+
write_basic_package_version_file(cmake/msft_proxy4ConfigVersion.cmake
8484
COMPATIBILITY SameMajorVersion
8585
ARCH_INDEPENDENT)
8686

8787
install(
8888
FILES
89-
${CMAKE_CURRENT_BINARY_DIR}/cmake/proxy4Config.cmake
90-
${CMAKE_CURRENT_BINARY_DIR}/cmake/proxy4ConfigVersion.cmake
91-
DESTINATION ${CMAKE_INSTALL_DATADIR}/proxy
89+
${CMAKE_CURRENT_BINARY_DIR}/cmake/msft_proxy4Config.cmake
90+
${CMAKE_CURRENT_BINARY_DIR}/cmake/msft_proxy4ConfigVersion.cmake
91+
DESTINATION ${CMAKE_INSTALL_DATADIR}/msft_proxy4
9292
)
9393

9494
# build tests if BUILD_TESTING is ON

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ Please refer to the [Proxy's Frequently Asked Questions](https://microsoft.githu
3535

3636
```cmake
3737
CPMAddPackage(
38-
NAME proxy4
38+
NAME msft_proxy4
3939
GIT_TAG 4.0.0 # or above
4040
GIT_REPOSITORY https://github.com/microsoft/proxy.git
4141
)
4242
43-
target_link_libraries(main PRIVATE msft_proxy::proxy4)
43+
target_link_libraries(main PRIVATE msft_proxy4::proxy)
4444
```
4545
4646
### Hello World

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_executable(msft_proxy_benchmarks
2222
proxy_management_benchmark.cpp
2323
)
2424
target_include_directories(msft_proxy_benchmarks PRIVATE .)
25-
target_link_libraries(msft_proxy_benchmarks PRIVATE msft_proxy::proxy4 benchmark::benchmark benchmark::benchmark_main)
25+
target_link_libraries(msft_proxy_benchmarks PRIVATE msft_proxy4::proxy benchmark::benchmark benchmark::benchmark_main)
2626

2727
if (MSVC)
2828
target_compile_options(msft_proxy_benchmarks PRIVATE /W4)

cmake/msft_proxy4Config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/msft_proxy4Targets.cmake")
4+
5+
set(msft_proxy4_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

cmake/msft_proxy4ModuleTargets.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if(NOT DEFINED msft_proxy4_INCLUDE_DIR)
2+
message(FATAL_ERROR "`msft_proxy4_INCLUDE_DIR` must be defined to use this script.")
3+
endif()
4+
5+
message(STATUS "Declaring `msft_proxy4::proxy_module` target for include path `${msft_proxy4_INCLUDE_DIR}`")
6+
7+
add_library(msft_proxy4_module)
8+
set_target_properties(
9+
msft_proxy4_module
10+
PROPERTIES
11+
SYSTEM TRUE
12+
EXCLUDE_FROM_ALL TRUE
13+
)
14+
15+
add_library(msft_proxy4::proxy_module ALIAS msft_proxy4_module)
16+
target_sources(msft_proxy4_module PUBLIC
17+
FILE_SET CXX_MODULES
18+
BASE_DIRS ${msft_proxy4_INCLUDE_DIR}
19+
FILES
20+
${msft_proxy4_INCLUDE_DIR}/proxy/v4/proxy.ixx
21+
)
22+
target_compile_features(msft_proxy4_module PUBLIC cxx_std_20)
23+
target_link_libraries(msft_proxy4_module PUBLIC msft_proxy4::proxy)

cmake/proxy4Config.cmake.in

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmake/proxy4ModuleTargets.cmake

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set_source_files_properties(${EXAMPLE_SOURCES} PROPERTIES GENERATED TRUE)
1717
foreach(SOURCE ${EXAMPLE_SOURCES})
1818
get_filename_component(EXECUTABLE_NAME ${SOURCE} NAME_WE)
1919
add_executable(${EXECUTABLE_NAME} ${SOURCE})
20-
target_link_libraries(${EXECUTABLE_NAME} PRIVATE msft_proxy::proxy4)
20+
target_link_libraries(${EXECUTABLE_NAME} PRIVATE msft_proxy4::proxy)
2121
if (MSVC)
2222
target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4)
2323
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

docs/cpp20_modules_support.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ The "Proxy" library ships with `.ixx` files starting with version **4.0.0**. Com
55
As of 2025-05-11, CMake lacks support for forward compatibility when consuming C++ modules, which causes consumers with newer C++ standard to be unable to use modules with older standard. Until this is implemented by CMake, a CMake target containing the module can be manually declared using the following CMake script:
66

77
```cmake
8-
find_package(proxy4 REQUIRED)
8+
find_package(msft_proxy4 REQUIRED)
99
10-
if(NOT DEFINED proxy4_INCLUDE_DIR) # (1)
11-
if(NOT DEFINED proxy_SOURCE_DIR)
12-
message(FATAL_ERROR "proxy4_INCLUDE_DIR or proxy_SOURCE_DIR must be defined to use this script.")
10+
if(NOT DEFINED msft_proxy4_INCLUDE_DIR) # (1)
11+
if(NOT DEFINED msft_proxy4_SOURCE_DIR)
12+
message(FATAL_ERROR "`msft_proxy4_INCLUDE_DIR` or `msft_proxy4_SOURCE_DIR` must be defined to use this script.")
1313
endif()
14-
set(proxy4_INCLUDE_DIR ${proxy_SOURCE_DIR}/include)
14+
set(msft_proxy4_INCLUDE_DIR ${msft_proxy4_SOURCE_DIR}/include)
1515
endif()
1616
17-
message(STATUS "Declaring `msft_proxy::proxy4_module` target for include path ${proxy4_INCLUDE_DIR}")
17+
message(STATUS "Declaring `msft_proxy4::proxy_module` target for include path `${msft_proxy4_INCLUDE_DIR}`")
1818
1919
add_library(msft_proxy4_module)
2020
set_target_properties(
@@ -24,24 +24,24 @@ set_target_properties(
2424
EXCLUDE_FROM_ALL TRUE
2525
)
2626
27-
add_library(msft_proxy::proxy4_module ALIAS msft_proxy4_module)
27+
add_library(msft_proxy4::proxy_module ALIAS msft_proxy4_module)
2828
target_sources(msft_proxy4_module PUBLIC
2929
FILE_SET CXX_MODULES
30-
BASE_DIRS ${proxy4_INCLUDE_DIR}
30+
BASE_DIRS ${msft_proxy4_INCLUDE_DIR}
3131
FILES
32-
${proxy4_INCLUDE_DIR}/proxy/v4/proxy.ixx
32+
${msft_proxy4_INCLUDE_DIR}/proxy/v4/proxy.ixx
3333
)
3434
target_compile_features(msft_proxy4_module PUBLIC cxx_std_20) # (2)
35-
target_link_libraries(msft_proxy4_module PUBLIC msft_proxy::proxy4)
35+
target_link_libraries(msft_proxy4_module PUBLIC msft_proxy4::proxy)
3636
```
3737

38-
- (1) `proxy4_INCLUDE_DIR` is automatically declared after `find_package(proxy4)`. CPM uses a slightly different convention where `proxy_SOURCE_DIR` is declared after `CPMAddPackage`.
38+
- (1) `msft_proxy4_INCLUDE_DIR` is automatically declared after `find_package(msft_proxy4)`. CPM uses a slightly different convention where `msft_proxy4_SOURCE_DIR` is declared after `CPMAddPackage`.
3939
- (2) The C++ standard version for `msft_proxy4_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.
4040

4141
It can then be consumed like this:
4242

4343
```cmake
44-
target_link_libraries(main PRIVATE msft_proxy::proxy4_module)
44+
target_link_libraries(main PRIVATE msft_proxy4::proxy_module)
4545
```
4646

4747
## Example

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_executable(msft_proxy_tests
3939
proxy_view_tests.cpp
4040
)
4141
target_include_directories(msft_proxy_tests PRIVATE .)
42-
target_link_libraries(msft_proxy_tests PRIVATE msft_proxy::proxy4 gtest_main fmt::fmt)
42+
target_link_libraries(msft_proxy_tests PRIVATE msft_proxy4::proxy gtest_main fmt::fmt)
4343

4444
if(MSVC)
4545
target_compile_options(msft_proxy_tests PRIVATE /W4 /WX)
@@ -59,7 +59,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
5959
target_compile_options(msft_proxy_freestanding_tests PRIVATE -ffreestanding -fno-exceptions -fno-rtti -Wall -Wextra -Wpedantic -Werror)
6060
endif()
6161
target_link_options(msft_proxy_freestanding_tests PRIVATE -nodefaultlibs -lc)
62-
target_link_libraries(msft_proxy_freestanding_tests PRIVATE msft_proxy::proxy4)
62+
target_link_libraries(msft_proxy_freestanding_tests PRIVATE msft_proxy4::proxy)
6363
add_test(NAME ProxyFreestandingTests COMMAND msft_proxy_freestanding_tests)
6464
endif()
6565

tests/cpp20_modules/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ if(PROXY_BUILD_MODULES)
1010
foo.cpp
1111
impl.cpp
1212
)
13-
target_link_libraries(msft_proxy_tests PRIVATE msft_proxy::proxy4_module)
13+
target_link_libraries(msft_proxy_tests PRIVATE msft_proxy4::proxy_module)
1414
endif()

0 commit comments

Comments
 (0)