Comments (7)
If you are using the CMakeDeps
generator, you can write self.cpp_info.set_property("cmake_find_mode", "none")
in the package_info()
method to turn off generation of CMake find modules for your package. There is some documentation (albeit a bit hidden) here.
from docs.
Thanks for your question.
I think this example can also help: https://docs.conan.io/2/examples/graph/requires/consume_cmake_macro.html
Basically:
- Make sure to package your
xxxx-config.cmake
files self.cpp_info.builddirs.append("<folder-you-put the .cmake>")
self.cpp_info.set_property("cmake_find_mode", "none")
so the consumer doesn't generate the files for it, even if it is usingCMakeDeps
- In the consumer side, the
CMakeToolchain
adds the paths to the packages sofind_package()
will find it inside your package.
from docs.
Thank you for the prompt response. I'll start digging into this right away.
As a side question, can you share what you think would be the best way to learn the ins and outs of conan? I am reading through the documentation, but as you can see I'm not finding everything. Is there more that you can share for how to approach this?
Thanks again.
from docs.
Thank you for the prompt response. I'll start digging into this right away.
Great
As a side question, can you share what you think would be the best way to learn the ins and outs of conan? I am reading through the documentation, but as you can see I'm not finding everything. Is there more that you can share for how to approach this?
The documentation is the best source at the moment. The community in CppLang slack and Discord is very helpful, but for official support do not hesitate to open here in Github as many tickets as you need for any question that you have. We often use the feedback here in Github issues to complete the documentation, so it is helpful too.
from docs.
I can confirm that the suggested solution worked. I did a quick mock using googletest.
The conanfile.py file.
from conan import ConanFile
from conan.tools.files import copy
import os
class gtestRecipe(ConanFile):
name = "googletest"
package_type = "library"
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [False], "fPIC": [True]}
default_options = {"shared": False, "fPIC": True}
def package(self):
copy(self, "*",
os.path.join(self.source_folder, "INSTALL"),
os.path.join(self.package_folder))
def package_info(self):
self.cpp_info.libdirs = ['lib']
self.cpp_info.includedirs = ['include']
self.cpp_info.builddirs.append(".")
self.cpp_info.set_property("cmake_find_mode", "none")
In the test I did a binary package deploy where we first compile and deploy to a local INSTALL
folder, which is a relocatable CMake package.
The entire INSTALL folder is packaged. Using the builddirs
and cmake_find_mode
settings allowed me to use the CMake packaging code generated by google test and included in the conan package.
General steps:
The test_packages/CMakeLists.txt file.
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)
find_package(GTest CONFIG REQUIRED)
add_executable(example src/example.cpp)
target_link_libraries(example PRIVATE GTest::gtest_main)
For the test_packages/src/example.cpp
file, I just copied one of the google test samples into it.
From a Windows git-bash shell, compile and install to my local install folder
cmake . -B BUILD -A x64
cmake --build BUILD --config Release
cmake --install BUILD --prefix "${PWD}/INSTALL" --config Release
Edit the generated/installed file INSTALL/lib/cmake/GTest/GTestConfig.cmake
to clearly show its my file by adding the following to the top of the file
message(STATUS)
message(STATUS "THIS IS MY FILE!!!!")
message(STATUS)
Create a conan package from my INSTALL
folder, exporting the package to my local repository
conan export-pkg . -s os=Windows -s arch=x86_64 -s compiler=msvc -s compiler.version=193 --version 1.10.0
See the expected results in the test_package output
The results
======== Testing the package: Building ========
googletest/1.10.0 (test package): Calling build()
googletest/1.10.0 (test package): Running CMake.configure()
googletest/1.10.0 (test package): RUN: cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package/build/msvc-193-x86_64-14-release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:\Users\rocha\Desktop\GitAll\3rdParty\googletest\test_package"
-- Using Conan toolchain: C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package/build/msvc-193-x86_64-14-release/generators/conan_toolchain.cmake
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=v143
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22631.
-- The CXX compiler identification is MSVC 19.38.33134.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- THIS IS MY FILE!!!!
--
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package/build/msvc-193-x86_64-14-release
googletest/1.10.0 (test package): Running CMake.build()
googletest/1.10.0 (test package): RUN: cmake --build "C:\Users\rocha\Desktop\GitAll\3rdParty\googletest\test_package\build\msvc-193-x86_64-14-release" --config Release
MSBuild version 17.8.3+195e7f5a3 for .NET Framework
Checking Build System
Building Custom Rule C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package/CMakeLists.txt
example.cpp
example.vcxproj -> C:\Users\rocha\Desktop\GitAll\3rdParty\googletest\test_package\build\msvc-193-x86_64-14-release\Release\example.exe
Building Custom Rule C:/Users/rocha/Desktop/GitAll/3rdParty/googletest/test_package/CMakeLists.txt
======== Testing the package: Executing test ========
googletest/1.10.0 (test package): Running test()
googletest/1.10.0 (test package): RUN: Release\example
Running main() from C:\Users\rocha\Desktop\GitAll\3rdParty\googletest\submodules\googletest\googletest\src\gtest_main.cc
[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[ PASSED ] 0 tests.
Thank you again.
from docs.
Fantastic, thanks very much for the detailed feedback.
I am re-opening this ticket and moving it to the docs repo, I think even if not high priority, it would be good to eventually add a full example like this to the docs. Thanks!
from docs.
We have added a new section with a working example in #3604, closing this as solved
from docs.
Related Issues (20)
- Tutorial/Consuming packages/Build a simple CMake project using Conan wrong command for windows
- Clarifications for build-requires graph cost & more
- [question] Components hide global definitions in layout method HOT 3
- building fmt/10.1.0 on windows failed about unicode HOT 2
- building openexr/3.2.1 on the windows, failed with a cmake error. HOT 2
- [question] How to exclude tool_requires from graph info output HOT 5
- [bug] Improper variable in tools.microsoft:winsdk_version description HOT 2
- Missing read more sections in the docs
- Mention that positional args should go before optional ones
- Prepend 'html_baseurl' to the href of each switching item in versions.html? HOT 2
- autodoc: failed to import class 'conan_api.ConanAPI' from module 'conan.api'
- [bug] path argument no longer position independent for "conan lock create" in Conan 2.1.0 HOT 2
- error: No module named 'test.examples_tools' when run run_example.py HOT 3
- [question] Clarification of run statement in documentation for cross building to Android HOT 2
- [question] VirtualBuildEnv in packages that were not just built HOT 9
- [bug][docs] `generic_system` documentation is wrong/`compilers` block is not documented HOT 2
- [bug][docs] Missing information about removal of `-e`, `-e:b` and `-e:h` and what to use instead HOT 3
- [question] Issue with `extra_cxxflags` not initializing `CMAKE_CXX_FLAGS_INIT` in Ninja Multi-Config CMake projects since Conan 2.1.0 HOT 6
- [bug] the “exported” files are not copied to the self.source_folder before calling the source() method HOT 3
- [question] [conan2] [config] How do I specify a path containing "~" in global.conf? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.