#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( ZPaq VERSION 7.1.5 DESCRIPTION "Experimental extreme file compression algorithm" ) include("../../BuildSystem/cmake/cplusplus.cmake") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/zpaq715.tar.gz) message(STATUS "Downloading ZPaq sources") file( DOWNLOAD http://mattmahoney.net/dc/zpaq715.zip ${PROJECT_SOURCE_DIR}/downloads/zpaq715.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=5a560b256f4de68ee26cb638acd33960c9e71f53b767dcc01064238ae5e376c3 ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting ZPaq sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/zpaq715.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/zpaq715 ${PROJECT_SOURCE_DIR}/build ) endif() # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/libzpaq.cpp" ) set( headerFiles "build/libzpaq.h" ) # ------------------------------------------------------------------------------------------------- add_library(ZPaq STATIC) add_library(ZPaq::Static ALIAS ZPaq) if(${CMAKE_PROJECT_NAME} STREQUAL "ZPaq") enable_target_compiler_warnings(ZPaq) else() disable_target_compiler_warnings(ZPaq) endif() target_compile_definitions( ZPaq PUBLIC NOJIT ) if(NOT WIN32) target_compile_definitions(ZPaq PUBLIC unix) endif() target_include_directories( ZPaq PUBLIC "build" ) target_sources( ZPaq PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) #set_target_properties(ZPaq PROPERTIES PREFIX "") set_target_properties(ZPaq PROPERTIES OUTPUT_NAME "zpaq") # ------------------------------------------------------------------------------------------------- install( FILES ${headerFiles} DESTINATION ${PROJECT_SOURCE_DIR}/Include ) install( TARGETS ZPaq ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${NUCLEX_COMPILER_TAG} ) # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/ZPaqConfig.cmake" "#!/usr/bin/cmake # Configuration to include ZPaq in a CMake-based project. If you want to # reference ZPaq as an externally compiled static library, do this: # # set(ZPaq_DIR \"../ThirdParty/zpaq\") # find_package(ZPaq REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE ZPaq::Static # ) # # Alternatively, if you want to build ZPaq together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/zpaq\" # \"\${CMAKE_BINARY_DIR}/zpaq\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE Zpaq # ) # # ------------------------------------------------------------------------------------------------- if(NOT DEFINED NUCLEX_COMPILER_TAG) message( FATAL_ERROR \"NUCLEX_COMPILER_TAG not defined! Include cplusplus.cmake before importing this package \\ in order to generate a tag identifying the platform/compiler/architecture/variant!\" ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}\") # TODO: Warn and link release build when compiling in debug mode # TODO: Warn and link build for older compiler version if found message( FATAL_ERROR \"Directory '\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}' not found. \\ Please either build and install this project before importing it via \\ find_package() or use this project's main CMakeFiles.txt via add_subdirectory()!\" ) endif() # ------------------------------------------------------------------------------------------------- add_library(ZPaq::Static STATIC IMPORTED) # This may cause warnings on recent GCC versions (10.0.0+?) with LTO because GCC detects # that the headers used during build (residing in build/) are not the same used when # linking the library (copies resising in Include/). # # CMake doesn't run the install step during build, so the only way to get the headers # in place before building would be by copying them rather than installing them. set_target_properties( ZPaq::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"C\" ) target_compile_definitions(ZPaq::Static PUBLIC NOJIT) if(WIN32) set_target_properties( ZPaq::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/zpaq.lib\" ) else() target_compile_definitions(ZPaq::Static PUBLIC unix) set_target_properties( ZPaq::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libzpaq.a\" ) endif() message(STATUS \"Imported ZPaq targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------