From 22303da601ccf2e068113c51ce85cc192ec6cd07 Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Wed, 17 Jan 2018 10:27:52 +0300 Subject: [PATCH] CMake: fixed multithreading build on Windows `ZSTD_MULTITHREAD_SUPPORT` option fixed for Windows. Signed-off-by: Alexey Ivanov --- build/cmake/CMakeLists.txt | 42 +++++++++++++++++++++-------- build/cmake/lib/CMakeLists.txt | 13 ++++++++- build/cmake/programs/CMakeLists.txt | 16 +++++------ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 7361bc8a6..fd9bc2b1e 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -31,18 +31,9 @@ MESSAGE(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") #----------------------------------------------------------------------------- # Options #----------------------------------------------------------------------------- + +# Legacy support OPTION(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF) -IF (UNIX) - OPTION(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" ON) -ELSE (UNIX) - OPTION(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" OFF) -ENDIF (UNIX) -OPTION(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" ON) -OPTION(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF) -OPTION(ZSTD_BUILD_TESTS "BUILD TESTS" OFF) -if (MSVC) - OPTION(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF) -endif () IF (ZSTD_LEGACY_SUPPORT) MESSAGE(STATUS "ZSTD_LEGACY_SUPPORT defined!") @@ -52,6 +43,35 @@ ELSE (ZSTD_LEGACY_SUPPORT) ADD_DEFINITIONS(-DZSTD_LEGACY_SUPPORT=0) ENDIF (ZSTD_LEGACY_SUPPORT) +# Multi-threading support +OPTION(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" ON) + +IF (ZSTD_MULTITHREAD_SUPPORT) + MESSAGE(STATUS "ZSTD_MULTITHREAD_SUPPORT is enabled") +ELSE (ZSTD_MULTITHREAD_SUPPORT) + MESSAGE(STATUS "ZSTD_MULTITHREAD_SUPPORT is disabled") +ENDIF (ZSTD_MULTITHREAD_SUPPORT) + +OPTION(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" ON) +OPTION(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF) +OPTION(ZSTD_BUILD_TESTS "BUILD TESTS" OFF) +if (MSVC) + OPTION(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF) +endif () + +#----------------------------------------------------------------------------- +# External dependencies +#----------------------------------------------------------------------------- +IF (ZSTD_MULTITHREAD_SUPPORT AND UNIX) + SET(THREADS_PREFER_PTHREAD_FLAG ON) + FIND_PACKAGE(Threads REQUIRED) + IF(CMAKE_USE_PTHREADS_INIT) + SET(THREADS_LIBS "${CMAKE_THREAD_LIBS_INIT}") + ELSE() + MESSAGE(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads") + ENDIF() +ENDIF (ZSTD_MULTITHREAD_SUPPORT AND UNIX) + #----------------------------------------------------------------------------- # Add source directories #----------------------------------------------------------------------------- diff --git a/build/cmake/lib/CMakeLists.txt b/build/cmake/lib/CMakeLists.txt index 3435e1bb3..945fdb922 100644 --- a/build/cmake/lib/CMakeLists.txt +++ b/build/cmake/lib/CMakeLists.txt @@ -24,7 +24,7 @@ INCLUDE_DIRECTORIES(${LIBRARY_DIR} ${LIBRARY_DIR}/common) # Parse version INCLUDE(GetZstdLibraryVersion) GetZstdLibraryVersion(${LIBRARY_DIR}/zstd.h LIBVER_MAJOR LIBVER_MINOR LIBVER_RELEASE) -MESSAGE("ZSTD VERSION ${LIBVER_MAJOR}.${LIBVER_MINOR}.${LIBVER_RELEASE}") +MESSAGE(STATUS "ZSTD VERSION ${LIBVER_MAJOR}.${LIBVER_MINOR}.${LIBVER_RELEASE}") SET(Sources ${LIBRARY_DIR}/common/entropy_common.c @@ -120,6 +120,17 @@ IF (MSVC) ENDIF (ZSTD_BUILD_STATIC) ENDIF (MSVC) +# Add multi-threading support definitions + +IF (ZSTD_MULTITHREAD_SUPPORT) + SET_PROPERTY(TARGET libzstd_shared libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD") + + IF (UNIX) + TARGET_LINK_LIBRARIES(libzstd_shared ${THREADS_LIBS}) + TARGET_LINK_LIBRARIES(libzstd_static ${THREADS_LIBS}) + ENDIF () +ENDIF (ZSTD_MULTITHREAD_SUPPORT) + # With MSVC static library needs to be renamed to avoid conflict with import library IF (MSVC) SET(STATIC_LIBRARY_BASE_NAME zstd_static) diff --git a/build/cmake/programs/CMakeLists.txt b/build/cmake/programs/CMakeLists.txt index 9251fd295..6c0ed05a1 100644 --- a/build/cmake/programs/CMakeLists.txt +++ b/build/cmake/programs/CMakeLists.txt @@ -54,19 +54,17 @@ IF (UNIX) SET_PROPERTY(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT") ENDIF (UNIX) +# Add multi-threading support definitions + IF (ZSTD_MULTITHREAD_SUPPORT) SET_PROPERTY(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD") - SET(THREADS_PREFER_PTHREAD_FLAG ON) - FIND_PACKAGE(Threads REQUIRED) - IF (CMAKE_USE_PTHREADS_INIT) - TARGET_LINK_LIBRARIES(zstd ${CMAKE_THREAD_LIBS_INIT}) - ELSE() - MESSAGE(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads") - ENDIF() + IF (UNIX) + TARGET_LINK_LIBRARIES(zstd ${THREADS_LIBS}) - ADD_CUSTOM_TARGET(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink") - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "bin") + ADD_CUSTOM_TARGET(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink") + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "bin") + ENDIF (UNIX) ENDIF (ZSTD_MULTITHREAD_SUPPORT) OPTION(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF) -- 2.47.2