### Install Library Targets and Headers Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This installs the Miniz library targets (runtime, archive, library) and header files. The installation is conditional on INSTALL_PROJECT and specifies destinations for each component. ```cmake if(INSTALL_PROJECT) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # users can use or INCLUDES DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ) endif() ``` -------------------------------- ### Add Example Executables Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This section adds several example executables to the build. Each executable is defined using add_executable and linked against the 'miniz' library. Some examples are conditional on build flags. ```cmake add_executable(example1 ${EXAMPLE1_SRC_LIST}) target_link_libraries(example1 miniz) if(NOT BUILD_NO_STDIO) add_executable(example2 ${EXAMPLE2_SRC_LIST}) target_link_libraries(example2 miniz) endif() add_executable(example3 ${EXAMPLE3_SRC_LIST}) target_link_libraries(example3 miniz) add_executable(example4 ${EXAMPLE4_SRC_LIST}) target_link_libraries(example4 miniz) add_executable(example5 ${EXAMPLE5_SRC_LIST}) target_link_libraries(example5 miniz) add_executable(example6 ${EXAMPLE6_SRC_LIST}) target_link_libraries(example6 miniz) if(${UNIX}) target_link_libraries(example6 m) endif() ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This installs the generated Miniz package configuration files (Config.cmake and ConfigVersion.cmake) to the CMake package installation directory. This is conditional on INSTALL_PROJECT and assigned to the 'Devel' component. ```cmake set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${ConfigPackageLocation} COMPONENT Devel ) ``` -------------------------------- ### Define Example Executable Sources Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This section defines the source file lists for various example executables (example1 through example6) and the miniz_tester.cpp. This is conditional on BUILD_EXAMPLES. ```cmake if(BUILD_EXAMPLES) set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c") set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c") set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c") set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c") set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c") set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c") set(MINIZ_TESTER_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp") endif() ``` -------------------------------- ### Set Include Directory and Install Headers Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Sets the include directory for installed headers and conditionally installs them if INSTALL_PROJECT is enabled. ```cmake set(INCLUDE_INSTALL_DIR "include") if(INSTALL_PROJECT) install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) endif() ``` -------------------------------- ### Install pkg-config File Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This snippet installs the generated pkg-config file to the appropriate location for the system's package manager. This is conditional on the INSTALL_PROJECT flag. ```cmake if(INSTALL_PROJECT) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() ``` -------------------------------- ### Install Exported Targets Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This installs the exported targets for the Miniz project. The targets are placed in a specified destination directory and namespace, conditional on INSTALL_PROJECT. ```cmake set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) install( EXPORT ${PROJECT_NAME}Targets FILE ${PROJECT_NAME}Targets.cmake NAMESPACE ${PROJECT_NAME}:: DESTINATION ${ConfigPackageLocation} ) ``` -------------------------------- ### Generate Basic Package Version File Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This uses CMake's write_basic_package_version_file to create a version file for the package configuration. This is part of the installation process. ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${MINIZ_VERSION} COMPATIBILITY AnyNewerVersion ) ``` -------------------------------- ### Create Miniz Zip Archive Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Custom command to create a zip archive of the Miniz project, including examples, documentation, and license files. This is useful for distributing the library. ```cmake set(INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h) file(GLOB_RECURSE ZIP_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" "${CMAKE_CURRENT_BINARY_DIR}/amalgamation/*") file(GLOB_RECURSE ZIP_FILES2 RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/examples/*") list(APPEND ZIP_FILES ${ZIP_FILES2}) list(APPEND ZIP_FILES "ChangeLog.md") list(APPEND ZIP_FILES "readme.md") list(APPEND ZIP_FILES "LICENSE") set(ZIP_OUT_FN "${CMAKE_CURRENT_BINARY_DIR}/miniz-${MINIZ_VERSION}.zip") message(STATUS "Zip files: ${ZIP_FILES}") add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/examples COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/ChangeLog.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/ChangeLog.md COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/readme.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/readme.md COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/LICENSE COMMAND ${CMAKE_COMMAND} -E tar "cf" "${ZIP_OUT_FN}" --format=zip -- ${ZIP_FILES} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" OUTPUT "${ZIP_OUT_FN}" DEPENDS ${ZIP_FILES} COMMENT "Zipping to ${CMAKE_CURRENT_BINARY_DIR}/miniz.zip." ) add_custom_target( create_zip ALL DEPENDS "${ZIP_OUT_FN}" ) ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This configures the Config.cmake.in template to generate the main package configuration file for Miniz. This file is essential for CMake to find and use the installed library. ```cmake configure_file(Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" @ONLY ) ``` -------------------------------- ### Configure pkg-config File Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This command configures the miniz.pc.in template file to generate a pkg-config file. The generated file is placed in the build directory. ```cmake configure_file(miniz.pc.in ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc @ONLY) ``` -------------------------------- ### Configure C++ Standard and Add Test Executable Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Enables C++ language support, sets the C++ standard to 20, and defines a test executable 'catch_tests'. It conditionally adds a compile definition if BUILD_NO_STDIO is set. ```cmake enable_language(CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED YES) add_executable(catch_tests tests/main.cpp tests/catch_amalgamated.cpp) if(BUILD_NO_STDIO) target_compile_definitions(catch_tests PRIVATE -DMINIZ_NO_STDIO) endif() target_link_libraries(catch_tests miniz) ``` -------------------------------- ### Build Miniz Static Library Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Configures and builds Miniz as a static library. This is the default build mode when amalgamation is not enabled. ```cmake include(GenerateExportHeader) set(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c) add_library(${PROJECT_NAME} ${miniz_SOURCE}) generate_export_header(${PROJECT_NAME}) if(NOT BUILD_SHARED_LIBS) string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER) set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE) else() set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden) endif() set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${MINIZ_VERSION}) set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${MINIZ_API_VERSION}) target_include_directories(${PROJECT_NAME} PUBLIC $ $ $ ) ``` -------------------------------- ### Enable Testing and Add Test Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Enables the CMake testing framework and adds a test named 'catch_tests' that executes the compiled test program. ```cmake enable_testing() add_test(NAME catch_tests COMMAND $) ``` -------------------------------- ### Add Executable for Fuzzer Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Defines an executable for a fuzzer target. Links the 'miniz' library to it. ```cmake add_executable(checksum_fuzzer ${CHECKSUM_FUZZER_SRC_LIST}) target_link_libraries(checksum_fuzzer miniz) ``` ```cmake add_executable(flush_fuzzer ${FLUSH_FUZZER_SRC_LIST}) target_link_libraries(flush_fuzzer miniz) ``` ```cmake add_executable(uncompress_fuzzer ${UNCOMPRESS_FUZZER_SRC_LIST}) target_link_libraries(uncompress_fuzzer miniz) ``` ```cmake add_executable(uncompress2_fuzzer ${UNCOMPRESS2_FUZZER_SRC_LIST}) target_link_libraries(uncompress2_fuzzer miniz) ``` ```cmake add_executable(compress_fuzzer ${COMPRESS_FUZZER_SRC_LIST}) target_link_libraries(compress_fuzzer miniz) ``` ```cmake add_executable(small_fuzzer ${SMALL_FUZZER_SRC_LIST}) target_link_libraries(small_fuzzer miniz) ``` ```cmake add_executable(large_fuzzer ${LARGE_FUZZER_SRC_LIST}) target_link_libraries(large_fuzzer miniz) ``` ```cmake add_executable(zip_fuzzer ${ZIP_FUZZER_SRC_LIST}) target_link_libraries(zip_fuzzer miniz) ``` ```cmake add_executable(add_in_place_fuzzer ${ADD_IN_PLACE_FUZZER_SRC_LIST}) target_link_libraries(add_in_place_fuzzer miniz) ``` -------------------------------- ### Amalgamate Miniz Sources Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt Copies and concatenates Miniz source and header files into single amalgamated files for easier integration. This process removes include directives and adds necessary defines. ```cmake file(COPY miniz.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/) file(READ miniz.h MINIZ_H) file(READ miniz_common.h MINIZ_COMMON_H) file(READ miniz_tdef.h MINIZ_TDEF_H) file(READ miniz_tinfl.h MINIZ_TINFL_H) file(READ miniz_zip.h MINIZ_ZIP_H) file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${MINIZ_COMMON_H} ${MINIZ_TDEF_H} ${MINIZ_TINFL_H} ${MINIZ_ZIP_H}") file(COPY miniz.c DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/) file(READ miniz_tdef.c MINIZ_TDEF_C) file(READ miniz_tinfl.c MINIZ_TINFL_C) file(READ miniz_zip.c MINIZ_ZIP_C) file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c "${MINIZ_TDEF_C} ${MINIZ_TINFL_C} ${MINIZ_ZIP_C}") file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h AMAL_MINIZ_H) file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c AMAL_MINIZ_C) foreach(REPLACE_STRING miniz;miniz_common;miniz_tdef;miniz_tinfl;miniz_zip;miniz_export) string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_H "${AMAL_MINIZ_H}") string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_C "${AMAL_MINIZ_C}") endforeach() string(CONCAT AMAL_MINIZ_H "#ifndef MINIZ_EXPORT\n#define MINIZ_EXPORT\n#endif\n" "${AMAL_MINIZ_H}") ``` ```cmake if(BUILD_HEADER_ONLY) string(CONCAT AMAL_MINIZ_H "${AMAL_MINIZ_H}" "\n#ifndef MINIZ_HEADER_FILE_ONLY\n" "${AMAL_MINIZ_C}" "\n#endif // MINIZ_HEADER_FILE_ONLY\n") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}") add_library(${PROJECT_NAME} INTERFACE) # Might not be a good idea to force this on the library user # as it could bloat the global namespace # https://github.com/libevent/libevent/issues/460 # target_compile_definitions(${PROJECT_NAME} # INTERFACE $<\:_GNU_SOURCE>) set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ $ ) else(BUILD_HEADER_ONLY) string(CONCAT AMAL_MINIZ_C "#include \"miniz.h\"\n" "${AMAL_MINIZ_C}") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c "${AMAL_MINIZ_C}") set(miniz_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c) add_library(${PROJECT_NAME} STATIC ${miniz_SOURCE}) target_include_directories(${PROJECT_NAME} PUBLIC $ $ ) endif(BUILD_HEADER_ONLY) ``` -------------------------------- ### Export Targets for Package Configuration Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This exports the project's targets for use in package configuration files. It specifies a file name, namespace, and destination for the exported targets. ```cmake export(EXPORT ${PROJECT_NAME}Targets FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake" NAMESPACE ${PROJECT_NAME}:: ) ``` -------------------------------- ### Define MINIZ_NO_STDIO Compile Definition Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This snippet defines the MINIZ_NO_STDIO preprocessor macro. This is used to build Miniz without standard I/O functions, conditional on the BUILD_NO_STDIO flag. ```cmake if(BUILD_NO_STDIO) target_compile_definitions(${PROJECT_NAME} PRIVATE MINIZ_NO_STDIO) endif() ``` -------------------------------- ### Set Compatible Interface String Property Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This sets the COMPATIBLE_INTERFACE_STRING property for the target. This is used to specify compatibility information for the library interface. ```cmake set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION ) ``` -------------------------------- ### Set Target Interface Version Property Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This sets the INTERFACE_MINIZ_MAJOR_VERSION property for the target. This is used for versioning the library interface. ```cmake set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${MINIZ_API_VERSION}) ``` -------------------------------- ### Define GNU Source Macro for GNU Compilers Source: https://github.com/richgel999/miniz/blob/master/CMakeLists.txt This snippet conditionally defines the _GNU_SOURCE macro for the GNU compiler ID. This is typically used to enable GNU-specific extensions. ```cmake target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:_GNU_SOURCE>) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.