Exemple #1
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator._aux_cmake_test_setup()

        # extract the conan_basic_setup macro
        macro = self._extract_macro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual("""macro(conan_basic_setup)
    conan_check_compiler()
    conan_output_dirs_setup()
    conan_set_find_library_paths()
    if(NOT "${ARGV0}" STREQUAL "TARGETS")
        message(STATUS "Conan: Using cmake global configuration")
        conan_global_flags()
    else()
        message(STATUS "Conan: Using cmake targets configuration")
        conan_define_targets()
    endif()
    conan_set_rpath()
    conan_set_vs_runtime()
    conan_set_libcxx()
    conan_set_find_paths()
endmacro()""", macro)

        # extract the conan_set_find_paths macro
        macro = self._extract_macro("conan_set_find_paths", aux_cmake_test_setup)
        self.assertEqual("""macro(conan_set_find_paths)
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})
endmacro()""", macro)
Exemple #2
0
 def cpp_info_name_cmake_vars_test(self):
     """
     Test cpp_info.names values are applied instead of the reference name
     """
     conanfile = ConanFile(TestBufferConanOutput(), None)
     conanfile.initialize(Settings({}), EnvValues())
     ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.name = "MyPkG"
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder2")
     cpp_info.name = "MyPkG2"
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     self.assertIn("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", content)
     content = content.replace("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", "")
     self.assertNotIn("my_pkg", content)
     self.assertNotIn("MY_PKG", content)
     self.assertIn('add_library(CONAN_PKG::MyPkG INTERFACE IMPORTED)',
                   content)
     self.assertIn('add_library(CONAN_PKG::MyPkG2 INTERFACE IMPORTED)',
                   content)
     self.assertNotIn('CONAN_PKG::my_pkg', content)
     self.assertNotIn('CONAN_PKG::my_pkg2', content)
