Skip to content

Commit

Permalink
Merge pull request #370 from conan-io/release/0.17
Browse files Browse the repository at this point in the history
cmake-conan version 0.17 to master
  • Loading branch information
czoido authored Nov 19, 2021
2 parents a3a0916 + f8fd649 commit 91c15d3
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 121 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cmake_conan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on: [push, pull_request, workflow_dispatch]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2019, macos-latest, ubuntu-latest]
include:
- os: windows-2019
ENV_CMAKE: ./activate_run.ps1
- os: macos-latest
ENV_CMAKE: source activate_run.sh
- os: ubuntu-latest
ENV_CMAKE: source activate_run.sh
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install Conan
run: pip install conan pytest && conan --version
- name: Install CMake
run: conan install cmake/3.16.4@ -g=virtualrunenv
- name: Run Tests
run: ${{matrix.ENV_CMAKE}} && pytest tests.py -rA -v
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .travis/install.sh

This file was deleted.

11 changes: 0 additions & 11 deletions .travis/run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ conan_cmake_autodetect(settings)

conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conan-center
REMOTE conancenter
SETTINGS ${settings})

find_package(fmt)
Expand Down
87 changes: 66 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cmake-conan

[![Build status](https://ci.appveyor.com/api/projects/status/xufl3dbdfrlnuhcp/branch/master?svg=true&passingText=master%20-%20OK)](https://ci.appveyor.com/project/ConanOrgCI/cmake-conan/branch/master) [![Build status](https://ci.appveyor.com/api/projects/status/xufl3dbdfrlnuhcp/branch/develop?svg=true&passingText=develop%20-%20OK)](https://ci.appveyor.com/project/ConanOrgCI/cmake-conan/branch/develop) [![Build Status](https://travis-ci.org/conan-io/cmake-conan.svg?branch=master)](https://travis-ci.org/conan-io/cmake-conan)
![Build Status](https://github.com/conan-io/cmake-conan/actions/workflows/cmake_conan.yml/badge.svg)

CMake wrapper for the Conan C and C++ package manager.

Expand All @@ -10,7 +10,7 @@ This cmake module allows to launch ``conan install`` from cmake.
The branches in this repo are:
- **develop**: PR are merged to this branch. Latest state of development
- **master**: Latest release
- **tagged releases**: https://github.com/conan-io/cmake-conan/releases.
- **tagged releases**: https://github.com/conan-io/cmake-conan/releases.

You probably want to use a tagged release to ensure controlled upgrades.

Expand All @@ -31,41 +31,55 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.16.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
EXPECTED_HASH SHA256=396e16d0f5eabdc6a14afddbcfff62a54a7ee75c6da23f32f7a31bc85db23484
TLS_VERIFY ON)
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
include(conan.cmake)
conan_cmake_configure(REQUIRES fmt/6.1.2
conan_cmake_configure(REQUIRES fmt/6.1.2
GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conan-center
REMOTE conancenter
SETTINGS ${settings})
find_package(fmt)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
target_link_libraries(main fmt::fmt)
```

There are different functions you can use from your CMake project to use Conan from there. The
recommended flow to use cmake-conan is successively calling to `conan_cmake_configure`,
`conan_cmake_autodetect` and `conan_cmake_install`. This flow is recommended from v0.16 where these
functions were introduced.

The example above is using the Conan `cmake_find_package` generator which is less intrusive than the
`cmake` generator and more aligned with the direction Conan is taking for the 2.0 version. If you
want to continue using the `cmake` generator with `conan_cmake_configure`, `conan_cmake_autodetect`
and `conan_cmake_install` flow, you should manually include the `conanbuildinfo.cmake` file generated
and also call to `conan_basic_setup`:

```cmake
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
```

Please [check the cmake generator documentation](https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#cmake-generator)
for further details.

## conan_cmake_configure()

This function will accept the same arguments as the sections of the
[conanfile.txt](https://docs.conan.io/en/latest/reference/conanfile_txt.html).

```cmake
conan_cmake_configure(REQUIRES fmt/6.1.2
conan_cmake_configure(REQUIRES fmt/6.1.2
GENERATORS cmake_find_package
BUILD_REQUIRES cmake/3.15.7
IMPORTS "bin, *.dll -> ./bin"
Expand All @@ -78,7 +92,9 @@ conan_cmake_configure(REQUIRES fmt/6.1.2

This function will return the auto-detected settings (things like *build_type*, *compiler* or *system
name*) so you can pass that information to `conan_cmake_install`. This step is optional as you may
want to rely on profiles, lockfiles or any other way of passing that information.
want to rely on profiles, lockfiles or any other way of passing that information. This function will
also accept as arguments `BUILD_TYPE` and `ARCH`. Setting those arguments will force that settings
to the value provided (this can be useful for the multi-configuration generator scenario below).

```cmake
conan_cmake_autodetect(settings)
Expand All @@ -102,19 +118,48 @@ It will also accept `OUTPUT_QUIET` and `ERROR_QUIET` arguments so that when it r
command the output is quiet or the error is bypassed (or both).

```cmake
conan_cmake_run(REQUIRES fmt/1.9.4
cgal/5.0.2
OPTIONS Pkg:shared=True
OtherPkg:option=value
SETTINGS build_type=Debug)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conancenter
SETTINGS ${settings})
```

## Using conan_cmake_autodetect() and conan_cmake_install() with Multi Configuration generators

The recommended approach when using Multi Configuration generators like Visual Studio or Xcode is
looping through the `CMAKE_CONFIGURATION_TYPES` in your _CMakeLists.txt_ and calling
`conan_cmake_autodetect` with the `BUILD_TYPE` argument and `conan_cmake_install` for each one using
a Conan multiconfig generator like `cmake_find_package_multi`. Please check the example:

```cmake
cmake_minimum_required(VERSION 3.5)
project(FormatOutput CXX)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
add_definitions("-std=c++11")
include(conan.cmake)
conan_cmake_configure(REQUIRES fmt/6.1.2 GENERATORS cmake_find_package_multi)
foreach(TYPE ${CMAKE_CONFIGURATION_TYPES})
conan_cmake_autodetect(settings BUILD_TYPE ${TYPE})
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conancenter
SETTINGS ${settings})
endforeach()
find_package(fmt CONFIG)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
```

## conan_cmake_run() high level wrapper

This function is not the recommended way of using cmake-conan any more and will be deprecated in the
near future. It will make the configure, auto-detect and install in one step so if you plan to use
any new Conan features like lockfiles or build and host profiles it's possible that the auto-detected
settings collide with the call to conan install.
settings collide with the call to conan install.

### conan_cmake_run() options:

Expand Down Expand Up @@ -163,7 +208,7 @@ The resolution of the path will be relative to the root ``CMakeLists.txt`` file.

```cmake
conan_cmake_run(REQUIRES fmt/6.1.2 boost...
BASIC_SETUP
BASIC_SETUP
BUILD <value>)
```

Expand Down Expand Up @@ -372,10 +417,10 @@ Arguments ``URL`` and ``NAME`` are required, ``INDEX`` and ``VERIFY_SSL`` are op

Example usage:
```
conan_add_remote(NAME bincrafters
conan_add_remote(NAME bincrafters
INDEX 1
URL https://api.bintray.com/conan/bincrafters/public-conan
VERIFY_SSL True)
VERIFY_SSL True)
```

### conan_config_install()
Expand Down Expand Up @@ -405,7 +450,7 @@ else() # in user space
# Make sure to use conanfile.py to define dependencies, to stay consistent
conan_cmake_configure(REQUIRES fmt/6.1.2 GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE . BUILD missing REMOTE conan-center SETTINGS ${settings})
conan_cmake_install(PATH_OR_REFERENCE . BUILD missing REMOTE conancenter SETTINGS ${settings})
endif()
```

Expand All @@ -414,8 +459,8 @@ Please check the source code for other options and arguments.

## Development, contributors

There are some tests, you can run in python, with nosetests, for example:
There are some tests, you can run in python, with pytest, for example:

```bash
$ nosetests . --nocapture
$ pytest tests.py -rA
```
18 changes: 0 additions & 18 deletions appveyor.yml

This file was deleted.

20 changes: 14 additions & 6 deletions conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# but it is only necessary on the end-user side. It is not necessary to create conan
# packages, in fact it shouldn't be use for that. Check the project documentation.

# version: 0.16.1
# version: 0.17.0

include(CMakeParseArguments)

Expand All @@ -55,6 +55,8 @@ function(_get_msvc_ide_version result)
set(${result} 15 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930)
set(${result} 16 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940)
set(${result} 17 PARENT_SCOPE)
else()
message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]")
endif()
Expand Down Expand Up @@ -126,6 +128,10 @@ macro(_conan_detect_compiler)
set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH})
endif()

if(USING_CXX)
set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD})
endif()

