Skip to content

Commit f6c4d9a

Browse files
committed
add call decision between a shared and a static library
1 parent 59efb2e commit f6c4d9a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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 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 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)