From 26ffc1863483d3cb4c24e2e7638a301324693c49 Mon Sep 17 00:00:00 2001 From: 0x123456789A <57141050+0x123456789A@users.noreply.github.com> Date: Tue, 29 Oct 2019 14:31:02 +0100 Subject: [PATCH 1/3] Introduce ZSTD_PROGRAMS_LINK_SHARED The CMake variable ZSTD_PROGRAMS_LINK_SHARED indicactes wether or not to link the zstd programs dynamically or statically. --- build/cmake/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 33c05aee8..41fdf787f 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -124,9 +124,13 @@ endif () #----------------------------------------------------------------------------- add_subdirectory(lib) +option(ZSTD_PROGRAMS_LINK_SHARED "PROGRAMS LINK SHARED" OFF) + if (ZSTD_BUILD_PROGRAMS) - if (NOT ZSTD_BUILD_STATIC) + if (NOT ZSTD_BUILD_STATIC AND NOT ZSTD_PROGRAMS_LINK_SHARED) message(SEND_ERROR "You need to build static library to build zstd CLI") + elseif(ZSTD_BUILD_STATIC AND ZSTD_PROGRAMS_LINK_SHARED) + message(SEND_ERROR "You need to build shared library to build zstd CLI") endif () add_subdirectory(programs) From 57a311d3b7dac3728a366ef9892f9d0ed48816a8 Mon Sep 17 00:00:00 2001 From: 0x123456789A <57141050+0x123456789A@users.noreply.github.com> Date: Tue, 29 Oct 2019 14:33:50 +0100 Subject: [PATCH 2/3] Consider ZSTD_PROGRAMS_LINK_SHARED Actually consider ZSTD_PROGRAMS_LINK_SHARED in programs CMakeLists --- build/cmake/programs/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build/cmake/programs/CMakeLists.txt b/build/cmake/programs/CMakeLists.txt index 8afd83503..b26e97d0d 100644 --- a/build/cmake/programs/CMakeLists.txt +++ b/build/cmake/programs/CMakeLists.txt @@ -21,13 +21,19 @@ if (ZSTD_LEGACY_SUPPORT) include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy) endif () +if (ZSTD_PROGRAMS_LINK_SHARED) + set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared) +else () + set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static) +endif () + if (MSVC) set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd) set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc) endif () add_executable(zstd ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/dibio.c ${PlatformDependResources}) -target_link_libraries(zstd libzstd_static) +target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET}) if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") target_link_libraries(zstd rt) endif () @@ -68,7 +74,7 @@ if (UNIX) DESTINATION "${MAN_INSTALL_DIR}") add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c) - target_link_libraries(zstd-frugal libzstd_static) + target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET}) set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT") endif () From 9db11e3e42d9cde6bfd88e0c52df369aefe55d5a Mon Sep 17 00:00:00 2001 From: 0x123456789A <57141050+0x123456789A@users.noreply.github.com> Date: Tue, 29 Oct 2019 14:41:32 +0100 Subject: [PATCH 3/3] Fixed check for building programs statically --- build/cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 41fdf787f..9d0e7fb0b 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -129,7 +129,7 @@ option(ZSTD_PROGRAMS_LINK_SHARED "PROGRAMS LINK SHARED" OFF) if (ZSTD_BUILD_PROGRAMS) if (NOT ZSTD_BUILD_STATIC AND NOT ZSTD_PROGRAMS_LINK_SHARED) message(SEND_ERROR "You need to build static library to build zstd CLI") - elseif(ZSTD_BUILD_STATIC AND ZSTD_PROGRAMS_LINK_SHARED) + elseif(NOT ZSTD_BUILD_SHARED AND ZSTD_PROGRAMS_LINK_SHARED) message(SEND_ERROR "You need to build shared library to build zstd CLI") endif ()