Skip to content

Commit

Permalink
Do not set default dirs if there is no value (conan-io#11614)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote authored and czoido committed Jul 28, 2022
1 parent 1ec7559 commit 501cbf5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
8 changes: 8 additions & 0 deletions conan/tools/cmake/toolchain/blocks.py
Expand Up @@ -852,13 +852,21 @@ def template(self):

return textwrap.dedent("""
set(CMAKE_INSTALL_PREFIX "{{package_folder}}")
{% if default_bin %}
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

0 comments on commit 501cbf5

Please sign in to comment.