#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( Bsc VERSION 3.1.0 DESCRIPTION "Experimental compression algorithm achieving high compression ratios" ) include("../../BuildSystem/cmake/cplusplus.cmake") set(BUILD_CMD OFF CACHE BOOL "Whether to build a command-line bsc-cmd tool") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/3.1.0.tar.gz) message(STATUS "Downloading Bsc sources") file( DOWNLOAD https://devel.nuclex.org/internal/svn/third-party/bsc/tags/3.1.0/downloads/3.1.0.tar.gz ${PROJECT_SOURCE_DIR}/downloads/3.1.0.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=64a290c14640f3bb95acc2954661fe98d55d440c78c39b932926b94082f4f804 ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting Bsc sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/3.1.0.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/libbsc-3.1.0 ${PROJECT_SOURCE_DIR}/build ) endif() # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/libbsc/adler32/adler32.cpp" "build/libbsc/bwt/bwt.cpp" "build/libbsc/bwt/divsufsort/divsufsort.c" "build/libbsc/coder/coder.cpp" "build/libbsc/coder/qlfc/qlfc.cpp" "build/libbsc/coder/qlfc/qlfc_model.cpp" "build/libbsc/filters/detectors.cpp" "build/libbsc/filters/preprocessing.cpp" "build/libbsc/libbsc/libbsc.cpp" "build/libbsc/lzp/lzp.cpp" "build/libbsc/platform/platform.cpp" "build/libbsc/st/st.cpp" ) set( headerFiles "build/libbsc/adler32/adler32.h" "build/libbsc/bwt/bwt.h" "build/libbsc/bwt/divsufsort/divsufsort.h" "build/libbsc/coder/coder.h" "build/libbsc/coder/common/predictor.h" "build/libbsc/coder/common/rangecoder.h" "build/libbsc/coder/common/tables.h" "build/libbsc/coder/qlfc/qlfc.h" "build/libbsc/coder/qlfc/qlfc_model.h" "build/libbsc/filters/tables.h" "build/libbsc/filters.h" "build/libbsc/libbsc.h" "build/libbsc/lzp/lzp.h" "build/libbsc/platform/platform.h" "build/libbsc/st/st.h" ) # ------------------------------------------------------------------------------------------------- add_library(Bsc STATIC) add_library(Bsc::Static ALIAS Bsc) target_compile_definitions( Bsc PUBLIC _7Z_TYPES_ ) target_include_directories( Bsc PUBLIC "build/libbsc" ) target_sources( Bsc PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) #set_target_properties(Bsc PROPERTIES PREFIX "") set_target_properties(Bsc PROPERTIES OUTPUT_NAME "bsc") # ------------------------------------------------------------------------------------------------- if(BUILD_CMD) add_executable(Bsc-cmd) target_compile_definitions( Bsc-cmd PUBLIC _7Z_TYPES_ ) target_include_directories( Bsc-cmd PUBLIC "build/libbsc" ) target_sources( Bsc-cmd PUBLIC ${headerFiles} PRIVATE ${sourceFiles} PRIVATE "build/bsc.cpp" ) #set_target_properties(Bsc-cmd PROPERTIES PREFIX "") set_target_properties(Bsc-cmd PROPERTIES OUTPUT_NAME "bsc-cmd") endif() # ------------------------------------------------------------------------------------------------- install( FILES ${headerFiles} DESTINATION ${PROJECT_SOURCE_DIR}/Include ) install( TARGETS Bsc ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${CMAKE_COMPILER_TAG} ) if(BUILD_CMD) install( TARGETS Bsc-cmd RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/bin/${CMAKE_COMPILER_TAG} ) endif() # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/BscConfig.cmake" "#!/usr/bin/cmake # Configuration to include Bsc in a CMake-based project. If you want to # reference Bsc as an externally compiled static library, do this: # # set(Bsc_DIR \"../ThirdParty/bsc\") # find_package(Bsc REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE Bsc::Static # ) # # Alternatively, if you want to build Bsc together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/bsc\" # \"\${CMAKE_BINARY_DIR}/bsc\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE Bsc # ) # # ------------------------------------------------------------------------------------------------- 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(Bsc::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( Bsc::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"C\" ) if(WIN32) set_target_properties( Bsc::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/bsc.lib\" ) else() set_target_properties( Bsc::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libbsc.a\" ) endif() message(STATUS \"Imported Bsc targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------