Added options for building programs, static library and tests

This commit is contained in:
Milan Ševčík 2017-03-20 15:47:28 +01:00
parent 16f771dfb1
commit 01d7ea27e9
2 changed files with 32 additions and 10 deletions

View File

@ -22,7 +22,9 @@ ADD_EXTRA_COMPILATION_FLAGS()
#-----------------------------------------------------------------------------
OPTION(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
OPTION(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" ON)
OPTION(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" ON)
OPTION(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF)
OPTION(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
IF (ZSTD_LEGACY_SUPPORT)
MESSAGE(STATUS "ZSTD_LEGACY_SUPPORT defined!")
@ -36,8 +38,19 @@ ENDIF (ZSTD_LEGACY_SUPPORT)
# Add source directories
#-----------------------------------------------------------------------------
ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(programs)
ADD_SUBDIRECTORY(tests)
IF (ZSTD_BUILD_PROGRAMS)
ADD_SUBDIRECTORY(programs)
ENDIF (ZSTD_BUILD_PROGRAMS)
IF (ZSTD_BUILD_TESTS)
IF (NOT ZSTD_BUILD_STATIC)
MESSAGE(SEND_ERROR "You need to build static library to build tests")
ENDIF (NOT ZSTD_BUILD_STATIC)
ADD_SUBDIRECTORY(tests)
ENDIF (ZSTD_BUILD_TESTS)
IF (ZSTD_BUILD_CONTRIB)
ADD_SUBDIRECTORY(contrib)
ENDIF (ZSTD_BUILD_CONTRIB)

View File

@ -14,6 +14,7 @@ PROJECT(libzstd)
INCLUDE(${CMAKE_SOURCE_DIR}/CMakeModules/GetLibraryVersion.cmake)
SET(CMAKE_INCLUDE_CURRENT_DIR TRUE)
OPTION(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" OFF)
# Define library directory, where sources and header files are located
SET(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
@ -89,13 +90,17 @@ IF (MSVC)
ENDIF (MSVC)
# Split project to static and shared libraries build
ADD_LIBRARY(libzstd_static STATIC ${Sources} ${Headers})
ADD_LIBRARY(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources})
IF (ZSTD_BUILD_STATIC)
ADD_LIBRARY(libzstd_static STATIC ${Sources} ${Headers})
ENDIF (ZSTD_BUILD_STATIC)
# Add specific compile definitions for MSVC project
IF (MSVC)
SET_TARGET_PROPERTIES(libzstd_static PROPERTIES COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
SET_TARGET_PROPERTIES(libzstd_shared PROPERTIES COMPILE_DEFINITIONS "ZSTD_DLL_EXPORT=1;ZSTD_HEAPMODE=0;_CONSOLE;_CRT_SECURE_NO_WARNINGS")
IF (ZSTD_BUILD_STATIC)
SET_TARGET_PROPERTIES(libzstd_static PROPERTIES COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
ENDIF (ZSTD_BUILD_STATIC)
ENDIF (MSVC)
# Define library base name
@ -111,22 +116,26 @@ ELSE ()
ENDIF (MSVC)
# Define static and shared library names
SET_TARGET_PROPERTIES(
libzstd_static
PROPERTIES
OUTPUT_NAME ${LIBRARY_BASE_NAME})
SET_TARGET_PROPERTIES(
libzstd_shared
PROPERTIES
OUTPUT_NAME ${LIBRARY_BASE_NAME}
SOVERSION ${LIBVER_MAJOR}.${LIBVER_MINOR}.${LIBVER_RELEASE})
IF (ZSTD_BUILD_STATIC)
SET_TARGET_PROPERTIES(
libzstd_static
PROPERTIES
OUTPUT_NAME ${LIBRARY_BASE_NAME})
ENDIF (ZSTD_BUILD_STATIC)
IF (UNIX)
# install target
INSTALL(FILES ${LIBRARY_DIR}/zstd.h ${LIBRARY_DIR}/deprecated/zbuff.h ${LIBRARY_DIR}/dictBuilder/zdict.h DESTINATION "include")
INSTALL(TARGETS libzstd_static ARCHIVE DESTINATION "lib")
INSTALL(TARGETS libzstd_shared LIBRARY DESTINATION "lib")
IF (ZSTD_BUILD_STATIC)
INSTALL(TARGETS libzstd_static ARCHIVE DESTINATION "lib")
ENDIF (ZSTD_BUILD_STATIC)
# uninstall target
CONFIGURE_FILE(