-
Notifications
You must be signed in to change notification settings - Fork 989
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
[question] generator for modern cmake #9108
Comments
|
Thanks for the clarification! But how does CMakeDeps works with multi config environments. Currently we use |
CMakeDeps is a multi-config generator, it will work in multi-config IDEs like VS, and single-config one (as the single-config is basically a simplification of the multi-config one, where only 1 config is installed) |
What about conan-cmake, can |
|
Well, I need |
Conan will no longer change the CMake or project layout, and it will not provide this method. Instead it will provide the If you want to change the CMake behavior you can define it yourself, implementation is straightforward, actually not related to Conan, just pure convention: set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) Instead of changing the CMake output directories, there are several, more idiomatic options that don't require to change the output directories:
|
@memsharded Thanks a lot for the info, but I'm still struggling with a consumer recipe that uses conan-cmake/CMakeDeps. As a first step, I try to attach Boost package; files 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")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_configure(REQUIRES boost/1.75.0
GENERATORS CMakeDeps)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
SETTINGS ${settings})
conan_load_buildinfo()
find_package(Boost)
I've tried to |
You need to:
This works on my side: cmake_minimum_required(VERSION 3.15)
project(MyApp CXX)
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")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_configure(REQUIRES boost/1.75.0
GENERATORS CMakeDeps)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
SETTINGS ${settings})
# conan_load_buildinfo()
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR} ${CMAKE_PREFIX_PATH})
find_package(Boost REQUIRED) |
@memsharded Thanks a lot again. BTW, there is another problem with cmake-conan: for multi-configuration generators its docs propose foreach(TYPE ${CMAKE_CONFIGURATION_TYPES})
conan_cmake_autodetect(settings BUILD_TYPE ${TYPE})
...
endforeach() but actually
Probably this should be reported as a cmake-conan issue? |
Yes, please, report this in cmake-conan. |
One more question if you don't mind. Suppose I have two header-only conan packages: PkgA and PkgB, and PkgA depends on PkgB. With |
Already reported by someone else: conan-io/cmake-conan#336 |
CMakeDeps are also transitive, so what you describe should work. Maybe is the target name, and should be something like |
|
Hi @memsharded ,
By the way, what is your recommended approach to configure Is it possible to make |
Hi @Nipheris It is not possible to make The general idea is try to use the native, natural layout that every build system would use, and let the |
@memsharded Bingo! I think we need some utility functions like |
Yes, the idea is to mature first the main helpers like CMakeToolchain, etc., and as we internally factorize the utility functions, we will make them available, but better wait until things stabilize a bit more before publishing them. |
@memsharded When using Does that mean |
It is not one or the other, actually both of them should be used for most common cases. Please read carefully the docs in: https://docs.conan.io/en/latest/reference/conanfile/tools/cmake.html The idea is that:
|
This is starting to make sense to me... but running into a question regarding In our setup, we are hoping to let Let's say we have the following in our
We run a
The Does this mean that we need to manually add a For MSBuildDeps... we get a really nice and simple |
Hi @sully7 Yes, it is necessary to add def generate(self):
finds = ["find_package({} CONFIG REQUIRED)".format(d.ref.name) for d in self.dependencies.direct_host.values()]
save(self, "conandeps.cmake", "\n".join(finds) |
@memsharded - Thanks so much for this!! For my use case, we had to add a second line to it to also include the
Hope this helps someone else who might be new to all this too :) |
@memsharded This should take into account |
Answering to myself: something like finds = []
for d in self.dependencies.direct_host.values():
name = d.cpp_info.get_property("cmake_file_name")
if not name:
name = d.ref.name
finds.append(f"find_package({name} CONFIG REQUIRED)")
save(self, "conandeps.cmake", "\n".join(finds)) seems to be enough |
Closing this as responded |
Conan supports many cmake generators:
Currently we use cmake and cmake_multi but they have a huge limitation (no components support). So I'm thinking to switch to cmake_find_package and cmake_find_package_multi but it seems that components support is also experimental. And then there is CMakeDeps which looks like a reimplementation of
cmake_find_package
My understanding is that these different generators were created to simplify conan integration with existing cmake projects! But What is the most recommended generator to use if we do conan oriented modern cmake ?
The text was updated successfully, but these errors were encountered: