• R/O
  • SSH

posixpp: Commit

The main posixpp library and associated tests.


Commit MetaInfo

Révision21ff2fa93f6791b5d877e6de16e96939df474a62 (tree)
l'heure2021-05-03 02:03:13
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Use library to create tiny, no-runtime support program.

Change Summary

Modification

diff -r 8e9f35b58b20 -r 21ff2fa93f67 CMakeLists.txt
--- a/CMakeLists.txt Sun May 02 07:48:07 2021 -0700
+++ b/CMakeLists.txt Sun May 02 10:03:13 2021 -0700
@@ -10,9 +10,7 @@
1010
1111 find_package(fmt REQUIRED)
1212
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)
1614 set_property(TARGET posixpp PROPERTY CXX_EXTENSIONS OFF)
1715 target_compile_features(posixpp PUBLIC cxx_std_20)
1816 target_include_directories(posixpp PUBLIC
@@ -20,6 +18,14 @@
2018 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2119 )
2220
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+
2329 add_executable(all_tests
2430 tests/simplefd.cpp tests/expected.cpp tests/flagset.cpp
2531 tests/tempdir.h pubincludes/posixpp/fdflags.h
@@ -37,6 +43,17 @@
3743 target_compile_features(junk PUBLIC cxx_std_20)
3844 target_link_libraries(junk posixpp)
3945
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+
4057 include(CTest)
4158 include(Catch)
4259 catch_discover_tests(all_tests)
diff -r 8e9f35b58b20 -r 21ff2fa93f67 examples/helloworld.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/helloworld.cpp Sun May 02 10:03:13 2021 -0700
@@ -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+}
Afficher sur ancien navigateur de dépôt.