From b80d41c327d80cfd5fcbacd4030f0d4cfba6a782 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 29 Jan 2023 14:10:39 +0100 Subject: [PATCH] Use `CMakeDeps` and `CMakeToolchain` as Generators on Conan (#4335) * deps(conan): use `CMakeDeps` as generator * chore: add changelog entry * deps(conan): add `CMakeToolchain` generator * fix: use generated toolchain file * docs: mention toolchain as well * fix: spelling * fix: formatting * revert: use nmake * docs: fix documentation --- .github/workflows/build.yml | 10 ++++++++-- BUILDING_ON_WINDOWS.md | 4 ++-- CHANGELOG.md | 3 ++- CMakeLists.txt | 19 ++++++------------- conanfile.txt | 3 ++- src/CMakeLists.txt | 18 ++---------------- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83a192792..92d9c5372 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,16 +85,22 @@ jobs: if: startsWith(matrix.os, 'windows') uses: ilammy/msvc-dev-cmd@v1.12.0 + - name: Setup Conan (Windows) + if: startsWith(matrix.os, 'windows') + run: | + conan profile new --detect --force default + conan profile update conf.tools.cmake.cmaketoolchain:generator="NMake Makefiles" default + - name: Build (Windows) if: startsWith(matrix.os, 'windows') run: | mkdir build cd build - conan install .. -b missing + conan install .. -s build_type=Release -b missing -pr:b=default cmake ` -G"NMake Makefiles" ` -DCMAKE_BUILD_TYPE=Release ` - -DUSE_CONAN=ON ` + -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" ` -DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" ` .. set cl=/MP diff --git a/BUILDING_ON_WINDOWS.md b/BUILDING_ON_WINDOWS.md index cf5fd67cd..ef16c1457 100644 --- a/BUILDING_ON_WINDOWS.md +++ b/BUILDING_ON_WINDOWS.md @@ -131,7 +131,7 @@ Open up your terminal with the Visual Studio environment variables, then enter t 1. `mkdir build` 2. `cd build` -3. `cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_CONAN=ON ..` +3. `cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" ..` 4. `nmake` ## Building on MSVC with AddressSanitizer @@ -160,7 +160,7 @@ Now open the project in CLion. You will be greeted with the _Open Project Wizard ``` -DCMAKE_PREFIX_PATH=C:\Qt\5.15.2\msvc2019_64\lib\cmake\Qt5 --DUSE_CONAN=ON +-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" ``` and the _Build Directory_ to `build`. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4fc4647..fd9a054f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,8 @@ - Dev: Fixed `final-dtor-non-final-class` warnings. (#4296) - Dev: Fixed `ambiguous-reversed-operator` warnings. (#4296) - Dev: Format YAML and JSON files with prettier. (#4304) -- Dev: Addded CMake Install Support on Windows. (#4300) +- Dev: Added CMake Install Support on Windows. (#4300) +- Dev: Changed conan generator to [`CMakeDeps`](https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmakedeps.html) and [`CMakeToolchain`](https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmaketoolchain.html). See PR for migration notes. (#4335) ## 2.4.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index b36e0eb7b..53c0294f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ -cmake_minimum_required(VERSION 3.12) -cmake_policy(SET CMP0087 NEW) +cmake_minimum_required(VERSION 3.15) +cmake_policy(SET CMP0087 NEW) # evaluates generator expressions in `install(CODE/SCRIPT)` +cmake_policy(SET CMP0091 NEW) # select MSVC runtime library through `CMAKE_MSVC_RUNTIME_LIBRARY` include(FeatureSummary) list(APPEND CMAKE_MODULE_PATH @@ -24,8 +25,6 @@ option(BUILD_TRANSLATIONS "" OFF) option(BUILD_SHARED_LIBS "" OFF) option(CHATTERINO_LTO "Enable LTO for all targets" OFF) -option(USE_CONAN "Use conan" OFF) - if(CHATTERINO_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR) @@ -40,13 +39,6 @@ else() set(MAJOR_QT_VERSION "5") endif() -if (USE_CONAN OR CONAN_EXPORTED) - include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake) - conan_basic_setup(TARGETS NO_OUTPUT_DIRS) -else () - set(QT_CREATOR_SKIP_CONAN_SETUP ON) -endif() - find_program(CCACHE_PROGRAM ccache) if (CCACHE_PROGRAM) set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") @@ -75,8 +67,9 @@ endif () find_package(Sanitizers) # Find boost on the system -find_package(Boost REQUIRED) -find_package(Boost COMPONENTS random) +# `OPTIONAL_COMPONENTS random` is required for vcpkg builds to link. +# `OPTIONAL` is required, because conan doesn't set `boost_random_FOUND`. +find_package(Boost REQUIRED OPTIONAL_COMPONENTS random) # Find OpenSSL on the system find_package(OpenSSL REQUIRED) diff --git a/conanfile.txt b/conanfile.txt index 2b96b3fac..52f1d9109 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -3,7 +3,8 @@ openssl/1.1.1s boost/1.80.0 [generators] -cmake +CMakeDeps +CMakeToolchain [options] openssl:shared=True diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c9e2a7f8..64c2764f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -809,30 +809,16 @@ if (WinToast_FOUND) WinToast) endif () -if (USE_CONAN AND TARGET CONAN_PKG::boost) - target_link_libraries(${LIBRARY_PROJECT} - PUBLIC - CONAN_PKG::boost - ) -else () - target_link_libraries(${LIBRARY_PROJECT} +target_link_libraries(${LIBRARY_PROJECT} PUBLIC ${Boost_LIBRARIES} ) -endif () -if (USE_CONAN AND TARGET CONAN_PKG::openssl) - target_link_libraries(${LIBRARY_PROJECT} - PUBLIC - CONAN_PKG::openssl - ) -else () - target_link_libraries(${LIBRARY_PROJECT} +target_link_libraries(${LIBRARY_PROJECT} PUBLIC OpenSSL::SSL OpenSSL::Crypto ) -endif () target_include_directories(${LIBRARY_PROJECT} PUBLIC ${RapidJSON_INCLUDE_DIRS})