Create build2 project

This commit is contained in:
Francois Kritzinger 2023-07-13 09:29:01 +02:00
commit fa16a2aa5c
22 changed files with 333 additions and 0 deletions

19
.gitattributes vendored Normal file
View File

@ -0,0 +1,19 @@
# This is a good default: files that are auto-detected by git to be text are
# converted to the platform-native line ending (LF on Unix, CRLF on Windows)
# in the working tree and to LF in the repository.
#
* text=auto
# Use `eol=crlf` for files that should have the CRLF line ending both in the
# working tree (even on Unix) and in the repository.
#
#*.bat text eol=crlf
# Use `eol=lf` for files that should have the LF line ending both in the
# working tree (even on Windows) and in the repository.
#
#*.sh text eol=lf
# Use `binary` to make sure certain files are never auto-detected as text.
#
#*.png binary

31
.gitignore vendored Normal file
View File

@ -0,0 +1,31 @@
.bdep/
# Local default options files.
#
.build2/local/
# Compiler/linker output.
#
*.d
*.t
*.i
*.i.*
*.ii
*.ii.*
*.o
*.obj
*.gcm
*.pcm
*.ifc
*.so
*.dylib
*.dll
*.a
*.lib
*.exp
*.pdb
*.ilk
*.exe
*.exe.dlls/
*.exe.manifest
*.pc

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# libasio
C++ library

4
build/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/config.build
/root/
/bootstrap/
build/

7
build/bootstrap.build Normal file
View File

@ -0,0 +1,7 @@
project = libasio
using version
using config
using test
using install
using dist

6
build/export.build Normal file
View File

@ -0,0 +1,6 @@
$out_root/
{
include src/
}
export $out_root/src/$import.target

20
build/root.build Normal file
View File

@ -0,0 +1,20 @@
# Uncomment to suppress warnings coming from external libraries.
#
#cxx.internal.scope = current
cxx.std = latest
using cxx
hxx{*}: extension = hxx
ixx{*}: extension = ixx
txx{*}: extension = txx
cxx{*}: extension = cxx
# Assume headers are importable unless stated otherwise.
#
hxx{*}: cxx.importable = true
# The test target for cross-testing (running tests under Wine, etc).
#
test.target = $cxx.target

5
buildfile Normal file
View File

@ -0,0 +1,5 @@
./: {*/ -build/} doc{README.md} manifest
# Don't install tests.
#
tests/: install = false

15
include/asio/asio.hxx Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <iosfwd>
#include <string>
#include <asio/export.hxx>
namespace asio
{
// Print a greeting for the specified name into the specified
// stream. Throw std::invalid_argument if the name is empty.
//
ASIO_SYMEXPORT void
say_hello (std::ostream&, const std::string& name);
}

14
include/asio/buildfile Normal file
View File

@ -0,0 +1,14 @@
pub_hdrs = {hxx ixx txx}{**}
./: $pub_hdrs
hxx{export}@./: cxx.importable = false
# Install into the asio/ subdirectory of, say, /usr/include/
# recreating subdirectories.
#
{hxx ixx txx}{*}:
{
install = include/asio/
install.subdirs = true
}

39
include/asio/export.hxx Normal file
View File

@ -0,0 +1,39 @@
#pragma once
// Normally we don't export class templates (but do complete specializations),
// inline functions, and classes with only inline member functions. Exporting
// classes that inherit from non-exported/imported bases (e.g., std::string)
// will end up badly. The only known workarounds are to not inherit or to not
// export. Also, MinGW GCC doesn't like seeing non-exported functions being
// used before their inline definition. The workaround is to reorder code. In
// the end it's all trial and error.
#if defined(ASIO_STATIC) // Using static.
# define ASIO_SYMEXPORT
#elif defined(ASIO_STATIC_BUILD) // Building static.
# define ASIO_SYMEXPORT
#elif defined(ASIO_SHARED) // Using shared.
# ifdef _WIN32
# define ASIO_SYMEXPORT __declspec(dllimport)
# else
# define ASIO_SYMEXPORT
# endif
#elif defined(ASIO_SHARED_BUILD) // Building shared.
# ifdef _WIN32
# define ASIO_SYMEXPORT __declspec(dllexport)
# else
# define ASIO_SYMEXPORT
# endif
#else
// If none of the above macros are defined, then we assume we are being used
// by some third-party build system that cannot/doesn't signal the library
// type. Note that this fallback works for both static and shared libraries
// provided the library only exports functions (in other words, no global
// exported data) and for the shared case the result will be sub-optimal
// compared to having dllimport. If, however, your library does export data,
// then you will probably want to replace the fallback with the (commented
// out) error since it won't work for the shared case.
//
# define ASIO_SYMEXPORT // Using static or shared.
//# error define ASIO_STATIC or ASIO_SHARED preprocessor macro to signal libasio library type being linked
#endif

