Closed WZHKLMA closed 10 months ago
Hi @WZHKLMA
Yes, you can. You can check the section "customizing profiles" in https://github.com/conan-io/cmake-conan/tree/develop2#customizing-conan-profiles
Basically you can use -DCONAN_HOST_PROFILE
to inject your own profiles, in which you can force build_type=Release
for your dependencies if you want to.
Please let us know if this works.
Hi @memsharded,
thank you for pointing this out. I achieved it via the following cmake commands directly after the project()
call:
set(CONAN_HOST_PROFILE "${CMAKE_BINARY_DIR}/conan_host_profile" CACHE STRING "Conan host profile" FORCE)
detect_host_profile(${CMAKE_BINARY_DIR}/conan_host_profile)
file(READ ${CMAKE_BINARY_DIR}/conan_host_profile FILE_CONTENTS)
string(REPLACE "build_type=Debug" "build_type=Release" FILE_CONTENTS "${FILE_CONTENTS}")
file(WRITE ${CMAKE_BINARY_DIR}/conan_host_profile "${FILE_CONTENTS}")
It works in my case, but I am not sure if it would work with a multiconfig generator due to https://github.com/conan-io/cmake-conan/blob/develop2/conan_provider.cmake#L508-L509
Happy that you managed to address it.
But please take into account that the recommended practice is to not modify the CMakeLists.txt
, and specially not hardcoding those things.
That kind of things belongs to external files, maybe toolchains, or CMakePresets.json, or even command line, but CMakeLists.txt
wouldn't be the recommended place.
Also you don't need to read, modify and save. You can perfectly have one profile, static file in your repo with just the built_type=Release
. When you apply that profile in the command line, it will be composed with the previous one (the one detected by cmake-conan, and will modify just the build-type leaving the other values.
So in short:
build_type=Release
Thanks a lot for your comment, that's so much better. Just had to put a [settings]
section in top of the "release" profile. Then I set it up via my Cmake Preset and all works.
Great, thanks for the feedback!
Unfortunately I was bit too quick with my testing. I only checked the cmake output and it looked promising:
[cmake] -- CMake-Conan: find_package(fmt) found, 'conan install' already ran
[cmake] -- Conan: Component target declared 'fmt::fmt-header-only'
But the build in Debug mode fails, since it cannot find the fmt
headers even when I add fmt::fmt-header-only
to the target_link_libraries
(in Release mode all works fine). In the compile_commands.json
nothing shows up related to fmt
(Debug mode, Release everything is there). In the build folder the cmake files generated by conan end up in conan/build/Release/generators
and the relevant cmake files in there are also named with a release tag, e.g. fmt-release-x86_64-data.cmake
. Do you have any idea what the problem could be?
Can you please try adding:
build_type=Release
&:build_type=Debug
In your profile? It might be necessary to let Conan know that your current build is Debug
That was the missing piece. Thank you very much!
I found this question, but would it be possible to achieve this via cmake conan develop2 integration?