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.
This commit is contained in:
Jehan 2015-11-17 18:12:44 +01:00
parent 9172b763d1
commit ad4dfc4be4
2 changed files with 29 additions and 12 deletions

View File

@ -59,6 +59,9 @@ set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale)
######## Configuration ######## Configuration
option(BUILD_STATIC "Build static library"
ON)
configure_file( configure_file(
uchardet.pc.in uchardet.pc.in
uchardet.pc uchardet.pc

View File

@ -51,15 +51,16 @@ add_library(
${UCHARDET_SOURCES} ${UCHARDET_SOURCES}
) )
add_library( if (BUILD_STATIC)
${UCHARDET_STATIC_TARGET} add_library(
STATIC ${UCHARDET_STATIC_TARGET}
${UCHARDET_SOURCES} STATIC
) ${UCHARDET_SOURCES}
)
endif (BUILD_STATIC)
set_target_properties( set_target_properties(
${UCHARDET_TARGET} ${UCHARDET_TARGET}
${UCHARDET_STATIC_TARGET}
PROPERTIES PROPERTIES
LINKER_LANGUAGE LINKER_LANGUAGE
CXX CXX
@ -71,6 +72,17 @@ set_target_properties(
0 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) if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions( add_definitions(
-O0 -O0
@ -96,12 +108,14 @@ install(
) )
endif (NOT WIN32) endif (NOT WIN32)
install( if (BUILD_STATIC)
TARGETS install(
${UCHARDET_STATIC_TARGET} TARGETS
ARCHIVE DESTINATION ${UCHARDET_STATIC_TARGET}
${DIR_LIBRARY_STATIC} ARCHIVE DESTINATION
) ${DIR_LIBRARY_STATIC}
)
endif (BUILD_STATIC)
install( install(
FILES FILES