The main posixpp library and associated tests.
Révision | 21ff2fa93f6791b5d877e6de16e96939df474a62 (tree) |
---|---|
l'heure | 2021-05-03 02:03:13 |
Auteur | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Use library to create tiny, no-runtime support program.
@@ -10,9 +10,7 @@ | ||
10 | 10 | |
11 | 11 | find_package(fmt REQUIRED) |
12 | 12 | |
13 | -option(BUILD_SHARED_LIBS "Build posixpp as a shared library." ON) | |
14 | - | |
15 | -add_library(posixpp empty.cpp) | |
13 | +add_library(posixpp SHARED empty.cpp) | |
16 | 14 | set_property(TARGET posixpp PROPERTY CXX_EXTENSIONS OFF) |
17 | 15 | target_compile_features(posixpp PUBLIC cxx_std_20) |
18 | 16 | target_include_directories(posixpp PUBLIC |
@@ -20,6 +18,14 @@ | ||
20 | 18 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
21 | 19 | ) |
22 | 20 | |
21 | +add_library(posixpp_static STATIC empty.cpp) | |
22 | +set_property(TARGET posixpp_static PROPERTY CXX_EXTENSIONS OFF) | |
23 | +target_compile_features(posixpp_static PUBLIC cxx_std_20) | |
24 | +target_include_directories(posixpp_static PUBLIC | |
25 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/pubincludes> | |
26 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | |
27 | + ) | |
28 | + | |
23 | 29 | add_executable(all_tests |
24 | 30 | tests/simplefd.cpp tests/expected.cpp tests/flagset.cpp |
25 | 31 | tests/tempdir.h pubincludes/posixpp/fdflags.h |
@@ -37,6 +43,17 @@ | ||
37 | 43 | target_compile_features(junk PUBLIC cxx_std_20) |
38 | 44 | target_link_libraries(junk posixpp) |
39 | 45 | |
46 | +# This currently only works when optimization can eliminate all exception | |
47 | +# handling code. Exception handling requires C++ runtime support that's not | |
48 | +# yet implemented as part of this library. | |
49 | +add_executable(helloworld | |
50 | + examples/helloworld.cpp) | |
51 | +set_property(TARGET helloworld PROPERTY CXX_EXTENSIONS OFF) | |
52 | +target_compile_features(helloworld PUBLIC cxx_std_20) | |
53 | +target_link_libraries(helloworld posixpp_static) | |
54 | +# These are specific to g++. I think they will also work with CLang. | |
55 | +target_link_options(helloworld PUBLIC -nodefaultlibs -nostartfiles -e main) | |
56 | + | |
40 | 57 | include(CTest) |
41 | 58 | include(Catch) |
42 | 59 | catch_discover_tests(all_tests) |
@@ -0,0 +1,12 @@ | ||
1 | +#include <posixpp/fd.h> | |
2 | +#include <posixpp/expected.h> | |
3 | +#include <posixpp/basic.h> | |
4 | + | |
5 | +int main(int argc, char const * const *argv) | |
6 | +{ | |
7 | + const ::posixpp::fd fdout{1}; | |
8 | + static constexpr char msg[] = "Hello World!\n"; | |
9 | + // sizeof(msg) - 1 to skip trailing '\0' | |
10 | + auto result = fdout.write(msg, sizeof(msg) - 1); | |
11 | + ::posixpp::exit(result.has_error()); | |
12 | +} |