cslim icon indicating copy to clipboard operation
cslim copied to clipboard

CMake build, fix build with CPP_COMPILING, bug fixes

Open matlo607 opened this issue 6 years ago • 5 comments

I propose an alternative way to build CSlim using CMake and Conan. It creates a small dependency (CONAN_PKG::CppUTest in tests/CMakeLists.txt) on Conan that could be easily fixable by creating a package finder for CppUTest.

To build it with conan, create a file conanfile.txt at the root of the project with the following content.

[requires]
CppUTest/3.8@matthieu/testing

[generators]
cmake

[options]

Create a conanfile.py in another directory and put the following content inside (NB: this file should be published in a separated git repository and uploaded to Conan Center to distribute it directly via Conan).

from os import path
from conans import ConanFile, CMake, tools


class CppUTest(ConanFile):
    name = "CppUTest"
    version = "3.8"
    description = """C /C++ based unit xUnit test framework for unit testing and for test-driving your code"""
    license = "BSD 3-clause \"New\" or \"Revised\" License, https://github.com/cpputest/cpputest/blob/master/COPYING"
    url = "https://cpputest.github.io"
    settings = "os", "compiler", "arch", "build_type"
    source_dir = "{name}-{version}".format(name=name, version=version)
    options = {
        "shared": [True, False],
        "include_pdbs": [True, False],
        "fPIC": [True, False],
        "tests": [True, False],
        "extensions": [True, False]
    }
    default_options = (
        "shared=False",
        "include_pdbs=False",
        "fPIC=False",
        "tests=False",
        "extensions=True"
    )
    scm = {
        "type": "git",
        "subfolder": source_dir,
        "url": "https://github.com/cpputest/cpputest.git",
        "revision": "tags/v{version}".format(version=version)
    }

    def source(self):
        pass

    def build(self):
        cmake = CMake(self)
        #cmake.verbose = True
        cmake.definitions["TESTS"] = self.options.tests
        cmake.configure(source_dir=path.join(self.source_folder, self.source_dir))
        cmake.build()
        if self.options.tests:
            cmake.test()
        cmake.install()

    def package(self):
        pass

    def package_info(self):
        self.cpp_info.libs = ["CppUTest"]
        if self.options.extensions:
            self.cpp_info.libs.append("CppUTestExt")
        if self.settings.compiler == "Visual Studio":
            self.cpp_info.libs.append("winmm.lib")

And run:

mkdir -p conan-recipes/conan-CppUTest
cd conan-recipes/conan-CppUTest
vim conanfile.py
# put the above content in conanfile.py
conan create . matthieu/testing
cd ${CSlim_root}
mkdir build-dir && cd build-dir
conan install ..
cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/root ..
make
make test
make install

matlo607 avatar Jul 24 '18 10:07 matlo607

Thanks for the PR. It's always good to know that something is being used! It's nice to see a C language source package distribution system. How prolific is Conan?

While I appreciate the reformating, it makes this PR a chore to review. Any chance you would be willing to split the PR into a couple pieces? Reformating, CMAKE, and fixes?

dougbradbury avatar Jul 24 '18 14:07 dougbradbury

Conan is young but a dynamic community is building around it. Some big companies are beginning to adopt it. Yes I can split it but the commits are already atomic. Isn't the view by commit ok for reviewing ?

matlo607 avatar Jul 24 '18 16:07 matlo607

@dougbradbury , I split the commits. Please could you review the PRs ?

matlo607 avatar Jul 26 '18 10:07 matlo607

@matlo607 Is there anything still relevant in this PR?

dougbradbury avatar Jan 24 '19 13:01 dougbradbury

@dougbradbury, I rebased the branch on master. There are 2 fixes concerning clang-format. The other was merged, and then reverted. Should I create another PR for clang-format ?

matlo607 avatar Jan 24 '19 20:01 matlo607