if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU)
# using GCC
# TODO: Handle other params
Expand Down Expand Up @@ -415,7 +421,8 @@ endfunction()

function(_collect_settings result)
set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
compiler.runtime compiler.libcxx compiler.toolset)
compiler.runtime compiler.libcxx compiler.toolset
compiler.cppstd)
foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
string(TOUPPER ${ARG} _arg_name)
string(REPLACE "." "_" _arg_name ${_arg_name})
Expand All @@ -427,10 +434,10 @@ function(_collect_settings result)
endfunction()

function(conan_cmake_autodetect detected_settings)
_conan_detect_build_type()
_conan_detect_build_type(${ARGV})
_conan_check_system_name()
_conan_check_language()
_conan_detect_compiler()
_conan_detect_compiler(${ARGV})
_collect_settings(collected_settings)
set(${detected_settings} ${collected_settings} PARENT_SCOPE)
endfunction()
Expand Down Expand Up @@ -807,7 +814,8 @@ macro(conan_check)
endif()

if(NOT CONAN_DETECT_QUIET)
message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}")
string(STRIP "${CONAN_VERSION_OUTPUT}" _CONAN_VERSION_OUTPUT)
message(STATUS "Conan: Version found ${_CONAN_VERSION_OUTPUT}")
endif()

if(DEFINED CONAN_VERSION)
Expand Down Expand Up @@ -837,7 +845,7 @@ function(conan_add_remote)
if(DEFINED CONAN_COMMAND)
set(CONAN_CMD ${CONAN_COMMAND})
else()
conan_check(REQUIRED)
conan_check(REQUIRED DETECT_QUIET)
endif()
set(CONAN_VERIFY_SSL_ARG "True")
if(DEFINED CONAN_VERIFY_SSL)
Expand Down
Loading

0 comments on commit 91c15d3

Please sign in to comment.