summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2017-01-02 23:35:42 (GMT)
committerGitHub <noreply@github.com>2017-01-02 23:35:42 (GMT)
commitc18a81c02a0543befb1c85a8e1682e2ee1e72e8e (patch)
tree61754c06be5e516c0264a7931d33c3db6f6bb614 /contrib
parent8c4de60d0f871f8e81986b2c61b70e1bcb8b97fd (diff)
parentd7969e49af22943a3f0062b8fe8abc04bb1dd6a7 (diff)
downloadlz4-c18a81c02a0543befb1c85a8e1682e2ee1e72e8e.zip
lz4-c18a81c02a0543befb1c85a8e1682e2ee1e72e8e.tar.gz
lz4-c18a81c02a0543befb1c85a8e1682e2ee1e72e8e.tar.bz2
Merge pull request #296 from mgorny/cmake-fixes
Multiple CMake improvements
Diffstat (limited to 'contrib')
-rw-r--r--contrib/cmake_unofficial/CMakeLists.txt65
1 files changed, 52 insertions, 13 deletions
diff --git a/contrib/cmake_unofficial/CMakeLists.txt b/contrib/cmake_unofficial/CMakeLists.txt
index de070d6..9a0983d 100644
--- a/contrib/cmake_unofficial/CMakeLists.txt
+++ b/contrib/cmake_unofficial/CMakeLists.txt
@@ -65,6 +65,11 @@ endif(NOT LZ4_BUNDLED_MODE AND NOT CPack_CMake_INCLUDED)
# which case we always use static libraries.
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON "NOT LZ4_BUNDLED_MODE" OFF)
+CMAKE_DEPENDENT_OPTION(BUILD_STATIC_LIBS "Build static libraries" OFF "BUILD_SHARED_LIBS" ON)
+
+if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
+ message(FATAL_ERROR "Both BUILD_SHARED_LIBS and BUILD_STATIC_LIBS have been disabled")
+endif()
set(LZ4_LIB_SOURCE_DIR "${LZ4_TOP_SOURCE_DIR}/lib")
set(LZ4_PROG_SOURCE_DIR "${LZ4_TOP_SOURCE_DIR}/programs")
@@ -90,28 +95,41 @@ set(LZ4_CLI_SOURCES
# we're building a shared library this is ignored and PIC is always
# used.
option(LZ4_POSITION_INDEPENDENT_LIB "Use position independent code for static library (if applicable)" ON)
-if(LZ4_POSITION_INDEPENDENT_LIB OR BUILD_SHARED_LIBS)
- set(LZ4_POSITION_INDEPENDENT_CODE TRUE)
-else()
- set(LZ4_POSITION_INDEPENDENT_CODE FALSE)
-endif()
# liblz4
-add_library(lz4 ${LZ4_SOURCES})
-set_target_properties(lz4 PROPERTIES
- SOVERSION "${LZ4_VERSION_STRING}"
- VERSION "${LZ4_VERSION_STRING}"
- POSITION_INDEPENDENT_CODE ${LZ4_POSITION_INDEPENDENT_CODE})
+set(LZ4_LIBRARIES_BUILT)
+if(BUILD_SHARED_LIBS)
+ add_library(lz4_shared SHARED ${LZ4_SOURCES})
+ set_target_properties(lz4_shared PROPERTIES
+ OUTPUT_NAME lz4
+ SOVERSION "${LZ4_VERSION_MAJOR}"
+ VERSION "${LZ4_VERSION_STRING}")
+ list(APPEND LZ4_LIBRARIES_BUILT lz4_shared)
+endif()
+if(BUILD_STATIC_LIBS)
+ add_library(lz4_static STATIC ${LZ4_SOURCES})
+ set_target_properties(lz4_static PROPERTIES
+ OUTPUT_NAME lz4
+ POSITION_INDEPENDENT_CODE ${LZ4_POSITION_INDEPENDENT_LIB})
+ list(APPEND LZ4_LIBRARIES_BUILT lz4_static)
+endif()
+
+# link to shared whenever possible, to static otherwise
+if(BUILD_SHARED_LIBS)
+ set(LZ4_LINK_LIBRARY lz4_shared)
+else()
+ set(LZ4_LINK_LIBRARY lz4_static)
+endif()
# lz4
add_executable(lz4cli ${LZ4_CLI_SOURCES})
set_target_properties(lz4cli PROPERTIES OUTPUT_NAME lz4)
-target_link_libraries(lz4cli lz4)
+target_link_libraries(lz4cli ${LZ4_LINK_LIBRARY})
# lz4c
add_executable(lz4c ${LZ4_CLI_SOURCES})
set_target_properties(lz4c PROPERTIES COMPILE_DEFINITIONS "ENABLE_LZ4C_LEGACY_OPTIONS")
-target_link_libraries(lz4c lz4)
+target_link_libraries(lz4c ${LZ4_LINK_LIBRARY})
# Extra warning flags
include (CheckCCompilerFlag)
@@ -149,7 +167,7 @@ if(NOT LZ4_BUNDLED_MODE)
install(TARGETS lz4cli lz4c
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
- install(TARGETS lz4
+ install(TARGETS ${LZ4_LIBRARIES_BUILT}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES
@@ -157,8 +175,29 @@ if(NOT LZ4_BUNDLED_MODE)
"${LZ4_LIB_SOURCE_DIR}/lz4frame.h"
"${LZ4_LIB_SOURCE_DIR}/lz4hc.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+ install(FILES "${LZ4_PROG_SOURCE_DIR}/lz4.1"
+ DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblz4.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+
+ # install lz4cat and unlz4 symlinks on *nix
+ if(UNIX)
+ install(CODE "
+ foreach(f lz4cat unlz4)
+ set(dest \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/\${f}\")
+ message(STATUS \"Symlinking: \${dest} -> lz4\")
+ execute_process(
+ COMMAND \"${CMAKE_COMMAND}\" -E create_symlink lz4 \"\${dest}\")
+ endforeach()
+ ")
+
+ # create manpage aliases
+ foreach(f lz4cat unlz4)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${f}.1" ".so man1/lz4.1\n")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${f}.1"
+ DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
+ endforeach()
+ endif(UNIX)
endif(NOT LZ4_BUNDLED_MODE)
# pkg-config