Exemple #3
0
 def multi_flag_test(self):
     conanfile = ConanFile(TestBufferConanOutput(), None)
     conanfile.initialize(Settings({}), EnvValues())
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.name = ref.name
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cxxflags = [
         "-DGTEST_USE_OWN_TR1_TUPLE=1", "-DGTEST_LINKED_AS_SHARED_LIBRARY=1"
     ]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder2")
     cpp_info.name = ref.name
     cpp_info.cflags = ["-DSOMEFLAG=1"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_C_FLAGS_MYPKG2 "-DSOMEFLAG=1")', cmake_lines)
     self.assertIn(
         'set(CONAN_CXX_FLAGS_MYPKG "-DGTEST_USE_OWN_TR1_TUPLE=1'
         ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1")', cmake_lines)
     self.assertIn('set(CONAN_C_FLAGS "-DSOMEFLAG=1 ${CONAN_C_FLAGS}")',
                   cmake_lines)
     self.assertIn(
         'set(CONAN_CXX_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1'
         ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ${CONAN_CXX_FLAGS}")',
         cmake_lines)
Exemple #4
0
    def variables_setup_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = ref.name
        cpp_info.defines = ["MYDEFINE1"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.name = ref.name
        cpp_info.defines = ["MYDEFINE2"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.deps_user_info["LIB1"].myvar = "myvalue"
        conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
        conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
        generator = CMakeGenerator(conanfile)
        content = generator.content
        cmake_lines = content.splitlines()
        self.assertIn('set(CONAN_DEFINES_MYPKG "-DMYDEFINE1")', cmake_lines)
        self.assertIn('set(CONAN_DEFINES_MYPKG2 "-DMYDEFINE2")', cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG "MYDEFINE1")',
                      cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG2 "MYDEFINE2")',
                      cmake_lines)

        self.assertIn('set(CONAN_USER_LIB1_myvar "myvalue")', cmake_lines)
        self.assertIn('set(CONAN_USER_LIB1_myvar2 "myvalue2")', cmake_lines)
        self.assertIn('set(CONAN_USER_LIB2_MYVAR2 "myvalue4")', cmake_lines)
Exemple #5
0
    def apple_frameworks_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.os = "Macos"
        settings.compiler = "apple-clang"
        settings.compiler.version = "9.1"
        settings.compiler.libcxx = "libc++"
        settings.arch = "x86_64"
        settings.build_type = "Debug"
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = ref.name
        cpp_info.framework_paths.extend(
            ["path/to/Frameworks1", "path/to/Frameworks2"])
        cpp_info.frameworks = ["OpenGL", "OpenCL"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.settings = settings

        generator = CMakeGenerator(conanfile)
        content = generator.content
        self.assertIn(
            'find_library(CONAN_FRAMEWORK_OPENGL OpenGL PATHS '
            '"path/to/Frameworks1"\n\t\t\t"path/to/Frameworks2")', content)
        self.assertIn(
            'find_library(CONAN_FRAMEWORK_OPENCL OpenCL PATHS '
            '"path/to/Frameworks1"\n\t\t\t"path/to/Frameworks2")', content)
        self.assertIn(
            'set(CONAN_LIBS_MYPKG  ${CONAN_FRAMEWORK_OPENGL} '
            '${CONAN_FRAMEWORK_OPENCL})', content)
        self.assertIn(
            'set(CONAN_LIBS  ${CONAN_FRAMEWORK_OPENGL} '
            '${CONAN_FRAMEWORK_OPENCL} ${CONAN_LIBS})', content)
Exemple #6
0
 def name_and_version_are_generated_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     conanfile.name = "MyPkg"
     conanfile.version = "1.1.0"
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_PACKAGE_NAME MyPkg)', cmake_lines)
     self.assertIn('set(CONAN_PACKAGE_VERSION 1.1.0)', cmake_lines)
Exemple #7
0
 def test_cmake(self):
     generator = CMakeGenerator(self.conanfile)
     content = generator.content
     self.assertNotIn("MyPkG", content)
     self.assertNotIn("MyPkG2", content)
     self.assertIn('add_library(CONAN_PKG::MyCMakeName INTERFACE IMPORTED)',
                   content)
     self.assertIn(
         'add_library(CONAN_PKG::MyCMakeName2 INTERFACE IMPORTED)', content)
Exemple #8
0
 def test_name_and_version_are_generated(self):
     conanfile = ConanFile(Mock(), None)
     conanfile.initialize(Settings({}), EnvValues())
     conanfile.name = "MyPkg"
     conanfile.version = "1.1.0"
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_PACKAGE_NAME MyPkg)', cmake_lines)
     self.assertIn('set(CONAN_PACKAGE_VERSION 1.1.0)', cmake_lines)
Exemple #9
0
 def cmake_test(self):
     generator = CMakeGenerator(self.conanfile)
     content = generator.content
     self.assertIn("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", content)
     content = content.replace("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", "")
     self.assertNotIn("my_pkg", content)
     self.assertNotIn("MY_PKG", content)
     self.assertIn('add_library(CONAN_PKG::MyPkG INTERFACE IMPORTED)', content)
     self.assertIn('add_library(CONAN_PKG::MyPkG2 INTERFACE IMPORTED)', content)
     self.assertNotIn('CONAN_PKG::my_pkg', content)
     self.assertNotIn('CONAN_PKG::my_pkg2', content)
Exemple #10
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator.content

        # extract the conan_basic_setup macro
        macro = self._extract_macro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_basic_setup)
    if(CONAN_EXPORTED)
        message(STATUS "Conan: called by CMake conan helper")
    endif()
    conan_check_compiler()
    conan_output_dirs_setup()
    conan_set_find_library_paths()
    if(NOT "${ARGV0}" STREQUAL "TARGETS")
        message(STATUS "Conan: Using cmake global configuration")
        conan_global_flags()
    else()
        message(STATUS "Conan: Using cmake targets configuration")
        conan_define_targets()
    endif()
    conan_set_rpath()
    conan_set_vs_runtime()
    conan_set_libcxx()
    conan_set_find_paths()
