aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2017-09-19 09:40:48 +0200
committerGitHub <noreply@github.com>2017-09-19 09:40:48 +0200
commit52f04833320d73a1970aaaf2737b23a63f85aeb2 (patch)
tree25caba5419fbba915f5fcb2537ee267b34780669 /CMakeLists.txt
parent87b43eb61b6c58fc60d9da871e8b55c6eb68987d (diff)
downloadbrotli-52f04833320d73a1970aaaf2737b23a63f85aeb2.zip
brotli-52f04833320d73a1970aaaf2737b23a63f85aeb2.tar.gz
brotli-52f04833320d73a1970aaaf2737b23a63f85aeb2.tar.bz2
Build both static and shared libs with CMake (#599)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt54
1 files changed, 34 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fcf0fd..150f44b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,22 +22,16 @@ if(BROTLI_BUNDLED_MODE STREQUAL "")
endif()
mark_as_advanced(BROTLI_BUNDLED_MODE)
-include(CMakeDependentOption)
-CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON "NOT BROTLI_BUNDLED_MODE" OFF)
-
include(GNUInstallDirs)
# When building shared libraries it is important to set the correct rpath.
# See https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH
-if (BUILD_SHARED_LIBS)
- add_definitions(-DBROTLI_SHARED_COMPILATION)
- set(CMAKE_SKIP_BUILD_RPATH FALSE)
- set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
- set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
- list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
- if ("${isSystemDir}" STREQUAL "-1")
- set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
- endif()
+set(CMAKE_SKIP_BUILD_RPATH FALSE)
+set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
+if ("${isSystemDir}" STREQUAL "-1")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
endif()
# Parse version information from common/version.h. Normally we would
@@ -113,9 +107,15 @@ endif()
unset(LOG2_RES)
set(BROTLI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/c/include")
+mark_as_advanced(BROTLI_INCLUDE_DIRS)
+
set(BROTLI_LIBRARIES_CORE brotlienc brotlidec brotlicommon)
set(BROTLI_LIBRARIES ${BROTLI_LIBRARIES_CORE} ${LIBM_LIBRARY})
-mark_as_advanced(BROTLI_INCLUDE_DIRS BROTLI_LIBRARIES)
+mark_as_advanced(BROTLI_LIBRARIES)
+
+set(BROTLI_LIBRARIES_CORE_STATIC brotlienc-static brotlidec-static brotlicommon-static)
+set(BROTLI_LIBRARIES_STATIC ${BROTLI_LIBRARIES_CORE_STATIC} ${LIBM_LIBRARY})
+mark_as_advanced(BROTLI_LIBRARIES_STATIC)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-DOS_LINUX)
@@ -125,14 +125,14 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-DOS_MACOSX)
endif()
-add_library(brotlicommon
+set(BROTLICOMMON_SOURCES
c/common/dictionary.c)
-add_library(brotlidec
+set(BROTLIDEC_SOURCES
c/dec/bit_reader.c
c/dec/decode.c
c/dec/huffman.c
c/dec/state.c)
-add_library(brotlienc
+set(BROTLIENC_SOURCES
c/enc/backward_references.c
c/enc/backward_references_hq.c
c/enc/bit_cost.c
@@ -151,25 +151,39 @@ add_library(brotlienc
c/enc/static_dict.c
c/enc/utf8_util.c)
+add_library(brotlicommon SHARED ${BROTLICOMMON_SOURCES})
+add_library(brotlidec SHARED ${BROTLIDEC_SOURCES})
+add_library(brotlienc SHARED ${BROTLIENC_SOURCES})
+
+add_library(brotlicommon-static STATIC ${BROTLICOMMON_SOURCES})
+add_library(brotlidec-static STATIC ${BROTLIDEC_SOURCES})
+add_library(brotlienc-static STATIC ${BROTLIENC_SOURCES})
+
# Older CMake versions does not understand INCLUDE_DIRECTORIES property.
include_directories(${BROTLI_INCLUDE_DIRS})
foreach(lib brotlicommon brotlidec brotlienc)
+ target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
+ string(TOUPPER "${lib}" LIB)
+ set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
+endforeach()
+
+foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static)
target_link_libraries(${lib} ${LIBM_LIBRARY})
set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
set_target_properties(${lib} PROPERTIES
SOVERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}"
VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}"
POSITION_INDEPENDENT_CODE TRUE)
- string(TOUPPER "${lib}" LIB)
- set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
-
set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
endforeach()
target_link_libraries(brotlidec brotlicommon)
target_link_libraries(brotlienc brotlicommon)
+target_link_libraries(brotlidec-static brotlicommon-static)
+target_link_libraries(brotlienc-static brotlicommon-static)
+
# For projects stuck on older versions of CMake, this will set the
# BROTLI_INCLUDE_DIRS and BROTLI_LIBRARIES variables so they still
# have a relatively easy way to use Brotli:
@@ -183,7 +197,7 @@ endif()
# Build the brotli executable
add_executable(brotli c/tools/brotli.c)
-target_link_libraries(brotli ${BROTLI_LIBRARIES})
+target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC})
# Installation
if(NOT BROTLI_BUNDLED_MODE)