#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( Zopfli VERSION 1.0.3 DESCRIPTION "Improved deflate implementation compatible with ZLib" ) include("../../BuildSystem/cmake/cplusplus.cmake") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/zopfli-1.0.3.tar.gz) message(STATUS "Downloading Zopfli sources") file( DOWNLOAD https://github.com/google/zopfli/archive/zopfli-1.0.3.tar.gz ${PROJECT_SOURCE_DIR}/downloads/zopfli-1.0.3.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=e955a7739f71af37ef3349c4fa141c648e8775bceb2195be07e86f8e638814bd ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting Zopfli sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/zopfli-1.0.3.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/zopfli-zopfli-1.0.3 ${PROJECT_SOURCE_DIR}/build ) endif() # ------------------------------------------------------------------------------------------------- # "build/src/zopfli/gzip_container.c" # "build/src/zopfli/zlib_container.c" # "build/src/zopfli/zopfli_bin.c" # "build/src/zopfli/zopfli_lib.c" set( sourceFiles "build/src/zopfli/blocksplitter.c" "build/src/zopfli/cache.c" "build/src/zopfli/deflate.c" "build/src/zopfli/hash.c" "build/src/zopfli/katajainen.c" "build/src/zopfli/lz77.c" "build/src/zopfli/squeeze.c" "build/src/zopfli/tree.c" "build/src/zopfli/util.c" ) set( headerFiles "build/src/zopfli/blocksplitter.h" "build/src/zopfli/cache.h" "build/src/zopfli/deflate.h" "build/src/zopfli/hash.h" "build/src/zopfli/katajainen.h" "build/src/zopfli/lz77.h" "build/src/zopfli/squeeze.h" "build/src/zopfli/symbols.h" "build/src/zopfli/tree.h" "build/src/zopfli/util.h" "build/src/zopfli/zopfli.h" ) # ------------------------------------------------------------------------------------------------- add_library(Zopfli STATIC) if(NOT WIN32) target_compile_definitions( Zopfli PUBLIC OS_LINUX ) endif() target_include_directories( Zopfli PUBLIC "build/src/zopfli" ) target_sources( Zopfli PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) #set_target_properties(Zopfli PROPERTIES PREFIX "") set_target_properties(Zopfli PROPERTIES OUTPUT_NAME "zopfli") # ------------------------------------------------------------------------------------------------- install( FILES ${headerFiles} DESTINATION ${PROJECT_SOURCE_DIR}/Include ) install( TARGETS Zopfli ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${CMAKE_COMPILER_TAG} ) add_library(Zopfli::Static ALIAS Zopfli) # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/ZopfliConfig.cmake" "#!/usr/bin/cmake # Configuration to include Zopfli in a CMake-based project. If you want to # reference Zopfli as an externally compiled static library, do this: # # set(Zopfli_DIR \"../ThirdParty/zopfli\") # find_package(Zopfli REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE Zopfli::Static # ) # # Alternatively, if you want to build Zopfli together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/zopfli\" # \"\${CMAKE_BINARY_DIR}/zopfli\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE Zopfli # ) # # ------------------------------------------------------------------------------------------------- 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(Zopfli::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( Zopfli::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"C\" ) if(WIN32) set_target_properties( Zopfli::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/zopfli.lib\" ) else() set_target_properties( Zopfli::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libzopfli.a\" ) endif() message(STATUS \"Imported Zopfli targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------