Skip to content
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

Inject CMake build_modules after targets are created #8130

Merged
merged 19 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions conans/client/generators/cmake_find_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class CMakeFindPackageGenerator(GeneratorComponentsMixin, Generator):
{find_dependencies_block}
endif()
endif()

foreach(_BUILD_MODULE_PATH ${{{name}_BUILD_MODULES_PATHS}})
danimtb marked this conversation as resolved.
Show resolved Hide resolved
include(${{_BUILD_MODULE_PATH}})
endforeach()
""")

find_components_tpl = Template(textwrap.dedent("""\
Expand Down
4 changes: 0 additions & 4 deletions conans/client/generators/cmake_find_package_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@

set(CMAKE_MODULE_PATH {deps.build_paths} ${{CMAKE_MODULE_PATH}})
set(CMAKE_PREFIX_PATH {deps.build_paths} ${{CMAKE_PREFIX_PATH}})

foreach(_BUILD_MODULE_PATH ${{{name}_BUILD_MODULES_PATHS{build_type_suffix}}})
danimtb marked this conversation as resolved.
Show resolved Hide resolved
include(${{_BUILD_MODULE_PATH}})
endforeach()
"""


Expand Down
66 changes: 66 additions & 0 deletions conans/test/functional/generators/cmake_find_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,72 @@ def build(self):
client.run("create .")
self.assertIn("Printing using a external module!", client.out)

def test_build_modules_alias_target(self):
client = TestClient()
client.run("new hello/1.0 -s")
print(os.listdir(client.current_folder))
conanfile = textwrap.dedent("""
import os
from conans import ConanFile, CMake

class Conan(ConanFile):
name = "hello"
version = "1.0"
settings = "os", "arch", "compiler", "build_type"
exports_sources = ["target-alias.cmake", "src/*"]
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure(source_folder="src")
cmake.build()

def package(self):
self.copy("*.h", dst="include")
self.copy("*.a", dst="lib")
self.copy("*.lib", dst="lib")
self.copy("target-alias.cmake", dst="share/cmake")

def package_info(self):
builddir = os.path.join("share", "cmake")
module = os.path.join(builddir, "target-alias.cmake")
self.cpp_info.build_modules.append(module)
self.cpp_info.builddirs = [builddir]
""")
target_alias = textwrap.dedent("""
add_library(otherhello INTERFACE IMPORTED)
target_link_libraries(otherhello INTERFACE hello::hello)
""")
client.save({"conanfile.py": conanfile, "target-alias.cmake": target_alias})
client.run("create .")

consumer = textwrap.dedent("""
from conans import ConanFile, CMake

class Conan(ConanFile):
name = "consumer"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
exports_sources = ["CMakeLists.txt"]
generators = "cmake_find_package"
requires = "hello/1.0"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
""")
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(hello)
get_target_property(tmp otherhello INTERFACE_LINK_LIBRARIES)
message("otherhello link libraries: ${tmp}")
""")
client.save({"conanfile.py": consumer, "CMakeLists.txt": cmakelists})
client.run("create .")
self.assertIn("otherhello link libraries: hello::hello", client.out)

def test_cpp_info_name(self):
client = TestClient()
client.run("new hello/1.0 -s")
Expand Down