Skip to content

Commit

Permalink
Merge pull request #11719 from czoido/fix_default_dirs
Browse files Browse the repository at this point in the history
Port #11614 to 1.50.1
  • Loading branch information
czoido committed Jul 28, 2022
2 parents 1ec7559 + c096ae4 commit 302f83a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion conans/__init__.py
Expand Up @@ -20,4 +20,4 @@
SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, REVISIONS] # Server is always with revisions
DEFAULT_REVISION_V1 = "0"

__version__ = '1.50.0'
__version__ = '1.50.1'
1 change: 1 addition & 0 deletions conans/client/migrations_settings.py
Expand Up @@ -3713,3 +3713,4 @@
"""

settings_1_50_0 = settings_1_49_0
settings_1_50_1 = settings_1_50_0
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 302f83a

Please sign in to comment.