### Installing hiredis-vip Library and Headers with CMake Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/h/hiredis-vip/port/cmakelists.txt This section details the installation process for hiredis-vip. It installs header files, directories, the library itself (archive, library, runtime), and exports targets for CMake integration. ```cmake install(DIRECTORY adapters DESTINATION include/hiredis-vip ) install(FILES hiredis.h async.h read.h sds.h hiutil.h hiarray.h dict.h adlist.h fmacros.h hircluster.h DESTINATION include/hiredis-vip ) install(TARGETS hiredis_vip EXPORT hiredis_vipTargets ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### Generating and Installing Pkgconfig File with CMake Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/h/hiredis-vip/port/cmakelists.txt This CMake snippet configures the generation of a hiredis_vip.pc file from a template and installs it into the pkgconfig directory. This allows other projects to easily find and link against hiredis-vip. ```cmake configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/hiredis_vip.pc.in ${CMAKE_CURRENT_BINARY_DIR}/hiredis_vip.pc @ONLY ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_vip.pc DESTINATION lib/pkgconfig) ``` -------------------------------- ### CMake Header Installation Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/m/marisa/port/CMakeLists.txt Installs the main Marisa header file and all other Marisa header files from the 'include/marisa' directory into the appropriate system include paths. ```cmake install(FILES "${PROJECT_SOURCE_DIR}/include/marisa.h" DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}) file(GLOB marisa_other_header_files ${PROJECT_SOURCE_DIR}/include/marisa/*.h) install(FILES ${marisa_other_header_files} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/marisa) ``` -------------------------------- ### Create Package Template from GitHub using xmake Source: https://github.com/xmake-io/xmake-repo/blob/dev/README.md Installs the gh CLI, logs in to GitHub, and creates a package configuration file (xmake.lua) from a GitHub repository. Requires the gh CLI and xmake to be installed. ```console gh auth login ``` ```console xmake l scripts/new.lua github:glennrp/libpng ``` -------------------------------- ### Installing Headers and Package Configuration File (CMake) Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/g/gnu-gsl/cmake/cmakelists.txt This CMake script handles the installation of public headers, including the generated 'gsl_types.h'. It also configures and installs the 'gsl.pc' file for pkg-config, specifying destinations for runtime, libraries, archives, and headers. ```cmake file(GLOB_RECURSE PUBLIC_HEADERS gsl*.h) list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/gsl_types.h) # The debug libraries have a "d" postfix so that CMake's FindGSL.cmake # module can distinguish between Release and Debug libraries set(CMAKE_DEBUG_POSTFIX "d") if(INSTALL_HEADERS) set_target_properties(gsl PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") endif() # For the build, we need to copy all headers to the gsl directory file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gsl) file(COPY ${PUBLIC_HEADERS} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gsl") set(TARGET_INSTALL_OPTIONS) if(INSTALL_HEADERS) set(TARGET_INSTALL_OPTIONS PUBLIC_HEADER DESTINATION include/gsl) endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/gsl.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/gsl.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gsl.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(TARGETS gsl gslcblas RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ${TARGET_INSTALL_OPTIONS} ) ``` -------------------------------- ### Base64 Library Target and Installation Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/t/turbobase64/port/CMakeLists.txt Defines the main `base64` library target (either static or shared) and links the previously created object libraries to it. It also handles potential compatibility issues with Xcode and installs the library and header files. ```cmake if(BUILD_SHARED_LIBS) add_library(base64 SHARED) else() add_library(base64 STATIC) endif() foreach(_obj ${_b64_objs}) set_target_properties(${_obj} PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) target_sources(base64 PRIVATE $) endforeach() # The XCODE fix is from https://github.com/ClickHouse/ClickHouse/blob/cf7d354a693f15fc5941edbf39e295d0bf8de21c/contrib%2Fbase64-cmake%2FCMakeLists.txt#L46-L54 if(XCODE OR XCODE_VERSION) # https://gitlab.kitware.com/cmake/cmake/issues/17457 # Some native build systems may not like targets that have only object files, so consider adding at least one real source file # This applies to Xcode. if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/dummy.c") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.c" "") endif() target_sources(base64 PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dummy.c") endif() if(BUILD_APP) add_executable(tb64app tb64app.c) target_link_libraries(tb64app base64) endif() # Set package information. set(PACKAGE_NAME ${PROJECT_NAME}) set(PACKAGE_NAMESPACE "turbo::") # For CMAKE_INSTALL_ležitDIR etc. include(GNUInstallDirs) set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}") # Please refer "Modern CMake" on how to install a library. # https://cliutils.gitlab.io/modern-cmake/chapters/install/installing.html # Also refer to cmake documentation # https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html # Set PUBLIC_HEADER property for install(TARGETS) to install header file. set_target_properties(base64 PROPERTIES PUBLIC_HEADER "${CMAKE_SOURCE_DIR}/turbob64.h") # Set includes destination for install(TARGETS), which will be added # to INTERFACE_INCLUDE_DIRECTORIES target property. # So user only need to call "target_link_libraries(turbo::base64)", without # needing to set include directories. target_include_directories( base64 SYSTEM PUBLIC $ # For being used from add_subdirectory. $ # When being used from an installation. ) # Installs library along with header files. # Also associates the installed target files with an export. install( TARGETS base64 EXPORT ${PACKAGE_NAME}-targets PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}" ) # Generates and installs cmake config files containing exported targets. install( EXPORT ${PACKAGE_NAME}-targets DESTINATION "${CONFIG_INSTALL_DIR}" NAMESPACE ${PACKAGE_NAMESPACE} ) ``` -------------------------------- ### CMake Tool Executable Builds Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/m/marisa/port/CMakeLists.txt Conditionally builds command-line tools if BUILD_TOOLS is ON. It defines a list of tool names, creates an object library for 'cmdopt', and then compiles each tool executable, linking them against 'marisa' and 'cmdopt', and installs them. ```cmake if(BUILD_TOOLS) add_library(cmdopt OBJECT "${PROJECT_SOURCE_DIR}/tools/cmdopt.cc") set(TOOLS marisa-benchmark marisa-build marisa-common-prefix-search marisa-dump marisa-lookup marisa-predictive-search marisa-reverse-lookup ) foreach(TOOL ${TOOLS}) add_executable(${TOOL} "${PROJECT_SOURCE_DIR}/tools/${TOOL}.cc") target_link_libraries(${TOOL} PRIVATE marisa cmdopt) install(TARGETS ${TOOL} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) endforeach(TOOL) endif() ``` -------------------------------- ### CMake Project Setup and Options Source: https://github.com/xmake-io/xmake-repo/blob/dev/packages/t/turbobase64/port/CMakeLists.txt Initializes the CMake project, sets the build type, and defines various build options such as shared libraries, error checking levels, AVX512 support, and application building. These options control various aspects of the build process and can be toggled via CMake command-line arguments. ```cmake cmake_minimum_required(VERSION 3.15) project(turbobase64 C) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() # Run cmake -D