]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
CMake: fixed multithreading build on Windows 993/head
authorAlexey Ivanov <alexey.ivanes@gmail.com>
Wed, 17 Jan 2018 07:27:52 +0000 (10:27 +0300)
committerAlexey Ivanov <alexey.ivanes@gmail.com>
Wed, 17 Jan 2018 07:27:52 +0000 (10:27 +0300)
`ZSTD_MULTITHREAD_SUPPORT` option fixed for Windows.

Signed-off-by: Alexey Ivanov <alexey.ivanes@gmail.com>
build/cmake/CMakeLists.txt
build/cmake/lib/CMakeLists.txt
build/cmake/programs/CMakeLists.txt

index 7361bc8a642730c574f8ec6c12bb618063c4b1c3..fd9bc2b1e7d8528cfede7e27609f0cbfb06994a9 100644 (file)
@@ -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
 #-----------------------------------------------------------------------------
index 3435e1bb3bfee7daf2f4875e953a3debc3ea9466..945fdb9221b44ad6972f400bcb154202a5fda69b 100644 (file)
@@ -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)
index 9251fd29585d09fac4c4df8a5974384159a46e04..6c0ed05a1db5e9bfc0aab4f22d2b070dd94660a1 100644 (file)
@@ -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)