def test_CMakeConfigure(): r"""Test CMakeConfigure.""" src = scripts['c'][0] sourcedir = os.path.dirname(src) builddir = sourcedir # Test get_output_file out = CMakeConfigure.get_output_file(src, dont_build=True) assert_equal(out, builddir) out = CMakeConfigure.get_output_file(src, dont_build=True, builddir='.', working_dir=sourcedir) assert_equal(out, builddir) # Test get_flags out_A = CMakeConfigure.get_flags(dont_link=True) out_B = CMakeConfigure.get_flags(dont_link=True, outfile='.') assert_equal(out_A, out_B)
def test_create_include(): r"""Test create_include.""" target = 'target' tempdir = tempfile.gettempdir() fname_dll = os.path.join(tempdir, 'test.dll') fname_lib = os.path.join(tempdir, 'test.lib') for fname in [fname_dll, fname_lib]: with open(fname, 'w') as fd: fd.write('') assert(os.path.isfile(fname)) testlist = [(['-DYGG'], [], ['ADD_DEFINITIONS(-DYGG)']), (['-Wall'], [], ['ADD_DEFINITIONS(-Wall)']), (['/nologo'], [], ['ADD_DEFINITIONS(/nologo)']), (['-Iinclude_dir'], [], ['INCLUDE_DIRECTORIES(include_dir)']), ([], ['-lm'], ['TARGET_LINK_LIBRARIES(%s -lm)' % target]), ([], ['-Llib_dir'], ['LINK_DIRECTORIES(lib_dir)']), ([], ['/LIBPATH:"lib_dir"'], ['LINK_DIRECTORIES(lib_dir)']), ([], ['m'], ['TARGET_LINK_LIBRARIES(%s m)' % target])] if CMakeConfigure.add_libraries: # pragma: debug testlist += [([], [fname_dll], ['ADD_LIBRARY(test SHARED IMPORTED)']), ([], [fname_lib], ['ADD_LIBRARY(test STATIC IMPORTED)'])] else: tempdir_cp = tempdir if platform._is_win: # pragma: windows tempdir_cp = tempdir.replace('\\', re.escape('\\')) testlist += [([], [fname_dll], [('FIND_LIBRARY(TEST_LIBRARY NAMES %s ' 'test HINTS %s)') % (os.path.basename(fname_dll), tempdir_cp)]), ([], [fname_lib], [('FIND_LIBRARY(TEST_LIBRARY NAMES %s ' 'test HINTS %s)') % (os.path.basename(fname_lib), tempdir_cp)])] from yggdrasil.drivers.CModelDriver import CModelDriver CModelDriver.compile_dependencies() CMakeModelDriver.compile_dependencies() kws = {'compiler': CModelDriver.get_tool('compiler'), 'linker': CModelDriver.get_tool('linker')} for c, l, lines in testlist: out = CMakeConfigure.create_include(None, target, compiler_flags=c, linker_flags=l, verbose=True, **kws) for x in lines: try: assert(x in out) except AssertionError: # pragma: debug print("Could not find '%s':" % x) pprint.pprint(out) raise for fname in [fname_dll, fname_lib]: os.remove(fname) assert_raises(ValueError, CMakeConfigure.create_include, None, target, compiler_flags=['invalid'], **kws) assert_raises(ValueError, CMakeConfigure.create_include, None, target, linker_flags=['-invalid'], **kws) assert_raises(ValueError, CMakeConfigure.create_include, None, target, linker_flags=['/invalid'], **kws)