def test_libcxx_abi_flag(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86_64" c.settings.compiler = "gcc" c.settings.compiler.version = "11" c.settings.compiler.cppstd = "20" c.settings.compiler.libcxx = "libstdc++" c.settings.os = "Linux" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=0' in content c.settings.compiler.libcxx = "libstdc++11" toolchain = CMakeToolchain(c) content = toolchain.content # by default, no flag is output anymore, it is assumed the compiler default assert 'GLIBCXX_USE_CXX11_ABI' not in content # recipe workaround for older distros toolchain.blocks["libcxx"].values["glibcxx"] = "1" content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=1' in content # but maybe the conf is better c.conf["tools.gnu:define_libcxx11_abi"] = True toolchain = CMakeToolchain(c) content = toolchain.content assert '_GLIBCXX_USE_CXX11_ABI=1' in content
def test_user_toolchain(conanfile): toolchain = CMakeToolchain(conanfile) toolchain.blocks["user_toolchain"].values["paths"] = ["myowntoolchain.cmake"] content = toolchain.content assert 'include("myowntoolchain.cmake")' in content toolchain = CMakeToolchain(conanfile) content = toolchain.content assert 'include(' not in content
def test_user_toolchain(conanfile): toolchain = CMakeToolchain(conanfile) toolchain.blocks["user_toolchain"].user_toolchain = "myowntoolchain.cmake" content = toolchain.content assert 'include(myowntoolchain.cmake)' in content toolchain = CMakeToolchain(conanfile) content = toolchain.content assert 'include(' not in content
def generate(self): toolchain = CMakeToolchain(self) toolchain.variables["GSOAP_PATH"] = "." toolchain.variables["BUILD_TOOLS"] = True toolchain.variables["WITH_OPENSSL"] = self.options.with_openssl toolchain.variables["WITH_IPV6"] = self.options.with_ipv6 toolchain.variables["WITH_COOKIES"] = self.options.with_cookies toolchain.variables["WITH_C_LOCALE"] = self.options.with_c_locale toolchain.generate() deps = CMakeDeps(self) deps.generate()
def generate(self): cmake = CMakeDeps(self) cmake.generate() tc = CMakeToolchain(self) # Don't use Visual Studio as the CMAKE_GENERATOR if self.settings.compiler == "Visual Studio": tc.blocks["generic_system"].values["generator_platform"] = None tc.blocks["generic_system"].values["toolset"] = None tc.generate()
def generate(self): toolchain = CMakeToolchain(self) toolchain.variables["HINDSIGHT_WITH_FMT"] = self.options.with_fmt if self.settings.os == "Linux": toolchain.variables["HINDSIGHT_RESOLVER_BACKEND"] = self.options.resolver_backend toolchain.variables["HINDSIGHT_BUILD_TESTS"] = self.options.build_tests toolchain.variables["HINDSIGHT_BUILD_EXAMPLES"] = self.options.build_examples toolchain.variables["HINDSIGHT_BUILD_DOCS"] = self.options.build_docs toolchain.generate()
def test_variables_types(conanfile): generator_folder = temp_folder() conanfile.folders.set_base_generators(generator_folder) # This is a trick for 1.X to use base_generator and not install folder conanfile.folders.generators = "here" toolchain = CMakeToolchain(conanfile) toolchain.variables["FOO"] = True toolchain.generate() contents = load( os.path.join(conanfile.generators_folder, "conan_toolchain.cmake")) assert 'set(FOO ON CACHE BOOL "Variable FOO conan-toolchain defined")' in contents
def test_replace_block(conanfile): toolchain = CMakeToolchain(conanfile) class MyBlock(Block): template = "HelloWorld" def context(self): return {} toolchain.blocks["generic_system"] = MyBlock content = toolchain.content assert 'HelloWorld' in content assert 'CMAKE_C_COMPILER' not in content
def test_add_new_block(conanfile): toolchain = CMakeToolchain(conanfile) class MyBlock(Block): template = "Hello {{myvar}}!!!" def context(self): return {"myvar": "World"} toolchain.blocks["mynewblock"] = MyBlock content = toolchain.content assert 'Hello World!!!' in content assert 'CMAKE_C_COMPILER' in content
def generate(self): toolchain = CMakeToolchain(self) toolchain.variables["USUL_BUILD_TESTS"] = self.options.run_tests toolchain.variables["USUL_ENABLE_CODE_COVERAGE"] = False toolchain.variables["CMAKE_DEBUG_POSTFIX"] = "" toolchain.variables["CMAKE_VERBOSE_MAKEFILE"] = True toolchain.generate()
def generate(self): toolchain = CMakeToolchain(self) toolchain.variables["BUILD_SHARED_LIBS"] = self.options.shared toolchain.variables["ASSERT"] = self.settings.build_type == "Debug" toolchain.variables["ASSERT2"] = self.settings.build_type == "Debug" toolchain.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared toolchain.generate()
def test_extend_block(conanfile): toolchain = CMakeToolchain(conanfile) class MyBlock(GenericSystemBlock): template = "Hello {{build_type}}!!" def context(self): c = super(MyBlock, self).context() c["build_type"] = c["build_type"] + "Super" return c toolchain.blocks["generic_system"] = MyBlock content = toolchain.content assert 'Hello ReleaseSuper!!' in content assert 'CMAKE_BUILD_TYPE' not in content
def test_context_update(conanfile): toolchain = CMakeToolchain(conanfile) build_type = toolchain.blocks["generic_system"].values["build_type"] toolchain.blocks["generic_system"].values[ "build_type"] = "Super" + build_type content = toolchain.content assert 'set(CMAKE_BUILD_TYPE "SuperRelease"' in content
def test_apple_cmake_osx_sysroot_sdk_mandatory(os, os_sdk, arch, expected_sdk): """ Testing if CMAKE_OSX_SYSROOT is correctly set. Issue related: https://github.com/conan-io/conan/issues/10275 """ c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.os = os c.settings.os.sdk = os_sdk c.settings.build_type = "Release" c.settings.arch = arch c.settings.compiler = "apple-clang" c.settings.compiler.version = "13.0" c.settings.compiler.libcxx = "libc++" c.settings.compiler.cppstd = "17" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] with pytest.raises(ConanException) as excinfo: CMakeToolchain(c).content() assert "Please, specify a suitable value for os.sdk." % expected_sdk in str( excinfo.value)
def test_template_change(conanfile): toolchain = CMakeToolchain(conanfile) tmp = toolchain.blocks["generic_system"].template toolchain.blocks["generic_system"].template = tmp.replace( "CMAKE_C_COMPILER", "OTHER_THING") content = toolchain.content assert 'set(OTHER_THING clang)' in content
def test_template_change(conanfile): toolchain = CMakeToolchain(conanfile) tmp = toolchain.blocks["generic_system"].template toolchain.blocks["generic_system"].template = tmp.replace( "CMAKE_BUILD_TYPE", "OTHER_THING") content = toolchain.content assert 'set(OTHER_THING "Release"' in content
def test_msvc_xp_toolsets(): c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize( Settings({ "os": ["Windows"], "compiler": { "msvc": { "version": ["170"], "update": [None], "cppstd": ["98"], "toolset": [None, "v110_xp"] } }, "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) c.settings.build_type = "Release" c.settings.arch = "x86" c.settings.compiler = "msvc" c.settings.compiler.version = "170" c.settings.compiler.toolset = "v110_xp" c.settings.compiler.cppstd = "98" c.settings.os = "Windows" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) assert 'CMAKE_GENERATOR_TOOLSET "v110_xp"' in toolchain.content assert 'Visual Studio 11 2012' in toolchain.generator # As by the CMake docs, this has no effect for VS < 2015 assert 'CMAKE_CXX_STANDARD 98' in toolchain.content
def test_fpic_when_shared_true(conanfile_linux_shared, fPIC): conanfile_linux_shared.options.fPIC = fPIC toolchain = CMakeToolchain(conanfile_linux_shared) cmake_value = 'ON' if fPIC else 'OFF' content = toolchain.content assert 'set(CMAKE_POSITION_INDEPENDENT_CODE {})'.format( cmake_value) in content
def test_toolset_x64(conanfile_msvc): # https://github.com/conan-io/conan/issues/11144 conanfile_msvc.conf.define("tools.cmake.cmaketoolchain:toolset_arch", "x64") toolchain = CMakeToolchain(conanfile_msvc) assert 'set(CMAKE_GENERATOR_TOOLSET "v143,host=x64" CACHE STRING "" FORCE)' in toolchain.content assert 'Visual Studio 17 2022' in toolchain.generator assert 'CMAKE_CXX_STANDARD 20' in toolchain.content
def generate(self): deps = CMakeDeps(self) deps.generate() tc = CMakeToolchain(self) tc.variables["BUILD_EXAMPLES"] = self.options.with_examples tc.variables["BUILD_CONFIG"] = self.options.with_config tc.variables["BUILD_GLFW"] = self.options.with_glfw tc.variables["BUILD_IMGUI"] = self.options.with_imgui tc.generate()
def test_context_change(conanfile): toolchain = CMakeToolchain(conanfile) tmp = toolchain.blocks["generic_system"] def context(self): assert self return {"build_type": "SuperRelease"} tmp.context = types.MethodType(context, tmp) content = toolchain.content assert 'set(CMAKE_BUILD_TYPE "SuperRelease"' in content
def generate(self): tc = CMakeToolchain(self) tc.variables["UNITS_DOWNCAST_MODE"] = str(self.options.downcast_mode).upper() # if self._run_tests: # TODO Enable this when environment is supported in the Conan toolchain tc.variables["UNITS_BUILD_DOCS"] = bool(self.options.build_docs) tc.variables["UNITS_USE_LIBFMT"] = self._use_libfmt tc.generate() deps = CMakeDeps(self) deps.generate()
def test_context_change(conanfile): toolchain = CMakeToolchain(conanfile) tmp = toolchain.blocks["generic_system"] def context(self): assert self return {"compiler": None} tmp.context = types.MethodType(context, tmp) content = toolchain.content assert 'CMAKE_C_COMPILER' not in content
def generate(self): tc = CMakeToolchain(self) tc.generator = "Ninja Multi-Config" tc.variables["CMAKE_VERBOSE_MAKEFILE"] = "TRUE" if self.settings.os == "iOS": tc.variables["CMAKE_SYSTEM_NAME"] = "iOS" if self.settings.arch != "x86_64": tc.blocks["apple_system"].values[ "cmake_osx_architectures"] = "armv7;arm64" tc.generate() deps = CMakeDeps(self) deps.generate()
def generate(self): tc = CMakeToolchain(self) tc.variables["CMAKE_SYSTEM_NAME"] = "Generic" tc.variables["CMAKE_SYSTEM_PROCESSOR"] = "cortex-m4" # disable linking stage of cmake compiler test build (required for crosscompilation) tc.variables["CMAKE_TRY_COMPILE_TARGET_TYPE"] = "STATIC_LIBRARY" #tc.variables[""] = "" tc.generate() deps = CMakeDeps(self) deps.generate()
def generate(self): tc = CMakeToolchain(self, generator=os.getenv("CONAN_CMAKE_GENERATOR")) tc.variables["UNITS_DOWNCAST_MODE"] = str( self.options.downcast_mode).upper() # if self._run_tests: # TODO Enable this when environment is supported in the Conan toolchain tc.variables["UNITS_BUILD_DOCS"] = self.options.build_docs tc.generate() deps = CMakeDeps(self) deps.generate()
def generate(self): tc = CMakeToolchain(self) tc.variables["CMAKE_SYSTEM_NAME"] = "Generic" tc.variables["CMAKE_SYSTEM_PROCESSOR"] = "armv7" tc.variables["CMAKE_TRY_COMPILE_TARGET_TYPE"] = "STATIC_LIBRARY" # If the source folder is missing, we're doing a local build from the recipe folder. Local # recipe builds have a different include path than cache builds, since the source is not # copied into the build/install folder during local builds. if (self.source_folder is None): # local build # eg, ~/work/libtest/include/ tc.variables[ "CMAKE_INCLUDE_PATH"] = self.recipe_folder + "/include" else: # cache build # eg, ~/.conan/data/libtest/0.0.1/aptera/sandbox/build/b1b...b9f6/ tc.variables[ "CMAKE_INCLUDE_PATH"] = self.install_folder + "/include" tc.generate() deps = CMakeDeps(self) deps.generate()
def generate(self): tc = CMakeToolchain(self) # TODO refactor to conans qt if self.options.qt_install: qt_install = str(self.options.qt_install) qt_cmake_dir = os.path.join(qt_install, 'lib', 'cmake', 'Qt5') self.output.info("qt_cmake_dir: %s" % (qt_cmake_dir)) tc.variables["Qt5_DIR"] = qt_cmake_dir.replace('\\', '\\\\') tc.variables["BUILD_SERVERS"] = self.options.get_safe("enable_servers", default=False) tc.variables["BUILD_UI"] = self.options.get_safe("enable_ui", default=False) tc.generate() cmake = CMakeDeps(self) cmake.generate()
def generate(self): tc = CMakeToolchain(self) tc.variables["enable-debug"] = self.settings.build_type tc.variables["enable-tests"] = False tc.variables[ "LIB_INSTALL_DIR"] = "lib" # https://github.com/FluidSynth/fluidsynth/issues/476 tc.variables["BUILD_SHARED_LIBS"] = self.options.shared for o in [ "floats", "fpe-check", "trap-on-check", "portaudio", "aufile", "dbus", "ipv6", "jack", "ladspa", "libsndfile", "midishare", "opensles", "oboe", "network", "oss", "dsound", "waveout", "winmidi", "sdl2", "pkgconfig", "pulseaudio", "readline", "threads", "lash", "alsa", "systemd", "coreaudio", "coremidi", "framework" ]: tc.variables["enable-{}".format(o)] = self.options.get_safe(o) tc.generate() cmake = CMakeDeps(self) cmake.generate()
def test_apple_cmake_osx_sysroot(os, os_sdk, arch, expected_sdk): """ Testing if CMAKE_OSX_SYSROOT is correctly set. Issue related: https://github.com/conan-io/conan/issues/10275 """ c = ConanFile(Mock(), None) c.settings = "os", "compiler", "build_type", "arch" c.initialize(Settings.loads(get_default_settings_yml()), EnvValues()) c.settings.os = os c.settings.os.sdk = os_sdk c.settings.build_type = "Release" c.settings.arch = arch c.settings.compiler = "apple-clang" c.settings.compiler.version = "13.0" c.settings.compiler.libcxx = "libc++" c.settings.compiler.cppstd = "17" c.conf = Conf() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] toolchain = CMakeToolchain(c) content = toolchain.content assert 'set(CMAKE_OSX_SYSROOT %s CACHE STRING "" FORCE)' % expected_sdk in content