From 952db0f3978b8c55648bcdee2291af4f54e36521 Mon Sep 17 00:00:00 2001 From: dota17 Date: Wed, 6 May 2020 10:48:53 +0800 Subject: [PATCH] support to build both static and shared libraries --- CMakeLists.txt | 20 ++++++++++++++++++++ README.md | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d51dc4..dc84b52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -400,6 +400,26 @@ target_include_directories(${PROJECT_NAME} $ ) +# Allow to build static and shared libraries at the same time +if (BUILD_STATIC_LIBS) + set(ORIGINAL_STATIC_LIB_NAME ${PROJECT_NAME}-static) + add_library(${ORIGINAL_STATIC_LIB_NAME} STATIC + ${JSON_C_SOURCES} + ${JSON_C_HEADERS} + ) + + # rename the static library + set_target_properties(${ORIGINAL_STATIC_LIB_NAME} PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + ) + + target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + ) +endif () + # Always create new install dirs with 0755 permissions, regardless of umask set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ diff --git a/README.md b/README.md index 39ea0d6..909fd11 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Variable | Type | Description CMAKE_INSTALL_PREFIX | String | The install location. CMAKE_BUILD_TYPE | String | Defaults to "debug" BUILD_SHARED_LIBS | Bool | The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library instead. +BUILD_STATIC_LIBS | Bool | This build generates a static (lib/a) library. ENABLE_RDRAND | Bool | Enable RDRAND Hardware RNG Hash Seed ENABLE_THREADING | Bool | Enable partial threading support DISABLE_WERROR | Bool | Disable use of -Werror @@ -106,7 +107,14 @@ DISABLE_BSYMBOLIC | Bool | Disable use of -Bsymbolic-functions Pass these options as `-D` on CMake's command-line. ```sh -cmake -DBUILD_SHARED_LIBS=OFF ... +# build a static library +cmake -DBUILD_SHARED_LIBS=OFF .. +``` + +Allow to build both static and shared libraries. + +```sh +cmake -DBUILD_STATIC_LIBS=ON .. ``` ### Building with partial threading support