Giter VIP home page Giter VIP logo

Comments (7)

jiixyj avatar jiixyj commented on July 17, 2024

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.

memsharded avatar memsharded commented on July 17, 2024

Hi @RochaStratovan

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 using CMakeDeps
  • In the consumer side, the CMakeToolchain adds the paths to the packages so find_package() will find it inside your package.

from docs.

RochaStratovan avatar RochaStratovan commented on July 17, 2024

@jiixyj, @memsharded,

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.

memsharded avatar memsharded commented on July 17, 2024

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.

RochaStratovan avatar RochaStratovan commented on July 17, 2024

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.

memsharded avatar memsharded commented on July 17, 2024

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.

memsharded avatar memsharded commented on July 17, 2024

We have added a new section with a working example in #3604, closing this as solved

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.