endmacro()""", macro)

        # extract the conan_set_find_paths macro
        macro = self._extract_macro("conan_set_find_paths",
                                    aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_set_find_paths)
    # CMAKE_MODULE_PATH does not have Debug/Release config, but there are variables
    # CONAN_CMAKE_MODULE_PATH_DEBUG to be used by the consumer
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})

    # Set the find root path (cross build)
    set(CMAKE_FIND_ROOT_PATH ${CONAN_CMAKE_FIND_ROOT_PATH} ${CMAKE_FIND_ROOT_PATH})
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
        set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
        set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
        set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
    endif()
endmacro()""", macro)
Exemple #11
0
 def cmake_test(self):
     generator = CMakeGenerator(self.conanfile)
     content = generator.content
     self.assertNotIn("not-a-cmake-module.pc", content)
     self.assertIn('set(CONAN_BUILD_MODULES_PATHS "dummy_root_folder1/my-module.cmake"'
                   '\n\t\t\t"dummy_root_folder2/other-mod.cmake" ${CONAN_BUILD_MODULES_PATHS})',
                   content)
     self.assertIn('set(CONAN_BUILD_MODULES_PATHS_MY_PKG "dummy_root_folder1/my-module.cmake")',
                   content)
     self.assertIn('set(CONAN_BUILD_MODULES_PATHS_MY_PKG2 "dummy_root_folder2/other-mod.cmake")',
                   content)
     self.assertIn("macro(conan_include_build_modules)", content)
     self.assertIn("conan_include_build_modules()", content)
