-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Multiple CMake builds from single conanfile #18905
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1b73df7
cmake multi
davidsanfal abe8f65
wip
davidsanfal 310f257
wip
davidsanfal 8b20ef3
reuse multi wip
davidsanfal 65a3695
wip
davidsanfal e96e292
wip
davidsanfal 41a7f41
wip
davidsanfal ecc6357
wip
davidsanfal 4b0ea3f
wip
davidsanfal 4d20fce
wip
davidsanfal b317d57
wip
davidsanfal a20a01c
wip
davidsanfal 0f97341
wip
davidsanfal dcbb52f
wip
davidsanfal 174fc6c
wip
davidsanfal 7b6e686
wip
davidsanfal af4412e
wip
davidsanfal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import os | ||
| import platform | ||
| import textwrap | ||
|
|
||
| from conan.test.utils.tools import TestClient | ||
|
|
||
|
|
||
| def test_multi_cMake(): | ||
| conanfile = textwrap.dedent(""" | ||
| from conan import ConanFile | ||
| from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps | ||
| import os | ||
| class multiRecipe(ConanFile): | ||
| settings = "os", "compiler", "build_type", "arch" | ||
| exports_sources = "cmake_one/CMakeLists.txt", "cmake_two/CMakeLists.txt", "src_one/*", "src_two/*" | ||
| def layout(self): | ||
| cmake_layout(self) | ||
| def generate(self): | ||
| deps = CMakeDeps(self) | ||
| deps.generate() | ||
| tc = CMakeToolchain(self) | ||
| tc.generate() | ||
| def build_one(self): | ||
| cmake = CMake(self) | ||
| cmake.configure(build_script_folder="cmake_one", subfolder="one") | ||
| cmake.build(subfolder="one") | ||
| # cmake.install(subfolder="one") | ||
| def build_two(self): | ||
| cmake = CMake(self) | ||
| # CMAKE_PREFIX_PATH | ||
| cmake.configure(build_script_folder="cmake_two", subfolder="two") | ||
| cmake.build(subfolder="two") | ||
| def build(self): | ||
| self.build_one() | ||
| self.build_two() | ||
| def package(self): | ||
| cmake = CMake(self) | ||
| cmake.install(subfolder="two") | ||
| def package_info(self): | ||
| self.cpp_info.libs = ["hello_two"] | ||
| self.cpp_info.includedirs = ['two/include'] | ||
| self.cpp_info.libdirs = ['two/lib'] | ||
| """) | ||
|
|
||
| hello_cpp = textwrap.dedent(""" | ||
| #include <iostream> | ||
| #include "hello_{name}.h" | ||
| void hello_{name}() {{ | ||
| std::cout << "Hello, World {name}!" << std::endl; | ||
| }} | ||
| """) | ||
|
|
||
| hello_h = textwrap.dedent(""" | ||
| #ifndef HELLO_{name}_H | ||
| #define HELLO_{name}_H | ||
| void hello_{name}(); | ||
| #endif | ||
| """) | ||
|
|
||
| cmakelist = textwrap.dedent(""" | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(hello_{name} LANGUAGES CXX) | ||
| add_library(hello_{name} ../src_{name}/hello_{name}.cpp) | ||
| target_include_directories(hello_{name} PUBLIC ../src_{name}) | ||
| set_target_properties(hello_{name} PROPERTIES PUBLIC_HEADER "../src_{name}/hello_{name}.h") | ||
| install(TARGETS hello_{name}) | ||
| """) | ||
|
|
||
| client = TestClient() | ||
| client.save({"conanfile.py": conanfile, | ||
| "cmake_one/CMakeLists.txt": cmakelist.format(name="one"), | ||
| "cmake_two/CMakeLists.txt": cmakelist.format(name="two"), | ||
| "src_one/hello_one.h": hello_h.format(name="one"), | ||
| "src_one/hello_one.cpp": hello_cpp.format(name="one"), | ||
| "src_two/hello_two.h": hello_h.format(name="two"), | ||
| "src_two/hello_two.cpp": hello_cpp.format(name="two")}) | ||
davidsanfal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| client.run("create . --name=multi --version=0.1") | ||
|
|
||
| if platform.system() != "Windows": | ||
| assert "[100%] Built target hello_one" in client.out | ||
| assert "[100%] Built target hello_two" in client.out | ||
| assert "multi/0.1: package(): Packaged 1 '.h' file: hello_two.h" in client.out | ||
| assert "multi/0.1: package(): Packaged 1 '.a' file: libhello_two.a" in client.out | ||
| package_folder = client.created_layout().package() | ||
|
|
||
| assert not os.path.exists(os.path.join(package_folder, "one", "include", "hello_one.h")) | ||
| assert not os.path.exists(os.path.join(package_folder, "one", "lib", "libhello_one.a")) | ||
|
||
|
|
||
| assert os.path.exists(os.path.join(package_folder, "two", "include", "hello_two.h")) | ||
| assert os.path.exists(os.path.join(package_folder, "two", "lib", "libhello_two.a")) | ||
| else: | ||
| assert "multi/0.1: package(): Packaged 1 '.h' file: hello_two.h" in client.out | ||
| assert "multi/0.1: package(): Packaged 1 '.lib' file: hello_two.lib" in client.out | ||
| package_folder = client.created_layout().package() | ||
|
|
||
| assert not os.path.exists(os.path.join(package_folder, "one", "include", "hello_one.h")) | ||
| assert not os.path.exists(os.path.join(package_folder, "one", "lib", "hello_one.lib")) | ||
|
|
||
| assert os.path.exists(os.path.join(package_folder, "two", "include", "hello_two.h")) | ||
| assert os.path.exists(os.path.join(package_folder, "two", "lib", "hello_two.lib")) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.