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

Do not set default dirs if there is no value #11614

Merged
merged 1 commit into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions conan/tools/cmake/toolchain/blocks.py
Expand Up @@ -854,13 +854,21 @@ def template(self):

return textwrap.dedent("""
set(CMAKE_INSTALL_PREFIX "{{package_folder}}")
{% if default_bin %}
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_INSTALL_BINDIR "{{default_bin}}")
set(CMAKE_INSTALL_SBINDIR "{{default_bin}}")
set(CMAKE_INSTALL_LIBEXECDIR "{{default_bin}}")
{% endif %}
{% if default_lib %}
set(CMAKE_INSTALL_LIBDIR "{{default_lib}}")
{% endif %}
{% if default_include %}
set(CMAKE_INSTALL_INCLUDEDIR "{{default_include}}")
set(CMAKE_INSTALL_OLDINCLUDEDIR "{{default_include}}")
{% endif %}
{% if default_res %}
set(CMAKE_INSTALL_DATAROOTDIR "{{default_res}}")
{% endif %}
""")

def _get_cpp_info_value(self, name):
Expand Down
91 changes: 91 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
Expand Up @@ -918,3 +918,94 @@ def test_cmake_presets_forbidden_build_type():
client.run("install . {}".format(settings_layout), assert_error=True)
assert "Error, don't include 'settings.build_type' in the " \
"'tools.cmake.cmake_layout:build_folder_vars' conf" in client.out


def test_resdirs_cmake_install():
"""If resdirs is declared, the CMAKE_INSTALL_DATAROOTDIR folder is set"""

client = TestClient(path_with_spaces=False)

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

class AppConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "CMakeLists.txt", "my_license"
name = "foo"
version = "1.0"

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def layout(self):
self.cpp.package.resdirs = ["res"]

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

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

cmake = """
cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_COMPILER_WORKS 1)
project(foo)
if(NOT CMAKE_INSTALL_DATAROOTDIR)
message(FATAL_ERROR "Cannot install stuff")
endif()
install(FILES my_license DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses)
"""

client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmake, "my_license": "MIT"})
client.run("create .")
assert "/res/licenses/my_license" in client.out
assert "Packaged 1 file: my_license" in client.out


def test_resdirs_none_cmake_install():
"""If no resdirs are declared, the CMAKE_INSTALL_DATAROOTDIR folder is not set"""

client = TestClient(path_with_spaces=False)

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

class AppConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
exports_sources = "CMakeLists.txt", "my_license"
name = "foo"
version = "1.0"

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

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

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

cmake = """
cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_COMPILER_WORKS 1)
project(foo)
if(NOT CMAKE_INSTALL_DATAROOTDIR)
message(FATAL_ERROR "Cannot install stuff")
endif()
"""

client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmake, "my_license": "MIT"})
client.run("create .", assert_error=True)
assert "Cannot install stuff" in client.out