Skip to content

Commit 9d446d1

Browse files
committed
Update Readme and Debug preset
1 parent 6d6508e commit 9d446d1

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

CMakeGenericPresets.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
"generator": "Ninja",
1414
"hidden": true,
1515
"cacheVariables": {
16-
"CMAKE_BUILD_TYPE": "Debug",
1716
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
1817
"CMAKE_MESSAGE_LOG_LEVEL": "WARNING",
19-
"MYLIB_SHARED_LIBS": true,
2018
"MYLIB_BUILD_TESTS": true,
2119
"MYLIB_BUILD_EXAMPLES": true
2220
}
@@ -47,6 +45,7 @@
4745
"type": "path",
4846
"value": "${sourceDir}/stagedir"
4947
},
48+
"CMAKE_BUILD_TYPE": "Debug",
5049
"CMAKE_MESSAGE_LOG_LEVEL": "STATUS",
5150
"BUILD_SHARED_LIBS": false,
5251
"BUILD_TESTING": true
@@ -63,7 +62,7 @@
6362
"name": "clang-tidy",
6463
"hidden": true,
6564
"cacheVariables": {
66-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=^${sourceDir}/"
65+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=^${sourceDir}/include"
6766
}
6867
},
6968
{

CMakeLists.txt

-12
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ target_sources(
9292
)
9393
target_compile_definitions(mylib PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:MYLIB_STATIC_DEFINE>")
9494

95-
# target_include_directories(mylib
96-
# PUBLIC
97-
# "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
98-
# "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
99-
10095
set_target_properties(mylib PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION})
10196

10297
if(MYLIB_INSTALL AND NOT CMAKE_SKIP_INSTALL_RULES)
@@ -116,13 +111,6 @@ if(MYLIB_INSTALL AND NOT CMAKE_SKIP_INSTALL_RULES)
116111
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
117112
)
118113

119-
# install(DIRECTORY include/
120-
# TYPE INCLUDE
121-
# COMPONENT mylib-dev)
122-
# install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/mylib/${export_file_name}"
123-
# COMPONENT mylib-dev
124-
# DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mylib")
125-
126114
set(targets_file "mylib-shared-targets.cmake")
127115

128116
if(NOT BUILD_SHARED_LIBS)

README.md

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
# Overview
22

3-
Template repository to be used as a base for creating C++ libraries built with CMake. This repository provides:
4-
* Commonly accepted directory layout: `cmake` for CMake utilities and package config, `include/<libname>` for public headers, `src` for library sources and private headers, `examples` and `tests` for library examples and tests correspondingly.
3+
Template repository to be used as a base for creating C++ libraries built with CMake.
4+
5+
## This repository provides:
6+
7+
* Commonly accepted directory layout:
8+
9+
- `cmake` for CMake utilities and package config
10+
- `include/<libname>` for public headers
11+
- `src` for library sources and private headers
12+
- `examples`
13+
- `tests` for library examples and tests correspondingly
14+
515
* `CMakeLists.txt` files thoroughly implemented with the following ideas in mind:
6-
* user should be able to build library both as subproject (probably fetched with CMake's [FetchContent_MakeAvailable](https://cmake.org/cmake/help/latest/module/FetchContent.html)) and as a stand-alone project
7-
* user should be able to build examples/tests as part of the library build or as a stand-alone projects
8-
* multi-configuration CMake generators should be supported
9-
* package systems (conan, vcpkg and others) should be respected, which means that library `CMakeLists.txt` file should contain only **build requirements**, i.e. should not hardcode any compiler/linker flags unless they are absolutely required to build the library
10-
* Basic [preset](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) file `CMakePresets.json` which is a modern way (since CMake 3.19) for specifying build options (instead of hardcoding them in the `CMakeLists.txt` or setting on the command line)
16+
17+
- user should be able to build library both as subproject (probably fetched with CMake's
18+
[FetchContent_MakeAvailable](https://cmake.org/cmake/help/latest/module/FetchContent.html)) and as a stand-alone project
19+
- user should be able to build examples/tests as part of the library build or as a stand-alone projects
20+
- multi-configuration CMake generators should be supported
21+
- package systems (conan, vcpkg and others) should be respected, which means that library `CMakeLists.txt` file should contain
22+
only **build requirements**, i.e. should not hardcode any compiler/linker flags unless they are absolutely required to build
23+
the library
24+
25+
* [CMake Workflow preset](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) file `CMakePresets.json` which is a
26+
modern way (since CMake 3.25) for specifying build options (instead of hardcoding them in the `CMakeLists.txt` or setting
27+
on the command line)
28+
1129
* My personal `.clang-format` for code-style worth trying
1230

13-
Note, that I prefer [googletest](https://github.com/google/googletest) as a testing framework so it's the one used in this repository. Still it's not a big deal to replace it with any other of your choice.
31+
* And too `.cmake-format.yml` to format the CMake files
32+
33+
Note, that I prefer [googletest](https://github.com/google/googletest) as a testing framework so it's the one used in this
34+
repository. Still it's not a big deal to replace it with any other of your choice.
35+
36+
37+
## Links
38+
39+
* Anton Pantyukhin - [Modern CMake tutorial for C++ library developers](https://medium.com/@pananton/modern-cmake-tutorial-for-c-library-developers-12f3bf57dc87)
40+
* Dominik Berner - [Organizing CMake presets](https://dominikberner.ch/cmake-presets-best-practices/)
41+
* Craig Scott -[C++20 Modules, CMake, And Shared Libraries](https://crascit.com/category/cmake/)
42+
* [cmake-init - CMake project generator](https://github.com/friendlyanon/cmake-init) that creates good `CMakeLists.tx` files

0 commit comments

Comments
 (0)