13
manifest Normal file
View File

@ -0,0 +1,13 @@
: 1
name: libasio
version: 0.1.0-a.0.z
language: c++
summary: asio C++ library
license: other: proprietary ; Not free/open source.
description-file: README.md
url: https://example.org/libasio
email: francois@codesynthesis.com
#build-error-email: francois@codesynthesis.com
depends: * build2 >= 0.16.0
depends: * bpkg >= 0.16.0
#depends: libhello ^1.0.0

11
repositories.manifest Normal file
View File

@ -0,0 +1,11 @@
: 1
summary: libasio project repository
#:
#role: prerequisite
#location: https://pkg.cppget.org/1/stable
#trust: ...
#:
#role: prerequisite
#location: https://git.build2.org/hello/libhello.git

17
src/asio.cxx Normal file
View File

@ -0,0 +1,17 @@
#include <asio/asio.hxx>
#include <ostream>
#include <stdexcept>
using namespace std;
namespace asio
{
void say_hello (ostream& o, const string& n)
{
if (n.empty ())
throw invalid_argument ("empty name");
o << "Hello, " << n << '!' << endl;
}
}

54
src/buildfile Normal file
View File

@ -0,0 +1,54 @@
intf_libs = # Interface dependencies.
impl_libs = # Implementation dependencies.
#import xxxx_libs += libhello%lib{hello}
# Public headers.
#
pub = [dir_path] ../include/asio/
include $pub
pub_hdrs = $($pub/ pub_hdrs)
lib{asio}: $pub/{$pub_hdrs}
# Private headers and sources as well as dependencies.
#
lib{asio}: {hxx ixx txx cxx}{**} $impl_libs $intf_libs
# Build options.
#
out_pfx_inc = [dir_path] $out_root/include/
src_pfx_inc = [dir_path] $src_root/include/
out_pfx_src = [dir_path] $out_root/src/
src_pfx_src = [dir_path] $src_root/src/
cxx.poptions =+ "-I$out_pfx_src" "-I$src_pfx_src" \
"-I$out_pfx_inc" "-I$src_pfx_inc"
{hbmia obja}{*}: cxx.poptions += -DASIO_STATIC_BUILD
{hbmis objs}{*}: cxx.poptions += -DASIO_SHARED_BUILD
# Export options.
#
lib{asio}:
{
cxx.export.poptions = "-I$out_pfx_inc" "-I$src_pfx_inc"
cxx.export.libs = $intf_libs
}
liba{asio}: cxx.export.poptions += -DASIO_STATIC
libs{asio}: cxx.export.poptions += -DASIO_SHARED
# For pre-releases use the complete version to make sure they cannot be used
# in place of another pre-release or the final version. See the version module
# for details on the version.* variable values.
#
if $version.pre_release
lib{asio}: bin.lib.version = "-$version.project_id"
else
lib{asio}: bin.lib.version = "-$version.major.$version.minor"
# Don't install private headers.
#
{hxx ixx txx}{*}: install = false

8
tests/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Test executables.
#
driver
# Testscript output directories (can be symlinks).
#
test
test-*

3
tests/basics/buildfile Normal file
View File

@ -0,0 +1,3 @@
import libs = libasio%lib{asio}
exe{driver}: {hxx ixx txx cxx}{**} $libs testscript{**}

34
tests/basics/driver.cxx Normal file
View File

@ -0,0 +1,34 @@
#include <sstream>
#include <stdexcept>
#include <asio/asio.hxx>
#undef NDEBUG
#include <cassert>
int main ()
{
using namespace std;
using namespace asio;
// Basics.
//
{
ostringstream o;
say_hello (o, "World");
assert (o.str () == "Hello, World!\n");
}
// Empty name.
//
try
{
ostringstream o;
say_hello (o, "");
assert (false);
}
catch (const invalid_argument& e)
{
assert (e.what () == string ("empty name"));
}
}

4
tests/build/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/config.build
/root/
/bootstrap/
build/

View File

@ -0,0 +1,5 @@
project = # Unnamed tests subproject.
using config
using test
using dist

20
tests/build/root.build Normal file
View File

@ -0,0 +1,20 @@
cxx.std = latest
using cxx
hxx{*}: extension = hxx
ixx{*}: extension = ixx
txx{*}: extension = txx
cxx{*}: extension = cxx
# Assume headers are importable unless stated otherwise.
#
hxx{*}: cxx.importable = true
# Every exe{} in this subproject is by default a test.
#
exe{*}: test = true
# The test target for cross-testing (running tests under Wine, etc).
#
test.target = $cxx.target

1
tests/buildfile Normal file
View File

@ -0,0 +1 @@
./: {*/ -build/}