forked from azriel91/googletest-conan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
110 lines (90 loc) · 5.7 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from conans import ConanFile
import os
class GoogleTestConan(ConanFile):
name = 'googletest'
license = 'Copyright 2008, Google Inc.' # See https://github.com/google/googletest/blob/release-1.7.0/LICENSE
version = '1.7.0'
settings = ['os', 'compiler', 'build_type', 'arch']
generators = ['cmake']
url = 'https://github.com/google/googletest-conan.git'
options = {
'BUILD_SHARED_LIBS': ['ON', 'OFF'], # Build shared libraries (DLLs).
'gtest_force_shared_crt': ['ON', 'OFF'], # Use shared (DLL) run-time lib even when Google Test is built as static lib.
'gtest_build_tests': ['ON', 'OFF'], # Build all of gtest's own tests.
'gtest_build_samples': ['ON', 'OFF'], # Build gtest's sample programs.
'gtest_disable_pthreads': ['ON', 'OFF'], # Disable uses of pthreads in gtest.
# Set this to 0 if your project already uses a tuple library, and GTest should use that library
# Set this to 1 if GTest should use its own tuple library
'GTEST_USE_OWN_TR1_TUPLE': [None, '0', '1'],
# Set this to 0 if GTest should not use tuple at all. All tuple features will be disabled
'GTEST_HAS_TR1_TUPLE': [None, '0'],
# If GTest incorrectly detects whether or not the pthread library exists on your system, you can force it
# by setting this option value to:
# 1 - if pthread does actually exist
# 0 - if pthread does not actually exist
'GTEST_HAS_PTHREAD': [None, '0', '1']
}
default_options = ('BUILD_SHARED_LIBS=OFF',
'gtest_force_shared_crt=ON',
'gtest_build_tests=OFF',
'gtest_build_samples=OFF',
'gtest_disable_pthreads=OFF',
'GTEST_USE_OWN_TR1_TUPLE=None',
'GTEST_HAS_TR1_TUPLE=None',
'GTEST_HAS_PTHREAD=None')
build_dir = 'build'
def source(self):
google_test_url = 'https://github.com/google/googletest.git'
release_tag = 'release-{version}'.format(version=self.version)
self.run("git clone {url} --branch {branch} --depth 1".format(url=google_test_url, branch=release_tag))
def build(self):
if not os.path.isdir("{conan_dir}{sep}{src_dir}".format(conan_dir=self.conanfile_directory, sep=os.sep, src_dir=self.name)):
self.source()
option_defines = ' '.join("-D%s=%s" % (opt, val) for (opt, val) in self.options.iteritems() if val is not None)
option_defines += ' -DGTEST_CREATE_SHARED_LIBRARY=' + ('1' if self.options['BUILD_SHARED_LIBS'] == 'ON' else '0')
self.run("cmake {src_dir} -B{build_dir} {defines}".format(src_dir=self.name,
build_dir=self.build_dir,
defines=option_defines))
self.run("cmake --build {build_dir}".format(build_dir=self.build_dir))
def package(self):
self.copy('*', dst='cmake', src="{src_dir}/cmake".format(src_dir=self.name), keep_path=True)
self.copy('*', dst='include', src="{src_dir}/include".format(src_dir=self.name), keep_path=True)
self.copy('CMakeLists.txt', dst='.', src=self.name, keep_path=True)
# google mock compiles with google test sources
self.copy('*', dst='src', src="{src_dir}/src".format(src_dir=self.name), keep_path=True)
# Meta files
self.copy('CHANGES', dst='.', src=self.name, keep_path=True)
self.copy('CONTRIBUTORS', dst='.', src=self.name, keep_path=True)
self.copy('LICENSE', dst='.', src=self.name, keep_path=True)
self.copy('README', dst='.', src=self.name, keep_path=True)
# Built artifacts
self.copy('*.lib', dst='lib', src=self.build_dir, keep_path=False)
self.copy('*.dll', dst='bin', src=self.build_dir, keep_path=False)
if self.options['BUILD_SHARED_LIBS'] == 'ON':
self.copy('libgtest.so', dst='lib', src=self.build_dir, keep_path=False)
self.copy('libgtest_main.so', dst='lib', src=self.build_dir, keep_path=False)
else:
self.copy('libgtest.a', dst='lib', src=self.build_dir, keep_path=False)
self.copy('libgtest_main.a', dst='lib', src=self.build_dir, keep_path=False)
# Commented code intentionally left here
# ======================================
# IDE sample files
# self.copy('*', dst='codegear', src="{src_dir}/codegear".format(src_dir=self.name))
# self.copy('*', dst='m4', src="{src_dir}/m4".format(src_dir=self.name))
# self.copy('*', dst='make', src="{src_dir}/make".format(src_dir=self.name))
# self.copy('*', dst='msvc', src="{src_dir}/msvc".format(src_dir=self.name))
# self.copy('*', dst='xcode', src="{src_dir}/xcode".format(src_dir=self.name))
# Autoconf/Automake
# self.copy('configure.ac', dst='configure.ac', src=self.name)
# self.copy('Makefile.am', dst='Makefile.am', src=self.name)
# self.copy('*', dst='samples', src="{src_dir}/samples".format(src_dir=self.name))
# Files not used by downstream
# self.copy('*', dst='build-aux', src="{src_dir}/build-aux".format(src_dir=self.name))
# self.copy('*', dst='scripts', src="{src_dir}/scripts".format(src_dir=self.name))
# self.copy('*', dst='test', src="{src_dir}/test".format(src_dir=self.name))
def package_info(self):
self.cpp_info.libs.append('gtest')
if self.options['BUILD_SHARED_LIBS'] == 'ON':
self.cpp_info.defines.append("GTEST_LINKED_AS_SHARED_LIBRARY=1")
if self.settings.os == 'Linux' or self.options['GTEST_HAS_PTHREAD'] == '1':
self.cpp_info.libs.append('pthread')