File tree 2 files changed +21
-4
lines changed 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,21 @@ cmake_minimum_required(VERSION 3.29)
2
2
3
3
project (library_1 VERSION 1.0.0 LANGUAGES CXX DESCRIPTION "my description" )
4
4
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} )
6
10
add_library (demo::${PROJECT_NAME} ALIAS ${PROJECT_NAME} )
7
11
8
12
# add_library(MyStuff SHARED source1.cpp ...)
9
13
set_target_properties (${PROJECT_NAME} PROPERTIES
10
14
VERSION 2.0.0
11
15
SOVERSION 2
12
- # This is for the Windows platform.
16
+
17
+ # This is for the Windows platform.
13
18
# Check Craig Scott "Professional CMake", Chapter "Shared Library Versioning"
14
- DLL_NAME_WITH_SOVERSION TRUE
19
+ DLL_NAME_WITH_SOVERSION TRUE
15
20
)
16
21
17
22
target_sources (${PROJECT_NAME}
Original file line number Diff line number Diff line change @@ -4,11 +4,23 @@ This example shows a minimal configuration for a C++ project yielding a library.
4
4
5
5
## Build Instructions
6
6
7
+ ### Build Static Library
8
+
7
9
``` bash
8
10
mkdir build_library_1
9
11
cd build_library_1/
10
- cmake ../library_1/
12
+ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=FALSE ../library_1
11
13
make
12
14
```
13
15
16
+ ### Build 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
+
14
26
Hint: there are more options to be considered for building stuff, see the other examples.
You can’t perform that action at this time.
0 commit comments