Пример #1
0
class MultiProjectTestCase(unittest.TestCase):
    tempdir = tempfile.TemporaryDirectory(prefix='cpppm-tests-')
    build_path = Path(tempdir.name)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.project = Project('test',
                               build_path=self.build_path,
                               source_path=self.build_path)
        self.test1 = self.project.library('testlib1')
        self.subproject1 = Project('test-sp1',
                                   build_path=self.build_path / 'sp1',
                                   source_path=self.build_path / 'sp1')
        self.project._subprojects.add(self.subproject1)
        self.subproject1.library('sp-testlib1')

        self.stand_alone_project = Project('standalone-test',
                                           build_path=self.build_path,
                                           source_path=self.build_path)
        self.stand_alone_project.library('st-testlib1')

    def test_project_libraries(self):
        self.assertTrue('testlib1' in [t.name for t in self.project.targets])
        self.assertTrue(
            'sp-testlib1' in [t.name for t in self.project.targets])
        self.assertFalse(
            'st-testlib1' in [t.name for t in self.project.targets])
Пример #2
0
class ProjectBaseTestCase(unittest.TestCase):
    build_path = Path('/tmp/cpppm-tests/ProjectBaseTestCase-build')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.project = Project('test',
                               build_path=ProjectBaseTestCase.build_path)
        self.test1 = self.project.library('testlib1')
        self.test2 = self.project.library('testlib2')
        self.test3 = self.project.library('testlib3')
        self.test2.link_libraries = self.test3, 'boost'
        self.exe = self.project.main_executable()
        self.exe.link_libraries = self.test1, self.test2
        self.source_path = self.exe.source_path

    def test_compile_definitions(self):
        self.test1.compile_definitions = {'DEF1': None}
        self.test2.compile_definitions = {'DEF2.1': 21, 'DEF2.2': 22}
        self.test3.compile_definitions = {'DEF3.1': 31, 'DEF3.2': 32}
        self.assertTrue(self.test1.compile_definitions == {'DEF1': None})
        self.assertTrue(self.test2.compile_definitions == {
            'DEF2.1': 21,
            'DEF2.2': 22,
            'DEF3.1': 31,
            'DEF3.2': 32
        })
        self.assertTrue(self.test3.compile_definitions == {
            'DEF3.1': 31,
            'DEF3.2': 32
        })
        self.assertTrue(self.exe.compile_definitions == {
            'DEF1': None,
            'DEF2.1': 21,
            'DEF2.2': 22,
            'DEF3.1': 31,
            'DEF3.2': 32
        })

    def test_include_path(self):
        self.test1.include_dirs = 'test1', 'test1_inc'
        self.test2.include_dirs = 'test2', 'test2_inc'
        self.test3.include_dirs = 'test3', 'test3_inc'
        self.assertTrue(
            all(
                str(p) in {'test1', 'test1_inc'}
                for p in self.test1.include_dirs))
        self.assertTrue(
            all(
                str(p) in {'test2', 'test2_inc', 'test3', 'test3_inc'}
                for p in self.test2.include_dirs))
        self.assertTrue(
            all(
                str(p) in {'test3', 'test3_inc'}
                for p in self.test3.include_dirs))
        self.assertTrue(
            all(
                str(p) in {
                    'test1', 'test1_inc', 'test2', 'test2_inc', 'test3',
                    'test3_inc'
                } for p in self.exe.include_dirs))
Пример #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.project = Project('test',
                            build_path=ProjectBaseTestCase.build_path)
     self.test1 = self.project.library('testlib1')
     self.test2 = self.project.library('testlib2')
     self.test3 = self.project.library('testlib3')
     self.test2.link_libraries = self.test3, 'boost'
     self.exe = self.project.main_executable()
     self.exe.link_libraries = self.test1, self.test2
     self.source_path = self.exe.source_path
Пример #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.project = Project('test',
                               build_path=self.build_path,
                               source_path=self.build_path)
        self.test1 = self.project.library('testlib1')
        self.subproject1 = Project('test-sp1',
                                   build_path=self.build_path / 'sp1',
                                   source_path=self.build_path / 'sp1')
        self.project._subprojects.add(self.subproject1)
        self.subproject1.library('sp-testlib1')

        self.stand_alone_project = Project('standalone-test',
                                           build_path=self.build_path,
                                           source_path=self.build_path)
        self.stand_alone_project.library('st-testlib1')
Пример #5
0
#!/usr/bin/env python3
from cpppm import Project, main

project = Project('basic-project')
basic = project.library('basic')
basic.sources = {'include/basic.hpp', 'src/basic.cpp', 'src/private.hpp'}
basic.include_dirs = 'include'
basic.compile_definitions = {'DEF': None, 'DEFAULT_WHO': '\"cpppm\"'}
basic.shared = True
# same effect
# basic.static = True
hello = project.main_executable()
hello.sources = 'src/main.cpp'
hello.link_libraries = basic

