Skip to content

Commit

Permalink
Add a BUILD_STATIC CMake option to optionally build a static library.
Browse files Browse the repository at this point in the history
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 #1.
  • Loading branch information
Jehan committed Nov 17, 2015
1 parent 9172b76 commit ad4dfc4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 26 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ad4dfc4

Please sign in to comment.