cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

CMake-multi generator automatically used if CMAKE_BUILD_TYPE not defined

Open akalali opened this issue 5 years ago • 2 comments
trafficstars

I was using a check for a multi-config generator, like this:

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT isMultiConfig)
  if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING
        "Choose the type of build, options are: Debug, Release, MinSizeRel, RelWithDebInfo." FORCE)
    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
                 "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  endif()
endif()

In a conan-run.cmake-file I was doing something like:

conan_cmake_run(REQUIRES poco/1.10.1
                BASIC_SETUP CMAKE_TARGETS
                GENERATORS cmake_paths cmake_find_package
                OPTIONS ${CONAN_OPTIONS}
                BUILD missing)

conan_cmake_run automatically uses the cmake_multi-generator if CMAKE_BUILD_TYPE is not set. With the first code-snippet I could remove the multi-config check and set a CMAKE_BUILD_TYPE for single- and multi-config generators. However, it is rather uncommon to use this CMake variable with e.g. Visual Studio projects, so users might not be aware to use this variable to change the build type (I'm talking about CMake GUI here).

The point is that I want to be able to include the Conan install process into my CMakeLists. Since cmake_multi does not work with findPackage (as written in #330 and in #1177) but I don't want my existing CMakeLists, which work with findPackage and Poco::Poco as linked library, to be changed, I always use single-config generators.

What is the proposed way to use the conan_cmake_run for e.g. VS generator using findPackage?

akalali avatar Mar 04 '20 11:03 akalali

Hi @akalali , Did you have a look at the cmake_find_package_multi generators? Maybe they could work for you? https://docs.conan.io/en/latest/reference/generators/cmake_find_package_multi.html

czoido avatar Mar 11 '20 16:03 czoido

I'm working on a project that uses find_package(... NO_MODULE REQUIRED) so cmake_find_package_multi works for me. It creates package config files for debug and release. However, as far as I can see, cmake_find_package needs to be used for projects using find_package(... MODULE REQUIRED), since they require a Find<package>.cmake-file. In this case, cmake_find_package_multi is not an option.

akalali avatar Mar 09 '21 11:03 akalali