Skip to content

Commit 2db6ba8

Browse files
committed
trying to unify FetchContent and find_package usage
1 parent 303fd80 commit 2db6ba8

File tree

4 files changed

+44
-37
lines changed

4 files changed

+44
-37
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ add_library(ut INTERFACE)
1515
foreach (include ${includes})
1616
add_subdirectory("${include}")
1717
cmake_path(GET include FILENAME module_name)
18-
target_link_libraries(ut INTERFACE "${module_name}")
19-
list(APPEND LIBUT_TARGET_LIST "${module_name}")
18+
target_link_libraries(ut INTERFACE ut_${module_name})
19+
list(APPEND LIBUT_TARGET_LIST ut_${module_name})
2020
endforeach ()
21+
if (NOT TARGET ut::ut)
22+
add_library(ut::ut ALIAS ut)
23+
endif ()
2124
list(APPEND LIBUT_TARGET_LIST ut)
2225
set(LIBUT_TARGET_LIST
2326
"${LIBUT_TARGET_LIST}"
2427
CACHE INTERNAL "" FORCE
2528
)
26-
message(STATUS "libut: adding UT::ut")
29+
message(STATUS "libut: adding ut::ut")
2730
libut_install()
2831

2932
if (PROJECT_IS_TOP_LEVEL)

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,43 @@ FetchContent_MakeAvailable(libut)
3232
3333
# assuming MY_TARGET is a valid target (executable or library)
3434
35-
target_link_libraries(MY_TARGET UT::target_name)
35+
target_link_libraries(MY_TARGET ut::target_name)
3636
```
3737

3838
### Currently available targets
3939

4040
<!-- AUTOGEN_BEGIN -->
4141

42-
* `UT::ptr_containers`: containers for storing owning pointers
43-
* `UT::check`: type which prints when it is constructed/copied/moved/destructed
44-
* `UT::pair`: a better `std::pair` implementation
45-
* `UT::switchboard`: composable and type-safe CLI parser
46-
* `UT::err`: convenient error type for use with std::expected
47-
* `UT::add_noexcept`: add the `noexcept` specifier to a function type
48-
* `UT::change_observer`: wrapper class that invokes callbacks when it's held value changes
49-
* `UT::traced_error`: an exception type that automatically stores a C++23 standard stacktrace
50-
* `UT::sv_to_num`: convert `std::string_view` to a number
51-
* `UT::copy_traits`: copy cvref qualifiers from one type to another
52-
* `UT::realloc_unique_ptr`: `realloc` functionality for `std::uniqur_ptr`
53-
* `UT::assert`: various assertion macros
54-
* `UT::resource`: a more general version of `std::unique_ptr` that operates on values
55-
* `UT::demangle`: convert types into human readable strings
56-
* `UT::constexpr_hash`: a hashing function usable in `constexpr` context
57-
* `UT::trim`: trim characters from start and end of a `std::string_view`
58-
* `UT::pack_loops`: loop over variadic template parameters (either values or types)
59-
* `UT::asis`: Provides a more convenient way to work with different kinds of dynamically polymorphic values.
42+
* `ut::ptr_containers`: containers for storing owning pointers
43+
* `ut::check`: type which prints when it is constructed/copied/moved/destructed
44+
* `ut::pair`: a better `std::pair` implementation
45+
* `ut::switchboard`: composable and type-safe CLI parser
46+
* `ut::err`: convenient error type for use with std::expected
47+
* `ut::add_noexcept`: add the `noexcept` specifier to a function type
48+
* `ut::change_observer`: wrapper class that invokes callbacks when it's held value changes
49+
* `ut::traced_error`: an exception type that automatically stores a C++23 standard stacktrace
50+
* `ut::sv_to_num`: convert `std::string_view` to a number
51+
* `ut::copy_traits`: copy cvref qualifiers from one type to another
52+
* `ut::realloc_unique_ptr`: `realloc` functionality for `std::uniqur_ptr`
53+
* `ut::assert`: various assertion macros
54+
* `ut::resource`: a more general version of `std::unique_ptr` that operates on values
55+
* `ut::demangle`: convert types into human readable strings
56+
* `ut::constexpr_hash`: a hashing function usable in `constexpr` context
57+
* `ut::trim`: trim characters from start and end of a `std::string_view`
58+
* `ut::pack_loops`: loop over variadic template parameters (either values or types)
59+
* `ut::asis`: Provides a more convenient way to work with different kinds of dynamically polymorphic values.
6060
* `UT::static_string`: compile time known string usable as a template parameter
61-
* `UT::breakpoint`: Portable(ish) breakpoint macros
62-
* `UT::mt_queue`: thread safe FIFO queue
63-
* `UT::curry`: create a curried function out of a regular function
64-
* `UT::defer`: a macro to defer execution until the scope ends
65-
* `UT::print`: macros for printing using `std::format` in c++20
66-
* `UT::overload`: creates a function object merging several other function objects as an overload set
61+
* `ut::static_string`: compile time known string usable as a template parameter
62+
* `ut::breakpoint`: Portable(ish) breakpoint macros
63+
* `ut::mt_queue`: thread safe FIFO queue
64+
* `ut::curry`: create a curried function out of a regular function
65+
* `ut::defer`: a macro to defer execution until the scope ends
66+
* `ut::print`: macros for printing using `std::format` in c++20
67+
* `ut::overload`: creates a function object merging several other function objects as an overload set
6768

6869
<!-- AUTOGEN_END -->
6970

70-
A special target `UT::ut` is also available, combining all of the above.
71+
A special target `ut::ut` is also available, combining all of the above.
7172

7273
## Testing
7374

cmake/targets.cmake

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
macro (libut_define_target name)
2-
add_library(${name} INTERFACE)
2+
add_library(ut_${name} INTERFACE)
33
target_sources(
4-
${name}
4+
ut_${name}
55
PUBLIC FILE_SET HEADERS #
66
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include #
77
FILES ${ARGN}
88
)
9+
if (NOT TARGET ut::${name})
10+
add_library(ut::${name} ALIAS ut_${name})
11+
endif ()
912

10-
# target_include_directories(
11-
# ${name} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
12-
# )
13-
message(STATUS "libut: adding ${name}")
13+
if (NOT TARGET ut::ut_${name})
14+
add_library(ut::ut_${name} ALIAS ut_${name})
15+
endif ()
16+
message(STATUS "libut: adding ut::${name}")
1417
endmacro ()

scripts/update_gists

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def write_cmake(name: str):
176176
if cmake_file.exists():
177177
print("file", cmake_file, "already exists", file=sys.stderr)
178178
return False
179-
print(f"Generating CMake file for target UT::{name}")
179+
print(f"Generating CMake file for target ut::{name}")
180180
with open(cmake_file, "w") as f:
181181
f.write(populate_cmake_template(name, cmake_file.parent))
182182

@@ -202,7 +202,7 @@ def update_readme():
202202
repl = (
203203
[r"\1"]
204204
+ [
205-
f"* `UT::{name.name}`: {get_desc(name)}"
205+
f"* `ut::{name.name}`: {get_desc(name)}"
206206
for name in INCLUDE.iterdir()
207207
if name.is_dir()
208208
]

0 commit comments

Comments
 (0)