Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove wrong include and modernize example #327

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ 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"
Expand All @@ -35,7 +32,7 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
TLS_VERIFY ON)
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)
include(conan)

conan_cmake_configure(REQUIRES fmt/6.1.2
GENERATORS cmake_find_package)
Expand All @@ -47,10 +44,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 Down Expand Up @@ -118,12 +116,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 @@ -135,9 +134,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 @@ -166,7 +166,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 @@ -182,7 +182,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 @@ -211,15 +211,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 @@ -229,7 +229,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 @@ -240,7 +240,7 @@ exist in *settings.yml*.
### BUILD_TYPE

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

Expand All @@ -250,18 +250,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 @@ -271,7 +271,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 @@ -290,7 +290,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 @@ -307,15 +307,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 @@ -337,7 +337,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 @@ -348,7 +348,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 @@ -368,7 +368,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 @@ -379,7 +379,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 @@ -432,7 +432,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