From ad4dfc4be4247104a525d8404f6180aeb0a3b223 Mon Sep 17 00:00:00 2001 From: Jehan Date: Tue, 17 Nov 2015 18:12:44 +0100 Subject: [PATCH] Add a BUILD_STATIC CMake option to optionally build a static library. It is still ON by default, which means both shared and static libs will be built and installed (current behavior), but it makes it possible to disable the build of a static lib. Closes https://github.com/BYVoid/uchardet/issues/1. --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 38 ++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad32ffc..e3df71c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,9 @@ set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) ######## Configuration +option(BUILD_STATIC "Build static library" + ON) + configure_file( uchardet.pc.in uchardet.pc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b36fd0..42574ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,15 +51,16 @@ add_library( ${UCHARDET_SOURCES} ) -add_library( - ${UCHARDET_STATIC_TARGET} - STATIC - ${UCHARDET_SOURCES} -) +if (BUILD_STATIC) + add_library( + ${UCHARDET_STATIC_TARGET} + STATIC + ${UCHARDET_SOURCES} + ) +endif (BUILD_STATIC) set_target_properties( ${UCHARDET_TARGET} - ${UCHARDET_STATIC_TARGET} PROPERTIES LINKER_LANGUAGE CXX @@ -71,6 +72,17 @@ set_target_properties( 0 ) +if (BUILD_STATIC) + set_target_properties( + ${UCHARDET_STATIC_TARGET} + PROPERTIES + LINKER_LANGUAGE + CXX + OUTPUT_NAME + uchardet + ) +endif (BUILD_STATIC) + if (CMAKE_BUILD_TYPE MATCHES Debug) add_definitions( -O0 @@ -96,12 +108,14 @@ install( ) endif (NOT WIN32) -install( - TARGETS - ${UCHARDET_STATIC_TARGET} - ARCHIVE DESTINATION - ${DIR_LIBRARY_STATIC} -) +if (BUILD_STATIC) + install( + TARGETS + ${UCHARDET_STATIC_TARGET} + ARCHIVE DESTINATION + ${DIR_LIBRARY_STATIC} + ) +endif (BUILD_STATIC) install( FILES