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
This commit is contained in:
nerix 2023-01-29 14:10:39 +01:00 committed by GitHub
parent 6a4f0befd4
commit b80d41c327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 35 deletions

View file

@ -85,16 +85,22 @@ jobs:
if: startsWith(matrix.os, 'windows') if: startsWith(matrix.os, 'windows')
uses: ilammy/msvc-dev-cmd@v1.12.0 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) - name: Build (Windows)
if: startsWith(matrix.os, 'windows') if: startsWith(matrix.os, 'windows')
run: | run: |
mkdir build mkdir build
cd build cd build
conan install .. -b missing conan install .. -s build_type=Release -b missing -pr:b=default
cmake ` cmake `
-G"NMake Makefiles" ` -G"NMake Makefiles" `
-DCMAKE_BUILD_TYPE=Release ` -DCMAKE_BUILD_TYPE=Release `
-DUSE_CONAN=ON ` -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" `
-DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" ` -DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" `
.. ..
set cl=/MP set cl=/MP

View file

@ -131,7 +131,7 @@ Open up your terminal with the Visual Studio environment variables, then enter t
1. `mkdir build` 1. `mkdir build`
2. `cd 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` 4. `nmake`
## Building on MSVC with AddressSanitizer ## 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 -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`. and the _Build Directory_ to `build`.

View file

@ -41,7 +41,8 @@
- Dev: Fixed `final-dtor-non-final-class` warnings. (#4296) - Dev: Fixed `final-dtor-non-final-class` warnings. (#4296)
- Dev: Fixed `ambiguous-reversed-operator` warnings. (#4296) - Dev: Fixed `ambiguous-reversed-operator` warnings. (#4296)
- Dev: Format YAML and JSON files with prettier. (#4304) - 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 ## 2.4.0

View file

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0087 NEW) 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) include(FeatureSummary)
list(APPEND CMAKE_MODULE_PATH list(APPEND CMAKE_MODULE_PATH
@ -24,8 +25,6 @@ option(BUILD_TRANSLATIONS "" OFF)
option(BUILD_SHARED_LIBS "" OFF) option(BUILD_SHARED_LIBS "" OFF)
option(CHATTERINO_LTO "Enable LTO for all targets" OFF) option(CHATTERINO_LTO "Enable LTO for all targets" OFF)
option(USE_CONAN "Use conan" OFF)
if(CHATTERINO_LTO) if(CHATTERINO_LTO)
include(CheckIPOSupported) include(CheckIPOSupported)
check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR) check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR)
@ -40,13 +39,6 @@ else()
set(MAJOR_QT_VERSION "5") set(MAJOR_QT_VERSION "5")
endif() 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) find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM) if (CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
@ -75,8 +67,9 @@ endif ()
find_package(Sanitizers) find_package(Sanitizers)
# Find boost on the system # Find boost on the system
find_package(Boost REQUIRED) # `OPTIONAL_COMPONENTS random` is required for vcpkg builds to link.
find_package(Boost COMPONENTS random) # `OPTIONAL` is required, because conan doesn't set `boost_random_FOUND`.
find_package(Boost REQUIRED OPTIONAL_COMPONENTS random)
# Find OpenSSL on the system # Find OpenSSL on the system
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)

View file

@ -3,7 +3,8 @@ openssl/1.1.1s
boost/1.80.0 boost/1.80.0
[generators] [generators]
cmake CMakeDeps
CMakeToolchain
[options] [options]
openssl:shared=True openssl:shared=True

View file

@ -809,30 +809,16 @@ if (WinToast_FOUND)
WinToast) WinToast)
endif () endif ()
if (USE_CONAN AND TARGET CONAN_PKG::boost) target_link_libraries(${LIBRARY_PROJECT}
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC
CONAN_PKG::boost
)
else ()
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC PUBLIC
${Boost_LIBRARIES} ${Boost_LIBRARIES}
) )
endif ()
if (USE_CONAN AND TARGET CONAN_PKG::openssl) target_link_libraries(${LIBRARY_PROJECT}
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC
CONAN_PKG::openssl
)
else ()
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC PUBLIC
OpenSSL::SSL OpenSSL::SSL
OpenSSL::Crypto OpenSSL::Crypto
) )
endif ()
target_include_directories(${LIBRARY_PROJECT} PUBLIC ${RapidJSON_INCLUDE_DIRS}) target_include_directories(${LIBRARY_PROJECT} PUBLIC ${RapidJSON_INCLUDE_DIRS})