Skip to content

Commit

Permalink
Remove wrong include in README and modernize examples
Browse files Browse the repository at this point in the history
Make use of more modern CMake. Reduce Conan.cmake includes to
"include(conan)", because that's why list(APPEND CMAKE_MODULE_PATH
${CMAKE_BINARY_DIR}) is declared at the top of the example.
  • Loading branch information
stephan-cr committed Mar 27, 2021
1 parent 0140fdb commit 3b9c579
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 42 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(FormatOutput CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

add_definitions("-std=c++11")

# 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/develop/conan.cmake"
Expand All @@ -17,7 +15,7 @@ add_definitions("-std=c++11")

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)
Expand All @@ -27,7 +25,8 @@ conan_cmake_install(PATH_OR_REFERENCE .
REMOTE conan-center
SETTINGS ${settings})

find_package(fmt)
find_package(fmt REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
target_link_libraries(main PRIVATE fmt::fmt)
target_compile_features(main PRIVATE cxx_std_11)
70 changes: 34 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,22 @@ You can just clone or grab the *conan.cmake* file and put in in your project.
Or it can be used in this way. Note the ``v0.16.1`` tag in the URL, change it to point to your desired release:

```cmake
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(FormatOutput CXX)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
add_definitions("-std=c++11")
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"
TLS_VERIFY ON)
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
include(conan.cmake)
include(conan)
conan_cmake_configure(REQUIRES fmt/6.1.2
conan_cmake_configure(REQUIRES fmt/6.1.2
GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
Expand All @@ -48,10 +43,11 @@ conan_cmake_install(PATH_OR_REFERENCE .
REMOTE conan-center
SETTINGS ${settings})
find_package(fmt)
find_package(fmt REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
target_link_libraries(main PRIVATE fmt::fmt)
target_compile_features(main PRIVATE cxx_std_11)
```

There are different functions you can use from your CMake project to use Conan from there. The
Expand All @@ -65,7 +61,7 @@ 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 Down Expand Up @@ -119,12 +115,13 @@ looping through the `CMAKE_CONFIGURATION_TYPES` in your _CMakeLists.txt_ and cal
a Conan multiconfig generator like `cmake_find_package_multi`. Please check the example:

```cmake
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
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)
include(conan)
conan_cmake_configure(REQUIRES fmt/6.1.2 GENERATORS cmake_find_package_multi)
Expand All @@ -136,9 +133,10 @@ foreach(TYPE ${CMAKE_CONFIGURATION_TYPES})
SETTINGS ${settings})
endforeach()
find_package(fmt CONFIG)
find_package(fmt REQUIRED CONFIG)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
target_link_libraries(main PRIVATE fmt::fmt)
target_compile_features(main PRIVATE cxx_std_11)
```

## conan_cmake_run() high level wrapper
Expand Down Expand Up @@ -167,7 +165,7 @@ it with the ``CONANFILE`` argument
If you want to use targets, you could do:

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(REQUIRES fmt/1.9.4
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
Expand All @@ -183,7 +181,7 @@ This will do a ``conan_basic_setup(TARGETS)`` for modern CMake targets definitio
If you want to use your own ``conanfile.txt`` or ``conanfile.py`` instead of generating a temporary one, you could do:

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(CONANFILE conanfile.txt # or relative build/conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
Expand Down Expand Up @@ -212,15 +210,15 @@ Used to define the build policy used for ``conan install``. Can take different v
### KEEP_RPATHS

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP KEEP_RPATHS)
```

### NO_OUTPUT_DIRS

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP NO_OUTPUT_DIRS)
```
Expand All @@ -230,7 +228,7 @@ Pass to ``conan_basic_setup(NO_OUTPUT_DIRS)`` so *conanbuildinfo.cmake* does not
### ARCH

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(ARCH armv7)
```

Expand All @@ -241,7 +239,7 @@ exist in *settings.yml*.
### BUILD_TYPE

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(BUILD_TYPE "None")
```

Expand All @@ -251,18 +249,18 @@ exist in *settings.yml*.
### CONFIGURATION_TYPES

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(CONFIGURATION_TYPES "Release;Debug;RelWithDebInfo")
```

Use it to set the different configurations when using multi-configuration generators. The default
configurations used for multi-configuration generators are `Debug` and `Release` if the argument
`CONFIGURATION_TYPES` is not specified The build types passed through this argument should exist
Use it to set the different configurations when using multi-configuration generators. The default
configurations used for multi-configuration generators are `Debug` and `Release` if the argument
`CONFIGURATION_TYPES` is not specified The build types passed through this argument should exist
in *settings.yml*.

### PROFILE
```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(PROFILE default)
```

Expand All @@ -272,7 +270,7 @@ and are overridden by the values from the profile.

### PROFILE_AUTO
```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(PROFILE default
PROFILE_AUTO build_type)
```
Expand All @@ -291,7 +289,7 @@ The ``ALL`` value is used to use all detected settings from CMake, instead of th
defined in the profile:

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(PROFILE default
PROFILE_AUTO ALL)
```
Expand All @@ -308,15 +306,15 @@ If the ``BUILD_TYPE`` is explictly passed to ``conan_cmake_run()``, then single

### SETTINGS
```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
SETTINGS arch=armv6
SETTINGS compiler.cppstd=14)
```

### ENV
```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
ENV env_var=value
ENV Pkg:env_var2=value2)
Expand All @@ -338,7 +336,7 @@ have higher precedence, so these values would be used instead of the profiles on
Provide the ``conan install --install-folder=[folder]`` argument:

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
INSTALL_FOLDER myfolder
)
Expand All @@ -349,7 +347,7 @@ conan_cmake_run(...
Add additional [generators](https://docs.conan.io/en/latest/reference/generators.html?highlight=generator). It may useful to add the [virtualrunenv](https://docs.conan.io/en/latest/mastering/virtualenv.html#virtualrunenv-generator)-generator:

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
GENERATORS virtualrunenv)
```
Expand All @@ -369,7 +367,7 @@ conan_cmake_run(...
Use ``NO_LOAD`` argument to avoid loading the _conanbuildinfo.cmake_ generated by the default ``cmake`` generator.

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
NO_LOAD)
```
Expand All @@ -380,7 +378,7 @@ Use ``CONAN_COMMAND`` argument to specify the conan path, e.g. in case of runnin
does not identify conan as command, even if it is +x and it is in the path.

```cmake
include(conan.cmake)
include(conan)
conan_cmake_run(...
CONAN_COMMAND "path_to_conan")
```
Expand Down Expand Up @@ -433,7 +431,7 @@ if(CONAN_EXPORTED) # in conan local cache
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else() # in user space
include(conan.cmake)
include(conan)
# 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)
Expand Down

0 comments on commit 3b9c579

Please sign in to comment.