Skip to content

Commit 2b4066a

Browse files
authored
Merge pull request #18 from grisumbras/exports
Project exports for pkg-config and CMake.
2 parents c338bd6 + f725da3 commit 2b4066a

File tree

10 files changed

+208
-6
lines changed

10 files changed

+208
-6
lines changed

conanfile.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
from conans import (
22
ConanFile,
33
python_requires,
4+
tools,
45
)
6+
import os
7+
import re
58

69

710
b2 = python_requires("b2-helper/0.2.0@grisumbras/testing")
811

912

13+
def get_version():
14+
try:
15+
content = tools.load("jamroot.jam")
16+
match = re.search(r"constant\s*VERSION\s*:\s*(\S+)\s*;", content)
17+
return match.group(1)
18+
except:
19+
pass
20+
21+
1022
class EnumFlagsConan(b2.B2.Mixin, ConanFile):
1123
name = "enum-flags"
12-
version = "0.1.0"
24+
version = get_version()
1325
description = "Bit flags for C++ scoped enums"
1426
topics = "bit-mask", "bit-flag",
1527
author = "Dmitry Arkhipov <grisumbras@gmail.com>"
1628
license = "MIT"
1729
url = "https://github.com/grisumbras/enum-flags"
1830
homepage = url
1931

20-
exports_sources = "jamroot.jam", "build.jam", "*.hpp", "*.cpp", "LICENSE*",
32+
exports_sources = (
33+
"jamroot.jam",
34+
"*build.jam",
35+
"exports/*.jam",
36+
"*.hpp",
37+
"*.cpp",
38+
"LICENSE*",
39+
)
2140
no_copy_source = True
2241
build_requires = "boost_build/[>=1.68]@bincrafters/stable"
2342

2443
def package_info(self):
2544
self.info.header_only()
45+
46+
pkgconfig_dir = os.path.join(self.package_folder, "lib", "pkgconfig")
47+
self.env_info.PKG_CONFIG_PATH.append(pkgconfig_dir)
48+
49+
self.env_info.CMAKE_PREFIX_PATH.append(self.package_folder)

exports/build.jam

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import install-path ;
2+
import make ;
3+
import print ;
4+
5+
6+
prefix = [ install-path.prefix enum-flags ] ;
7+
execprefix = [ install-path.exec-prefix $(prefix) ] ;
8+
libdir = [ install-path.libdir $(execprefix) ] ;
9+
includedir = [ install-path.includedir $(prefix) ] ;
10+
11+
12+
make enum-flags.pc : : @write-pc ;
13+
install install-pc : enum-flags.pc : <location>$(libdir)/pkgconfig ;
14+
15+
make enumflags-config.cmake : : @write-cmake-config ;
16+
make enumflags-config-version.cmake : : @write-cmake-version ;
17+
install install-cmake
18+
: enumflags-config.cmake
19+
enumflags-config-version.cmake
20+
: <location>$(libdir)/cmake/enumflags-$(VERSION)
21+
;
22+
23+
alias install : install-pc install-cmake ;
24+
explicit install install-pc install-cmake ;
25+
26+
27+
rule write-pc ( target : sources * : properties * ) {
28+
write $(target)
29+
: "Name: enum-flags"
30+
"Description: Bit-flags for C++ scoped enums"
31+
"Version: $(VERSION)"
32+
"Cflags: -I$(includedir)"
33+
""
34+
;
35+
}
36+
37+
38+
rule write-cmake-config ( target : sources * : properties * ) {
39+
write $(target)
40+
: "if(TARGET EnumFlags::EnumFlags)"
41+
" return()"
42+
"endif()"
43+
""
44+
"add_library(EnumFlags::EnumFlags INTERFACE IMPORTED)"
45+
"set_target_properties("
46+
" EnumFlags::EnumFlags"
47+
" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"$(includedir)\""
48+
")"
49+
""
50+
;
51+
}
52+
53+
54+
rule write-cmake-version ( target : sources * : properties * ) {
55+
write $(target)
56+
: "set(PACKAGE_VERSION $(VERSION))"
57+
""
58+
"if(NOT PACKAGE_FIND_VERSION OR PACKAGE_FIND_VERSION EQUAL $(VERSION))"
59+
" set(PACKAGE_VERSION_EXACT TRUE)"
60+
" set(PACKAGE_VERSION_COMPATIBLE TRUE)"
61+
" set(PACKAGE_VERSION_UNSUITABLE FALSE)"
62+
"else()"
63+
" set(PACKAGE_VERSION_EXACT FALSE)"
64+
" set(PACKAGE_VERSION_COMPATIBLE FALSE)"
65+
" set(PACKAGE_VERSION_UNSUITABLE TRUE)"
66+
"endif()"
67+
""
68+
;
69+
}
70+
71+
72+
local rule write ( target : content * ) {
73+
print.output $(target) ;
74+
print.text $(content) ;
75+
}

