Beispiel #1
0
    def test_one_comp_package_no_deps_plugin_test(self):
        comps = [{
            'header': 'file.h',
            'source': 'file.cpp',
            'driver': 'file.t.cpp'
        }]
        target = Package(pjoin('path', 'target'), [], comps)
        target.plugin_tests = True

        out = StringIO()
        generate([target], out)

        cmake = list(lex(out))

        find_command(cmake, 'add_library', ['file.t', 'SHARED'])
        find_command(cmake, 'target_link_libraries', ['file.t', 'target'])

        apple_start, _ = find_command(cmake, 'if', ['APPLE'])
        stmts = parse(iter(cmake[apple_start:]))[0]
        _, props = find_command(stmts[1], 'set_target_properties')

        assert ([
            'file.t', 'PROPERTIES', 'LINK_FLAGS', '"-undefined',
            'dynamic_lookup"'
        ] == props)

        win32_start, _ = find_command(cmake, 'if', ['WIN32'])
        stmts = parse(iter(cmake[win32_start:]))[0]

        _, props = find_command(stmts[1], 'target_link_options')
        assert (['file.t', 'PUBLIC', '/EXPORT:main'] == props)
Beispiel #2
0
    def test_empty_package_lazily_bound(self):
        p = Package('p', [], [])
        p.lazily_bound = True

        out = StringIO()
        generate([p], out)

        commands = list(lex(out))

        apple_start, _ = find_command(commands, 'if', ['APPLE'])
        stmts = parse(iter(commands[apple_start:]))[0]

        _, props = find_command(stmts[1], 'set_target_properties')
        assert ([
            'p', 'PROPERTIES', 'LINK_FLAGS', '"-undefined', 'dynamic_lookup"'
        ] == props)
Beispiel #3
0
    def test_empty_package_lazily_bound(self):
        p = Package('p', [], [])
        p.lazily_bound = True

        files = {}
        generate([p], get_filestore_writer(files))

        assert ('p.cmake' in files)
        commands = list(lex(files['p.cmake']))

        apple_start, _ = find_command(commands, 'if', ['APPLE'])
        stmts = parse(iter(commands[apple_start:]))[0]

        _, props = find_command(stmts[1], 'set_target_properties')
        assert ([
            'p', 'PROPERTIES', 'LINK_FLAGS', '"-undefined', 'dynamic_lookup"'
        ] == props)
Beispiel #4
0
    def test_pkg_config_generates_static_props(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package)

        files = {}
        generate([p], get_filestore_writer(files))

        cmake = files[f'{name}.cmake']
        commands = list(lex(cmake))
        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])
        stmts = parse(iter(commands[sh_lib_start:]))[0]

        static = {tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[2]}

        assert ((f'{name}_STATIC_INCLUDE_DIRS', ) in static)
        includes = static[(f'{name}_STATIC_INCLUDE_DIRS', )]
        assert ([] == includes[1])
        assert (1 == len(includes[0]))
        include = includes[0][0]
        assert ('target_include_directories' == include[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_INCLUDE_DIRS}}"'] == \
                                                                    include[1])

        assert ((f'{name}_STATIC_LDFLAGS', ) in static)
        ldflags = static[(f'{name}_STATIC_LDFLAGS', )]
        assert ([] == ldflags[1])
        assert (1 == len(ldflags[0]))
        ldflag = ldflags[0][0]
        assert ('target_link_libraries' == ldflag[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_LDFLAGS}}"'] == \
                                                                     ldflag[1])

        assert ((f'{name}_STATIC_CFLAGS_OTHER', ) in static)
        cflags = static[(f'{name}_STATIC_CFLAGS_OTHER', )]
        assert ([] == cflags[1])
        assert (1 == len(cflags[0]))
        cflag = cflags[0][0]
        assert ('target_compile_options' == cflag[0])
        assert([name, 'INTERFACE', f'"${{{name}_STATIC_CFLAGS_OTHER}}"'] == \
                                                                      cflag[1])
Beispiel #5
0
    def test_pkg_config_generates_shared_props(self):
        name = 'foo'
        package = 'bar'
        p = Pkg(name, package, [])

        out = StringIO()
        generate([p], out)

        commands = list(lex(out))
        sh_lib_start, _ = find_command(commands, 'if', ['BUILD_SHARED_LIBS'])
        stmts = parse(iter(commands[sh_lib_start:]))[0]

        shared = {tuple(stmt[0]): (stmt[1], stmt[2]) for stmt in stmts[1]}

        assert ((f'{name}_INCLUDE_DIRS', ) in shared)
        includes = shared[(f'{name}_INCLUDE_DIRS', )]
        assert ([] == includes[1])
        assert (1 == len(includes[0]))
        include = includes[0][0]
        assert ('target_include_directories' == include[0])
        assert([name, 'INTERFACE', f'"${{{name}_INCLUDE_DIRS}}"'] == \
                                                                    include[1])

        assert ((f'{name}_LDFLAGS', ) in shared)
        ldflags = shared[(f'{name}_LDFLAGS', )]
        assert ([] == ldflags[1])
        assert (1 == len(ldflags[0]))
        ldflag = ldflags[0][0]
        assert ('target_link_libraries' == ldflag[0])
        assert ([name, 'INTERFACE', f'"${{{name}_LDFLAGS}}"'] == ldflag[1])

        assert ((f'{name}_CFLAGS_OTHER', ) in shared)
        cflags = shared[(f'{name}_CFLAGS_OTHER', )]
        assert ([] == cflags[1])
        assert (1 == len(cflags[0]))
        cflag = cflags[0][0]
        assert ('target_compile_options' == cflag[0])
        assert ([name, 'INTERFACE', f'"${{{name}_CFLAGS_OTHER}}"'] == cflag[1])
Beispiel #6
0
def call_parse(*cmds):
    return parse(iter(cmds))