-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix cmakedeps multi conditional (#15853)
* fix cmakedeps multi conditional * fix test * wip * fix * tried test faster, didn't work
- Loading branch information
1 parent
df77297
commit ea07cc3
Showing
5 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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
101 changes: 101 additions & 0 deletions
101
conans/test/functional/toolchains/cmake/cmakedeps/test_conditional_build_type.py
This file contains 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,101 @@ | ||
import textwrap | ||
|
||
from conans.test.utils.tools import TestClient | ||
|
||
|
||
def test_conditional_build_type(): | ||
# https://github.com/conan-io/conan/issues/15851 | ||
c = TestClient() | ||
# A header-only library can't be used for testing, it doesn't fail | ||
c.run("new cmake_lib -d name=pkga -d version=0.1") | ||
c.run("create . -s build_type=Debug -tf=") | ||
|
||
c.save({}, clean_first=True) | ||
c.run("new cmake_lib -d name=pkgb -d version=0.1 -d requires=pkga/0.1") | ||
conanfile = textwrap.dedent(""" | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps | ||
class pkgbRecipe(ConanFile): | ||
name = "pkgb" | ||
version = "0.1" | ||
package_type = "static-library" | ||
settings = "os", "compiler", "build_type", "arch" | ||
exports_sources = "CMakeLists.txt", "src/*", "include/*" | ||
def layout(self): | ||
cmake_layout(self) | ||
def generate(self): | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
tc = CMakeToolchain(self) | ||
if self.settings.build_type == "Debug": | ||
tc.cache_variables["USE_PKGA"] = 1 | ||
tc.preprocessor_definitions["USE_PKGA"] = 1 | ||
tc.generate() | ||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
def package_info(self): | ||
self.cpp_info.libs = ["pkgb"] | ||
def requirements(self): | ||
if self.settings.build_type == "Debug": | ||
self.requires("pkga/0.1") | ||
""") | ||
cmake = textwrap.dedent("""\ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(pkgb CXX) | ||
add_library(pkgb src/pkgb.cpp) | ||
target_include_directories(pkgb PUBLIC include) | ||
if(USE_PKGA) | ||
find_package(pkga CONFIG REQUIRED) | ||
target_link_libraries(pkgb PRIVATE pkga::pkga) | ||
endif() | ||
set_target_properties(pkgb PROPERTIES PUBLIC_HEADER "include/pkgb.h") | ||
install(TARGETS pkgb) | ||
""") | ||
pkgb_cpp = textwrap.dedent(r""" | ||
#include <iostream> | ||
#include "pkgb.h" | ||
#ifdef USE_PKGA | ||
#include "pkga.h" | ||
#endif | ||
void pkgb(){ | ||
#ifdef USE_PKGA | ||
pkga(); | ||
#endif | ||
#ifdef NDEBUG | ||
std::cout << "pkgb/0.1: Hello World Release!\n"; | ||
#else | ||
std::cout << "pkgb/0.1: Hello World Debug!\n"; | ||
#endif | ||
} | ||
""") | ||
c.save({"conanfile.py": conanfile, | ||
"CMakeLists.txt": cmake, | ||
"src/pkgb.cpp": pkgb_cpp}) | ||
c.run("create . -s build_type=Debug -tf=") | ||
assert "pkga/0.1" in c.out | ||
c.run("create . -s build_type=Release -tf=") # without dep to pkga | ||
assert "pkga" not in c.out | ||
|
||
c.save({}, clean_first=True) | ||
c.run("new cmake_lib -d name=pkgc -d version=0.1 -d requires=pkgb/0.1") | ||
c.run("build . -s build_type=Debug") | ||
c.run("build . -s build_type=Release") | ||
# This used to crash because "pkga::pkga" | ||
assert "conanfile.py (pkgc/0.1): Running CMake.build()" in c.out |
This file contains 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