exports/install-path.jam

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import modules ;
2+
import option ;
3+
import property ;
4+
5+
6+
rule prefix ( package-name : requirements * ) {
7+
local prefix
8+
= [ option.get prefix
9+
: [ property.select <install-default-prefix> : $(requirements) ]
10+
] ;
11+
prefix = $(prefix:G=) ;
12+
requirements
13+
= [ property.change $(requirements) : <install-default-prefix> ] ;
14+
15+
if ! $(prefix) {
16+
if [ modules.peek : NT ] {
17+
prefix = C:\\$(package-name) ;
18+
} else if [ modules.peek : UNIX ] {
19+
prefix = /usr/local ;
20+
}
21+
}
22+
return $(prefix) ;
23+
}
24+
25+
26+
rule exec-prefix ( prefix ) {
27+
return [ option.get execprefix : $(prefix) ] ;
28+
}
29+
30+
31+
rule libdir ( execprefix ) {
32+
return [ option.get libdir : $(execprefix)/lib ] ;
33+
}
34+
35+
36+
rule includedir ( prefix ) {
37+
return [ option.get includedir : $(prefix)/include ] ;
38+
}

jamroot.jam

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import path ;
44

55
project enum-flags ;
66

7+
constant VERSION : 0.1.0 ;
8+
79

810
alias libs : usage-requirements <include>include ;
911

@@ -18,5 +20,5 @@ explicit headers ;
1820

1921
package.install-data license : enum-flags : LICENSE ;
2022

21-
alias install : headers license ;
23+
alias install : headers license exports//install ;
2224
explicit install headers license ;

test/build.jam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import testing ;
22

33

4-
project
4+
project enum-flags-test
55
: requirements <warnings>all
66
<warnings-as-errors>on
77
: default-build <variant>release

test/cmake/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
project(EnumFlagsUser)
4+
5+
find_package(EnumFlags REQUIRED)
6+
7+
add_executable(app main.cpp)
8+
target_link_libraries(app EnumFlags::EnumFlags)

test/cmake/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <flags/flags.hpp>
2+
3+
int main() { return 0; }

test/conanfile.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
from conans import (
2+
CMake,
23
ConanFile,
34
python_requires,
45
)
6+
import os
57

68

79
b2 = python_requires("b2-helper/0.2.0@grisumbras/testing")
810

911

10-
class EnumFlagsTestConan(b2.B2.Mixin, ConanFile):
12+
class EnumFlagsTestConan(ConanFile):
1113
settings = "os", "compiler", "build_type", "arch", "cppstd",
1214
build_requires = (
1315
"boost_build/[>=1.68]@bincrafters/stable",
1416
"boost_core/[>1.60]@bincrafters/stable",
17+
"cmake_installer/[>3.0]@conan/stable",
1518
)
19+
generators = "b2"
1620

1721
def test(self):
18-
pass
22+
builder = b2.B2(self)
23+
builder.build_folder = os.path.join(self.build_folder, "base")
24+
builder.configure()
25+
builder.build()
26+
27+
builder = b2.B2(self)
28+
builder.source_folder = os.path.join(self.source_folder, "pkgconfig")
29+
builder.build_folder = os.path.join(self.build_folder, "pkgconfig")
30+
builder.configure()
31+
builder.build()
32+
33+
builder = CMake(self)
34+
builder.configure(
35+
source_folder=os.path.join(self.source_folder, "cmake"),
36+
build_folder=os.path.join(self.build_folder, "cmake"),
37+
)
38+
builder.build()

test/pkgconfig/jamroot.jam

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import errors ;
2+
import os ;
3+
import string ;
4+
5+
project enum-flags-test ;
6+
7+
exe app : main.cpp pkgconfig-enum-flags ;
8+
9+
10+
local rule pkgconfig ( package ) {
11+
local pkgconfig = [ os.environ PKG_CONFIG ] ;
12+
pkgconfig ?= pkg-config ;
13+
14+
local result
15+
= [ SHELL "$(pkgconfig) $(package) --cflags --libs"
16+
: exit-status strip-eol
17+
] ;
18+
if 0 != $(result[2]) {
19+
errors.error Could not find package '$(package)' with pkg-config
20+
"($(pkgconfig)):" $(result[1])! ;
21+
}
22+
23+
results = [ string.words $(result[1]) ] ;
24+
return <cxxflags>$(results) ;
25+
}
26+
27+
alias pkgconfig-enum-flags
28+
: usage-requirements [ pkgconfig enum-flags ]
29+
;

test/pkgconfig/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <flags/flags.hpp>
2+
3+
int main() { return 0; }

0 commit comments

Comments
 (0)