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

Feature/language cppstd #16314

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ def context(self):
is_win = self.conanfile.settings.get_safe("os") == "Windows"
auto_link = self.cmakedeps.get_property("cmake_set_interface_link_directories",
self.conanfile, check_type=bool)
link_languages = [lang if lang != "C++" else "CXX" for lang in self.conanfile.languages]
link_languages = ";".join(link_languages)

return {"pkg_name": self.pkg_name,
"root_target_name": self.root_target_name,
"config_suffix": self.config_suffix,
"config": self.configuration.upper(),
"deps_targets_names": ";".join(deps_targets_names),
"components_names": components_names,
"configuration": self.cmakedeps.configuration,
"set_interface_link_directories": auto_link and is_win}
"set_interface_link_directories": auto_link and is_win,
"link_languages": None}

@property
def template(self):
Expand Down Expand Up @@ -128,6 +132,9 @@ def template(self):
$<$<CONFIG:{{configuration}}>:{{ pkg_var(pkg_name, 'LIB_DIRS', config_suffix) }}>)
{%- endif %}

{% if link_languages %}
set_target_properties({{root_target_name}} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "{{link_languages}}")
{%- endif %}

{%- else %}

Expand Down
48 changes: 48 additions & 0 deletions test/functional/toolchains/cmake/cmakedeps/test_auto_stdcpp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import textwrap


def test_auto_cppstd(matrix_c_interface_client):
c = matrix_c_interface_client

consumer = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(myapp C)

find_package(matrix REQUIRED)

add_executable(app app.c)
target_link_libraries(app PRIVATE matrix::matrix)
""")

conanfile = textwrap.dedent("""\
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout

class Recipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
package_type = "application"
generators = "CMakeToolchain", "CMakeDeps"
requires = "matrix/0.1"

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
self.run(os.path.join(self.cpp.build.bindir, "app"), env="conanrun")
""")
app = textwrap.dedent("""
#include "matrix.h"
int main(){
matrix();
return 0;
}
""")
c.save({"conanfile.py": conanfile,
"CMakeLists.txt": consumer,
"app.c": app}, clean_first=True)
c.run("build .")
assert "Hello Matrix!" in c.out
89 changes: 89 additions & 0 deletions test/functional/toolchains/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import textwrap

import pytest

Expand Down Expand Up @@ -48,3 +49,91 @@ def transitive_libraries(_transitive_libraries):
c.cache_folder = os.path.join(temp_folder(), ".conan2")
shutil.copytree(_transitive_libraries.cache_folder, c.cache_folder)
return c


@pytest.fixture(scope="session")
def _matrix_c_interface_client():
c = TestClient()
matrix_h = textwrap.dedent("""\
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void matrix();
#ifdef __cplusplus
}
#endif
""")
matrix_cpp = textwrap.dedent("""\
#include "matrix.h"
#include <iostream>
#include <string>

void matrix(){
std::cout<< std::string("Hello Matrix!") <<std::endl;
}
""")
cmake = textwrap.dedent("""\
cmake_minimum_required(VERSION 3.15)
project(matrix C CXX)
add_library(matrix STATIC src/matrix.cpp)
target_include_directories(matrix PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(matrix PROPERTIES PUBLIC_HEADER "include/matrix.h")

install(TARGETS matrix EXPORT matrixConfig)
export(TARGETS matrix
NAMESPACE matrix::
FILE "${CMAKE_CURRENT_BINARY_DIR}/matrixConfig.cmake"
)

install(EXPORT matrixConfig
DESTINATION "${CMAKE_INSTALL_PREFIX}/matrix/cmake"
NAMESPACE matrix::
)
""")
conanfile = textwrap.dedent("""\
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout

class Recipe(ConanFile):
name = "matrix"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
package_type = "static-library"
generators = "CMakeToolchain"
exports_sources = "CMakeLists.txt", "src/*", "include/*"

languages = "C", "C++"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["matrix"]
""")
c.save({"include/matrix.h": matrix_h,
"src/matrix.cpp": matrix_cpp,
"conanfile.py": conanfile,
"CMakeLists.txt": cmake})
c.run("create .")
return c


@pytest.fixture()
def matrix_c_interface_client(_matrix_c_interface_client):
c = TestClient()
c.cache_folder = os.path.join(temp_folder(), ".conan2")
shutil.copytree(_matrix_c_interface_client.cache_folder, c.cache_folder)
return c
3 changes: 2 additions & 1 deletion test/integration/package_id/test_cache_compatibles.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ def package_info(self):
assert "pkg/0.1: CPPSTD: 17" in c.out

def test_check_min_cstd(self):
""" test that the check_min_cstd works fine with compatibility
"""
test that the check_min_cstd works fine with compatibility
"""
conanfile = textwrap.dedent("""
from conan import ConanFile
Expand Down