Skip to content

Commit 572aa33

Browse files
authored
Merge pull request #9 from daixtrose/add-library-refinements
Add library refinements
2 parents 53def92 + 46acc4f commit 572aa33

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ A short introduction to C++. The examples build on top of each other. A special
66

77
## Useful Weblinks
88

9+
### C++
10+
911
- [C++ Reference](https://en.cppreference.com/)
1012
- This is a carefully crafted encyclopedia of C++ features with examples
1113
- The first stop for any question
1214
- [Matt Godbolt's Compiler Explorer](https://godbolt.org/)
1315
- An online compiler tester
1416
- Use for testing small C++ code snippets
17+
18+
### CMake
19+
1520
- [Craig Scott: "Professional CMake"](https://crascit.com/professional-cmake/)
1621
- The one and only book you need about build systems
1722
- [HSF - More Modern CMake](https://hsf-training.github.io/hsf-training-cmake-webpage/index.html)
23+
- [Building a Dual Shared and Static Library with CMake](https://alexreinking.com/blog/building-a-dual-shared-and-static-library-with-cmake.html)
1824

1925
## List of Subprojects
2026

library_1/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ cmake_minimum_required(VERSION 3.29)
22

33
project(library_1 VERSION 1.0.0 LANGUAGES CXX DESCRIPTION "my description")
44

5-
add_library(${PROJECT_NAME} SHARED)
5+
# This option changes the implicit behavior of CMake
6+
# See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
7+
option(BUILD_SHARED_LIBS "Build as shared library" ON)
8+
9+
add_library(${PROJECT_NAME})
610
add_library(demo::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
711

812
# add_library(MyStuff SHARED source1.cpp ...)
913
set_target_properties(${PROJECT_NAME} PROPERTIES
1014
VERSION 2.0.0
1115
SOVERSION 2
12-
# This is for the Windows platform.
16+
17+
# This is for the Windows platform.
1318
# Check Craig Scott "Professional CMake", Chapter "Shared Library Versioning"
14-
DLL_NAME_WITH_SOVERSION TRUE
19+
DLL_NAME_WITH_SOVERSION TRUE
1520
)
1621

1722
target_sources(${PROJECT_NAME}

library_1/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ This example shows a minimal configuration for a C++ project yielding a library.
44

55
## Build Instructions
66

7+
### Build a Static Library
8+
79
```bash
810
mkdir build_library_1
911
cd build_library_1/
10-
cmake ../library_1/
12+
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=FALSE ../library_1
1113
make
1214
```
1315

16+
### Build a Shared Library
17+
18+
```bash
19+
mkdir build_library_1
20+
cd build_library_1/
21+
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=TRUE ../library_1
22+
make
23+
```
24+
25+
1426
Hint: there are more options to be considered for building stuff, see the other examples.

0 commit comments

Comments
 (0)