From 319dd31f7ba8752683aaab2679a1c8fefcf48ef3 Mon Sep 17 00:00:00 2001 From: Clovis Durand Date: Sat, 25 Apr 2020 01:53:50 +0200 Subject: [PATCH] CMake fixes + CMake search for OpenSSL (macOS) (#1383) Signed-off-by: Clovis Durand Co-authored-by: Billy Robert O'Neal III --- Build_iOS/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- README.md | 2 +- Release/CMakeLists.txt | 2 +- Release/cmake/cpprest_find_openssl.cmake | 4 +- .../cmake/cpprestsdk-config-version.in.cmake | 10 ++ Release/cmake/cpprestsdk-config.in.cmake | 2 +- Release/src/CMakeLists.txt | 9 +- azure-devops/build-windows.yml | 5 - azure-pipelines.yml | 162 +++++++++--------- 10 files changed, 106 insertions(+), 94 deletions(-) create mode 100644 Release/cmake/cpprestsdk-config-version.in.cmake diff --git a/Build_iOS/CMakeLists.txt b/Build_iOS/CMakeLists.txt index 0cf1b62467..f5c5bae75a 100644 --- a/Build_iOS/CMakeLists.txt +++ b/Build_iOS/CMakeLists.txt @@ -1,5 +1,5 @@ project(casablanca-ios NONE) -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.9) enable_testing() diff --git a/CMakeLists.txt b/CMakeLists.txt index d010e21fcd..4e0377ef27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.9) project(cpprestsdk-root NONE) enable_testing() add_subdirectory(Release) diff --git a/README.md b/README.md index 09cf148dcf..a1f46ab4fb 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Once you have the library, look at our [tutorial](https://github.com/Microsoft/c To use from CMake: ```cmake -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.9) project(main) find_package(cpprestsdk REQUIRED) diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt index 18b0cb3f48..e495bd391b 100644 --- a/Release/CMakeLists.txt +++ b/Release/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0) -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.9) if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) # use MACOSX_RPATH endif() diff --git a/Release/cmake/cpprest_find_openssl.cmake b/Release/cmake/cpprest_find_openssl.cmake index 57e43a2fb7..9333663607 100644 --- a/Release/cmake/cpprest_find_openssl.cmake +++ b/Release/cmake/cpprest_find_openssl.cmake @@ -34,11 +34,13 @@ function(cpprest_find_openssl) if(APPLE) if(NOT DEFINED OPENSSL_ROOT_DIR) # Prefer a homebrew version of OpenSSL over the one in /usr/lib - file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*) + file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl*/*) # Prefer the latest (make the latest one first) list(REVERSE OPENSSL_ROOT_DIR) + list(GET OPENSSL_ROOT_DIR 0 OPENSSL_ROOT_DIR) endif() # This should prevent linking against the system provided 0.9.8y + message(STATUS "OPENSSL_ROOT_DIR = ${OPENSSL_ROOT_DIR}") set(_OPENSSL_VERSION "") endif() if(UNIX) diff --git a/Release/cmake/cpprestsdk-config-version.in.cmake b/Release/cmake/cpprestsdk-config-version.in.cmake new file mode 100644 index 0000000000..017879c58f --- /dev/null +++ b/Release/cmake/cpprestsdk-config-version.in.cmake @@ -0,0 +1,10 @@ +set(PACKAGE_VERSION @CPPREST_VERSION_MAJOR@.@CPPREST_VERSION_MINOR@.@CPPREST_VERSION_REVISION@) + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) +endif(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) diff --git a/Release/cmake/cpprestsdk-config.in.cmake b/Release/cmake/cpprestsdk-config.in.cmake index be95abf99a..72476b062d 100644 --- a/Release/cmake/cpprestsdk-config.in.cmake +++ b/Release/cmake/cpprestsdk-config.in.cmake @@ -15,7 +15,7 @@ if(@CPPREST_USES_WINHTTPPAL@) find_dependency(WINHTTPPAL) endif() -if(@CPPREST_USES_BOOST@ AND OFF) +if(@CPPREST_USES_BOOST@) if(UNIX) find_dependency(Boost COMPONENTS random system thread filesystem chrono atomic date_time regex) else() diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt index 1c40257c47..a2d4d30b64 100644 --- a/Release/src/CMakeLists.txt +++ b/Release/src/CMakeLists.txt @@ -236,9 +236,9 @@ else() endif() if(CPPREST_INSTALL_HEADERS) - install(FILES ${HEADERS_CPPREST} DESTINATION include/cpprest) - install(FILES ${HEADERS_PPLX} DESTINATION include/pplx) - install(FILES ${HEADERS_DETAILS} DESTINATION include/cpprest/details) + install(FILES ${HEADERS_CPPREST} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpprest) + install(FILES ${HEADERS_PPLX} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pplx) + install(FILES ${HEADERS_DETAILS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpprest/details) endif() if(CPPREST_INSTALL) @@ -281,9 +281,10 @@ if(CPPREST_INSTALL) ) configure_file(../cmake/cpprestsdk-config.in.cmake "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake" @ONLY) + configure_file(../cmake/cpprestsdk-config-version.in.cmake "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config-version.cmake" @ONLY) install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake" + FILES "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPPREST_EXPORT_DIR} ) install( diff --git a/azure-devops/build-windows.yml b/azure-devops/build-windows.yml index 2a5de3c509..45045ee907 100644 --- a/azure-devops/build-windows.yml +++ b/azure-devops/build-windows.yml @@ -13,11 +13,6 @@ jobs: steps: - script: git submodule update --init vcpkg displayName: Checkout vcpkg submodule - - task: CacheBeta@0 - displayName: Cache vcpkg - inputs: - key: $(vcpkgResponseFile) | $(Build.SourcesDirectory)/.git/modules/vcpkg/HEAD | ${{ parameters.targetPlatform }} | ${{ parameters.image }} - path: '$(vcpkgLocation)' - task: run-vcpkg@0 displayName: 'Run vcpkg' inputs: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 05f20d6f80..7df61d453a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -68,85 +68,89 @@ jobs: export NCPU=2 ../configure.sh --ndk /usr/local/lib/android/sdk/ndk-bundle displayName: 'Build for Android' - # - job: MacOS_Homebrew - # pool: - # vmImage: 'macOS-latest' - # steps: - # - script: brew install boost openssl ninja - # displayName: Brew install dependencies - # - script: | - # mkdir build.debug - # mkdir build.release - # mkdir build.release.static - # displayName: Make Build Directories - # - task: CMake@1 - # inputs: - # workingDirectory: 'build.debug' - # cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug ..' - # - task: CMake@1 - # inputs: - # workingDirectory: 'build.release' - # cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Release ..' - # - task: CMake@1 - # inputs: - # workingDirectory: 'build.release.static' - # cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF ..' - # - script: | - # cd build.debug - # ninja - # displayName: 'Run ninja, debug' - # - script: | - # cd build.debug/Release/Binaries - # ./test_runner *test.dylib - # displayName: 'Run tests, debug' - # - script: | - # cd build.release - # ninja - # displayName: 'Run ninja, release' - # - script: | - # cd build.release/Release/Binaries - # ./test_runner *test.dylib - # displayName: 'Run tests, release' - # - script: | - # cd build.release.static - # ninja - # displayName: 'Run ninja, release static' - # - job: MacOS_Vcpkg - # pool: - # vmImage: 'macOS-latest' - # steps: - # - script: | - # ./vcpkg/bootstrap-vcpkg.sh - # ./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli --vcpkg-root ./vcpkg - # displayName: Vcpkg install dependencies - # - script: | - # mkdir build.debug - # mkdir build.release - # displayName: Make Build Directories - # - task: CMake@1 - # inputs: - # workingDirectory: 'build.debug' - # cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - # - task: CMake@1 - # inputs: - # workingDirectory: 'build.release' - # cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - # - script: | - # cd build.debug - # ninja - # displayName: 'Run ninja debug' - # - script: | - # cd build.debug/Release/Binaries - # ./test_runner *test.dylib - # displayName: 'Run Tests debug' - # - script: | - # cd build.release - # ninja - # displayName: 'Run ninja, release' - # - script: | - # cd build.release/Release/Binaries - # ./test_runner *test.dylib - # displayName: 'Run tests, release' + - job: MacOS_Homebrew + pool: + vmImage: 'macOS-latest' + steps: + - script: brew install boost openssl ninja + displayName: Brew install dependencies + - script: git submodule update --init Release/libs/websocketpp + displayName: Checkout websocketpp submodule + - script: | + mkdir build.debug + mkdir build.release + mkdir build.release.static + displayName: Make Build Directories + - task: CMake@1 + inputs: + workingDirectory: 'build.debug' + cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug ..' + - task: CMake@1 + inputs: + workingDirectory: 'build.release' + cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Release ..' + - task: CMake@1 + inputs: + workingDirectory: 'build.release.static' + cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF ..' + - script: | + cd build.debug + ninja + displayName: 'Run ninja, debug' + - script: | + cd build.debug/Release/Binaries + ./test_runner *test.dylib + displayName: 'Run tests, debug' + - script: | + cd build.release + ninja + displayName: 'Run ninja, release' + - script: | + cd build.release/Release/Binaries + ./test_runner *test.dylib + displayName: 'Run tests, release' + - script: | + cd build.release.static + ninja + displayName: 'Run ninja, release static' + - job: MacOS_Vcpkg + pool: + vmImage: 'macOS-latest' + steps: + - script: git submodule update --init vcpkg + displayName: Checkout vcpkg submodule + - script: | + ./vcpkg/bootstrap-vcpkg.sh + ./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli --vcpkg-root ./vcpkg + displayName: Vcpkg install dependencies + - script: | + mkdir build.debug + mkdir build.release + displayName: Make Build Directories + - task: CMake@1 + inputs: + workingDirectory: 'build.debug' + cmakeArgs: '-G Ninja -DCMAKE_MAKE_PROGRAM=$(Build.SourcesDirectory)/vcpkg/downloads/tools/ninja-1.10.0-osx/ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + - task: CMake@1 + inputs: + workingDirectory: 'build.release' + cmakeArgs: '-G Ninja -DCMAKE_MAKE_PROGRAM=$(Build.SourcesDirectory)/vcpkg/downloads/tools/ninja-1.10.0-osx/ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + - script: | + cd build.debug + $(Build.SourcesDirectory)/vcpkg/downloads/tools/ninja-1.10.0-osx/ninja + displayName: 'Run ninja debug' + - script: | + cd build.debug/Release/Binaries + ./test_runner *test.dylib + displayName: 'Run Tests debug' + - script: | + cd build.release + $(Build.SourcesDirectory)/vcpkg/downloads/tools/ninja-1.10.0-osx/ninja + displayName: 'Run ninja, release' + - script: | + cd build.release/Release/Binaries + ./test_runner *test.dylib + displayName: 'Run tests, release' # - job: MacOS_iOS # pool: # vmImage: 'macOS-latest'