winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CMakeLists.txt (5170B)


      1 # Copyright (c) Microsoft Corporation.
      2 # Licensed under the MIT License.
      3 
      4 # HTTP stack library
      5 find_package(CURL REQUIRED)
      6 
      7 # JSON library
      8 find_package(nlohmann_json CONFIG REQUIRED)
      9 
     10 # CorrelationVector Library from Microsoft
     11 find_package(correlation_vector CONFIG REQUIRED)
     12 
     13 add_library(${PROJECT_NAME} STATIC)
     14 add_library(Microsoft::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
     15 
     16 target_sources(
     17     ${PROJECT_NAME}
     18     PRIVATE src/AppContent.cpp
     19             src/AppFile.cpp
     20             src/ApplicabilityDetails.cpp
     21             src/Content.cpp
     22             src/ContentId.cpp
     23             src/details/connection/Connection.cpp
     24             src/details/connection/ConnectionConfig.cpp
     25             src/details/connection/ConnectionManager.cpp
     26             src/details/connection/CurlConnection.cpp
     27             src/details/connection/CurlConnectionManager.cpp
     28             src/details/connection/HttpHeader.cpp
     29             src/details/connection/mock/MockConnection.cpp
     30             src/details/connection/mock/MockConnectionManager.cpp
     31             src/details/ContentUtil.cpp
     32             src/details/CorrelationVector.cpp
     33             src/details/entity/ContentType.cpp
     34             src/details/entity/FileEntity.cpp
     35             src/details/entity/VersionEntity.cpp
     36             src/details/Env.cpp
     37             src/details/ErrorHandling.cpp
     38             src/details/OSInfo.cpp
     39             src/details/ReportingHandler.cpp
     40             src/details/SFSClientImpl.cpp
     41             src/details/SFSException.cpp
     42             src/details/SFSUrlBuilder.cpp
     43             src/details/TestOverride.cpp
     44             src/details/UrlBuilder.cpp
     45             src/details/Util.cpp
     46             src/File.cpp
     47             src/Logging.cpp
     48             src/Result.cpp
     49             src/SFSClient.cpp)
     50 
     51 # Include dir for the library depends on whether the library is being built or
     52 # if it was installed
     53 target_include_directories(
     54     ${PROJECT_NAME}
     55     PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/sfsclient>
     56            $<INSTALL_INTERFACE:include> # <prefix>/include
     57 )
     58 
     59 target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
     60 target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json)
     61 target_link_libraries(${PROJECT_NAME} PRIVATE microsoft::correlation_vector)
     62 
     63 # Pick up git revision during configuration to add to logging
     64 include(FindGit)
     65 if(GIT_FOUND)
     66     execute_process(
     67         COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
     68         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     69         OUTPUT_VARIABLE SFS_GIT_HEAD_NAME
     70         OUTPUT_STRIP_TRAILING_WHITESPACE)
     71     execute_process(
     72         COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
     73         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     74         OUTPUT_VARIABLE SFS_GIT_HEAD_REVISION
     75         OUTPUT_STRIP_TRAILING_WHITESPACE)
     76 
     77     target_compile_definitions(
     78         ${PROJECT_NAME}
     79         PRIVATE SFS_GIT_INFO="${SFS_GIT_HEAD_NAME}:${SFS_GIT_HEAD_REVISION}")
     80 endif()
     81 
     82 set_compile_options_for_target(${PROJECT_NAME})
     83 
     84 target_compile_definitions(${PROJECT_NAME}
     85                            PRIVATE SFS_VERSION="${SFS_LIBRARY_VERSION}")
     86 
     87 if(SFS_ENABLE_TEST_OVERRIDES)
     88     target_compile_definitions(${PROJECT_NAME}
     89                                PRIVATE SFS_ENABLE_TEST_OVERRIDES=1)
     90 endif()
     91 
     92 if(SFS_BUILD_TESTS)
     93     # Enables one to run tests through "ctest --test-dir .\build\client"
     94     enable_testing()
     95 
     96     add_subdirectory(tests)
     97 endif()
     98 
     99 #
    100 # Install section
    101 #
    102 
    103 set(_INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sfsclient")
    104 set(_TARGET_CONFIG_CMAKE_FILEPATH
    105     "${CMAKE_CURRENT_BINARY_DIR}/sfsclient-config.cmake")
    106 
    107 # Install headers
    108 install(
    109     FILES include/sfsclient/AppContent.h
    110           include/sfsclient/AppFile.h
    111           include/sfsclient/ApplicabilityDetails.h
    112           include/sfsclient/ClientConfig.h
    113           include/sfsclient/Content.h
    114           include/sfsclient/ContentId.h
    115           include/sfsclient/File.h
    116           include/sfsclient/Logging.h
    117           include/sfsclient/RequestParams.h
    118           include/sfsclient/Result.h
    119           include/sfsclient/SFSClient.h
    120     DESTINATION include/sfsclient)
    121 
    122 # Export targets for this library to a local file
    123 install(
    124     TARGETS ${PROJECT_NAME}
    125     EXPORT sfsclient-targets
    126     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    127     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    128     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
    129 
    130 # And then install the exported targets file to the destination
    131 install(
    132     EXPORT sfsclient-targets
    133     FILE sfsclient-targets.cmake
    134     NAMESPACE microsoft::
    135     DESTINATION ${_INSTALL_DESTINATION})
    136 
    137 # Add configure_package_config_file for below
    138 include(CMakePackageConfigHelpers)
    139 
    140 # Create the sfsclient-config.cmake file, which will be used by find_package()
    141 configure_package_config_file(
    142     ../cmake/sfsclient-config.cmake.in ${_TARGET_CONFIG_CMAKE_FILEPATH}
    143     INSTALL_DESTINATION ${_INSTALL_DESTINATION})
    144 
    145 # Then install the generated file to the destination
    146 install(FILES ${_TARGET_CONFIG_CMAKE_FILEPATH}
    147         DESTINATION ${_INSTALL_DESTINATION})