Exemple #12
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator._aux_cmake_test_setup()

        # extract the conan_basic_setup macro
        macro = self.extractMacro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual("""macro(conan_basic_setup)
    conan_check_compiler()
    conan_output_dirs_setup()
    conan_flags_setup()
    conan_set_find_paths()
endmacro()""", macro)
        
        # extract the conan_set_find_paths macro
        macro = self.extractMacro("conan_set_find_paths", aux_cmake_test_setup)
        self.assertEqual("""macro(conan_set_find_paths)
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})
endmacro()""", macro)
Exemple #13
0
 def escaped_flags_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-load", r"C:\foo\bar.dll"]
     cpp_info.cflags = ["-load", r"C:\foo\bar2.dll"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn(r'set(CONAN_C_FLAGS_MYPKG "-load C:\\foo\\bar2.dll")',
                   cmake_lines)
     self.assertIn(r'set(CONAN_CXX_FLAGS_MYPKG "-load C:\\foo\\bar.dll")',
                   cmake_lines)
Exemple #14
0
 def variables_setup_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.defines = ["MYDEFINE1"]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder2")
     cpp_info.defines = ["MYDEFINE2"]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn("set(CONAN_DEFINES_MYPKG -DMYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_DEFINES_MYPKG2 -DMYDEFINE2)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG MYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG2 MYDEFINE2)", cmake_lines)
Exemple #15
0
 def escaped_flags_test(self):
     conanfile = ConanFile(TestBufferConanOutput(), None)
     conanfile.initialize(Settings({}), EnvValues())
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo(ref.name, "dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cxxflags = ["-load", r"C:\foo\bar.dll"]
     cpp_info.cflags = ["-load", r"C:\foo\bar2.dll"]
     cpp_info.defines = ['MY_DEF=My string', 'MY_DEF2=My other string']
     conanfile.deps_cpp_info.add(ref.name, cpp_info)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn(r'set(CONAN_C_FLAGS_MYPKG "-load C:\\foo\\bar2.dll")', cmake_lines)
     self.assertIn(r'set(CONAN_CXX_FLAGS_MYPKG "-load C:\\foo\\bar.dll")', cmake_lines)
     self.assertIn(r'set(CONAN_DEFINES_MYPKG "-DMY_DEF=My string"', cmake_lines)
     self.assertIn('\t\t\t"-DMY_DEF2=My other string")', cmake_lines)
Exemple #16
0
 def paths_cmake_test(self):
     settings_mock = _MockSettings()
     conanfile = ConanFile(TestBufferConanOutput(), None)
     conanfile.initialize(settings_mock, EnvValues())
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     tmp_folder = temp_folder()
     save(os.path.join(tmp_folder, "lib", "mylib.lib"), "")
     save(os.path.join(tmp_folder, "include", "myheader.h"), "")
     cpp_info = CppInfo(ref.name, tmp_folder)
     cpp_info.release.libs = ["hello"]
     cpp_info.debug.libs = ["hello_D"]
     conanfile.deps_cpp_info.add(ref.name, cpp_info)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     content = content.replace(tmp_folder.replace("\\", "/"), "root_folder")
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_INCLUDE_DIRS_MYPKG_RELEASE "root_folder/include")', cmake_lines)
     self.assertIn('set(CONAN_LIB_DIRS_MYPKG_RELEASE "root_folder/lib")', cmake_lines)
Exemple #17
0
 def paths_cmake_test(self):
     settings_mock = namedtuple("Settings", "build_type, os, os_build, constraint, items")
     conanfile = ConanFile(None, None)
     conanfile.initialize(settings_mock(None, None, None, lambda x, raise_undefined_field: x,
                                        lambda: {}), EnvValues())
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     tmp_folder = temp_folder()
     save(os.path.join(tmp_folder, "lib", "mylib.lib"), "")
     save(os.path.join(tmp_folder, "include", "myheader.h"), "")
     cpp_info = CppInfo(tmp_folder)
     cpp_info.release.libs = ["hello"]
     cpp_info.debug.libs = ["hello_D"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     content = content.replace(tmp_folder.replace("\\", "/"), "root_folder")
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_INCLUDE_DIRS_MYPKG_RELEASE "root_folder/include")', cmake_lines)
     self.assertIn('set(CONAN_LIB_DIRS_MYPKG_RELEASE "root_folder/lib")', cmake_lines)
Exemple #18
0
 def settings_are_generated_tests(self):
     settings = Settings.loads(default_settings_yml)
     settings.os = "Windows"
     settings.compiler = "Visual Studio"
     settings.compiler.version = "12"
     settings.compiler.runtime = "MD"
     settings.arch = "x86"
     settings.build_type = "Debug"
     conanfile = ConanFile(None, None, Settings({}), None)
     conanfile.settings = settings
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_SETTINGS_BUILD_TYPE "Debug")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_ARCH "x86")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER "Visual Studio")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER_VERSION "12")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER_RUNTIME "MD")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_OS "Windows")', cmake_lines)
Exemple #19
0
    def test_apple_frameworks(self):
        settings = Settings.loads(get_default_settings_yml())
        settings.os = "Macos"
        settings.compiler = "apple-clang"
        settings.compiler.version = "9.1"
        settings.compiler.libcxx = "libc++"
        settings.arch = "x86_64"
        settings.build_type = "Debug"
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())
        conanfile.settings = settings

        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.frameworkdirs.extend(
            ["path/to/Frameworks1", "path/to/Frameworks2"])
        cpp_info.frameworks = ["OpenGL", "OpenCL"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        generator = CMakeGenerator(conanfile)
        content = generator.content
        self.assertIn(
            'find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS'
            ' ${CONAN_FRAMEWORK_DIRS${SUFFIX}} CMAKE_FIND_ROOT_PATH_BOTH)',
            content)
        self.assertIn(
            'set(CONAN_FRAMEWORK_DIRS "dummy_root_folder1/Frameworks"\n'
            '\t\t\t"dummy_root_folder1/path/to/Frameworks1"\n'
            '\t\t\t"dummy_root_folder1/path/to/Frameworks2" '
            '${CONAN_FRAMEWORK_DIRS})', content)
        self.assertIn(
            'set(CONAN_LIBS ${CONAN_LIBS} ${CONAN_SYSTEM_LIBS} '
            '${CONAN_FRAMEWORKS_FOUND})', content)

        generator = CMakeFindPackageGenerator(conanfile)
        content = generator.content
        content = content['FindMyPkg.cmake']
        self.assertIn(
            'conan_find_apple_frameworks(MyPkg_FRAMEWORKS_FOUND "${MyPkg_FRAMEWORKS}"'
            ' "${MyPkg_FRAMEWORK_DIRS}")', content)
Exemple #20
0
    def apple_frameworks_test(self):
        settings = Settings.loads(get_default_settings_yml())
        settings.os = "Macos"
        settings.compiler = "apple-clang"
        settings.compiler.version = "9.1"
        settings.compiler.libcxx = "libc++"
        settings.arch = "x86_64"
        settings.build_type = "Debug"
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = ref.name
        cpp_info.framework_paths.extend(
            ["path/to/Frameworks1", "path/to/Frameworks2"])
        cpp_info.frameworks = ["OpenGL", "OpenCL"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.settings = settings

        generator = CMakeGenerator(conanfile)
        content = generator.content
        self.assertIn(
            'find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS'
            ' ${CONAN_FRAMEWORK_DIRS${SUFFIX}})', content)
        self.assertIn(
            'set(CONAN_FRAMEWORK_DIRS "path/to/Frameworks1"\n\t\t\t"path/to/Frameworks2" '
            '${CONAN_FRAMEWORK_DIRS})', content)
        self.assertIn(
            'set(CONAN_LIBS ${CONAN_LIBS} ${CONAN_SYSTEM_LIBS} '
            '${CONAN_FRAMEWORKS_FOUND})', content)

        generator = CMakeFindPackageGenerator(conanfile)
        content = generator.content
        content = content['FindMyPkg.cmake']
        self.assertIn(
            'conan_find_apple_frameworks(MyPkg_FRAMEWORKS_FOUND "${MyPkg_FRAMEWORKS}"'
            ' "${MyPkg_FRAMEWORK_DIRS}")', content)
Exemple #21
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator.content

        # extract the conan_basic_setup macro
        macro = self._extract_macro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_basic_setup)
    set(options TARGETS NO_OUTPUT_DIRS SKIP_RPATH KEEP_RPATHS SKIP_STD SKIP_FPIC)
    cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

    if(CONAN_EXPORTED)
        conan_message(STATUS "Conan: called by CMake conan helper")
    endif()

    if(CONAN_IN_LOCAL_CACHE)
        conan_message(STATUS "Conan: called inside local cache")
    endif()

    if(NOT ARGUMENTS_NO_OUTPUT_DIRS)
        conan_message(STATUS "Conan: Adjusting output directories")
        conan_output_dirs_setup()
    endif()

    if(NOT ARGUMENTS_TARGETS)
        conan_message(STATUS "Conan: Using cmake global configuration")
        conan_global_flags()
    else()
        conan_message(STATUS "Conan: Using cmake targets configuration")
        conan_define_targets()
    endif()

    if(ARGUMENTS_SKIP_RPATH)
        # Change by "DEPRECATION" or "SEND_ERROR" when we are ready
        conan_message(WARNING "Conan: SKIP_RPATH is deprecated, it has been renamed to KEEP_RPATHS")
    endif()

    if(NOT ARGUMENTS_SKIP_RPATH AND NOT ARGUMENTS_KEEP_RPATHS)
        # Parameter has renamed, but we keep the compatibility with old SKIP_RPATH
        conan_message(STATUS "Conan: Adjusting default RPATHs Conan policies")
        conan_set_rpath()
    endif()

    if(NOT ARGUMENTS_SKIP_STD)
        conan_message(STATUS "Conan: Adjusting language standard")
        conan_set_std()
    endif()

    if(NOT ARGUMENTS_SKIP_FPIC)
        conan_set_fpic()
    endif()

    conan_check_compiler()
    conan_set_libcxx()
    conan_set_vs_runtime()
    conan_set_find_paths()
    conan_include_build_modules()
    conan_set_find_library_paths()
endmacro()""", macro)

        # extract the conan_set_find_paths macro
        macro = self._extract_macro("conan_set_find_paths",
                                    aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_set_find_paths)
    # CMAKE_MODULE_PATH does not have Debug/Release config, but there are variables
    # CONAN_CMAKE_MODULE_PATH_DEBUG to be used by the consumer
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})

    # Set the find root path (cross build)
    set(CMAKE_FIND_ROOT_PATH ${CONAN_CMAKE_FIND_ROOT_PATH} ${CMAKE_FIND_ROOT_PATH})
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
        set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
        set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
        set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
    endif()
endmacro()""", macro)