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

Testing new flow for Multi Configuration generators #325

Merged
merged 12 commits into from
Mar 23, 2021
Merged
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
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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 Down Expand Up @@ -109,6 +111,36 @@ conan_cmake_run(REQUIRES fmt/1.9.4
SETTINGS build_type=Debug)
```

## 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 conan-center
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
Expand Down
6 changes: 3 additions & 3 deletions conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ function(_collect_settings result)
set(${result} ${detected_setings} PARENT_SCOPE)
endfunction()

function(conan_cmake_autodetect detected_settings)
_conan_detect_build_type()
function(conan_cmake_autodetect detected_settings ${ARGV})
_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
24 changes: 24 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,30 @@ def test_vs_toolset(self):
cmd = os.sep.join([".", "bin", "main"])
run(cmd)

@unittest.skipIf(platform.system() != "Windows", "Multi-config only in Windows")
def test_multi_new_flow(self):
content = textwrap.dedent("""
cmake_minimum_required(VERSION 3.5)
project(HelloProject 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 hello/1.0 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 conan-center
SETTINGS ${settings})
endforeach()
find_package(hello CONFIG)
add_executable(main main.cpp)
target_link_libraries(main hello::hello)
""")
save("CMakeLists.txt", content)
self._build_multi(["Release", "Debug", "MinSizeRel", "RelWithDebInfo"])

@unittest.skipIf(platform.system() != "Windows", "Multi-config only in Windows")
def test_multi(self):
content = textwrap.dedent("""
Expand Down