if __name__ == '__main__':
    main()
Пример #6
0
#!/usr/bin/env python3
from cpppm import Project, main

project = Project('conan-requires')
project.requires = 'spdlog/1.8.1', 'doctest/2.3.6'
exe = project.main_executable()
exe.sources = 'src/main.cpp'
exe.link_libraries = 'spdlog', 'doctest'

if __name__ == '__main__':
    main()
Пример #7
0
#!/usr/bin/env python3
from cpppm import Project, main

project = Project('conan-test-package')
project.requires = 'cpppm-examples/0.0.0'

hello = project.main_executable()
hello.sources = 'main.cpp'
hello.link_libraries = 'cpppm-examples'

if __name__ == '__main__':
    main()
Пример #8
0
#!/usr/bin/env python3
from cpppm import Project, main

project = Project('header-only')

lib = project.main_library()
lib.sources = 'include/header_lib/header_lib.hpp'
lib.include_dirs = 'include'

lib.tests = 'tests/simple.test.cpp', 'tests/another.test.cpp'
lib.tests_backend = 'catch2/2.13.3'

if __name__ == '__main__':
    main()
Пример #9
0
#!/usr/bin/env python3
from cpppm import Project, main

project = Project('hello-cpppm')
hello = project.main_executable()
hello.sources = 'src/main.cpp'

if __name__ == '__main__':
    main()
Пример #10
0
#!/usr/bin/env python3

from cpppm import Project, main, Executable, Library

project = Project('g6-router')
project.requires = 'ctre/3.3.2'

router: Library = project.main_library()
router.include_dirs = 'include'
router.sources = 'include/g6/router.hpp'
router.link_libraries = 'ctre'
router.compile_options = '-std=c++20'

project.build_requires = 'boost/1.74.0', 'spdlog/1.8.1', 'fmt/7.1.2'
project.requires_options = {'boost:header_only': True}

# tests
router.tests_backend = 'catch2/2.13.3'

basic_test: Executable = project.executable('g6-router-basic-route-test')
basic_test.sources = 'tests/basic-route-test.cpp'
basic_test.link_libraries = 'fmt'

beast_example: Executable = project.executable('g6-http-router-example')
beast_example.sources = 'examples/http_router.cpp'
beast_example.link_libraries = router, 'boost', 'spdlog', 'fmt'

router.tests = basic_test, beast_example

if __name__ == '__main__':
    main()
Пример #11
0
#!/usr/bin/env python3
from pathlib import Path

from cpppm import Project, main
from git import Repo

project = Project('subdirectories')

ctti = Path('.deps/ctti')
if not ctti.exists():
    ctti_repo = Repo.clone_from('https://github.com/Manu343726/ctti.git',
                                to_path=ctti)
else:
    ctti_repo = Repo(ctti)
ctti_repo.remotes.origin.pull()

exe = project.main_executable()
exe.sources = 'src/main.cpp'
exe.include_dirs = ctti / 'include'
exe.subdirs = ctti.absolute()
exe.link_libraries = 'ctti'

if __name__ == '__main__':
    main()
Пример #12
0
#!/usr/bin/env python3

from cpppm import Project, main
from cpppm.config import config

project = Project('cpppm-examples', '0.0.0')

project.license = 'MIT'
project.description = 'CPP Package Manager example project'
project.url = 'https://github.com/Garcia6l20/cpppm'

project.subproject('hello_cpppm')
project.subproject('conan_requires')
project.subproject('basic_project')
project.subproject('header_only')

build_events = project.subproject('build_events')

project.default_executable = build_events.default_executable

config.toolchain.cxx_flags.append('/std:c++17' if config.toolchain.name ==
                                  'msvc' else '-std=c++17')

if __name__ == '__main__':
    main()
Пример #13
0
#!/usr/bin/env python3
from cpppm import Project, Executable, main, events
from cpppm.config import config

from ext_example.git import git_config_generator

project = Project('events')
project.requires = 'fmt/7.1.2'
# project.requires_options = {'fmt:header_only': True}

gen = project.executable('gen_date')
gen.install = False
gen.sources = 'src/generator.cpp'
gen.link_libraries = 'fmt'

exe = project.main_executable()
exe.sources = 'src/main.cpp'
exe.link_libraries = 'fmt'

exe.dependencies = git_config_generator(exe.build_path / 'generated' /
                                        'git_config.hpp')


# note:
#   as we are in a coroutine context (and other builds/runs might occurs)
#   paths must be handled as absolute (os.chdir might affect all running subprocesses)
#   if something like os.chdir is required, just don't use async/await (but generator call will be bocking)
@events.generator([exe.build_path / 'generated' / 'config.hpp'],
                  gen,
                  depends=gen)
async def config_generator(generator: Executable):