From d7cf2ceb611df450dd483310d0dab14214963ee6 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:03:59 -0400 Subject: [PATCH 01/38] Implement stumpless_get_prival_string --- CMakeLists.txt | 3 ++ include/stumpless.h | 1 + include/stumpless/prival.h | 59 +++++++++++++++++++++++++++++++ src/prival.c | 48 +++++++++++++++++++++++++ src/windows/stumpless.def | 3 ++ test/function/prival.cpp | 33 +++++++++++++++++ tools/check_headers/stumpless.yml | 1 + 7 files changed, 148 insertions(+) create mode 100644 include/stumpless/prival.h create mode 100644 src/prival.c create mode 100644 test/function/prival.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce0b7640..31c2339d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1025,6 +1025,9 @@ add_custom_target(check DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) +add_function_test(prival + SOURCES test/function/prival.cpp +) # examples add_example(basic diff --git a/include/stumpless.h b/include/stumpless.h index 11ec8fd03..cd8759b0d 100644 --- a/include/stumpless.h +++ b/include/stumpless.h @@ -101,6 +101,7 @@ #include #include #include +#include #ifdef STUMPLESS_CHAIN_TARGETS_SUPPORTED /** @example chain_example.c diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h new file mode 100644 index 000000000..722e7bdb8 --- /dev/null +++ b/include/stumpless/prival.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* + * Copyright 2018-2023 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** @file + * Function for converting prival from int to string + */ + +#ifndef __STUMPLESS_PRIVAL_H +# define __STUMPLESS_PRIVAL_H + +# include + +# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE +# include +# endif + +/** + * Gets the string representation of the given prival. + * + * This is a string literal that should not be modified or freed by the caller. + * + * **Thread Safety: MT-Safe** + * This function is thread safe. + * + * **Async Signal Safety: AS-Safe** + * This function is safe to call from signal handlers. + * + * **Async Cancel Safety: AC-Safe** + * This function is safe to call from threads that may be asynchronously + * cancelled. + * + * @param prival int to get the string from. + * + * @return The string representation of the given prival. + */ +STUMPLESS_PUBLIC_FUNCTION +const char * +stumpless_get_prival_string( int prival ); + +# ifdef __cplusplus +} /* extern "C" */ +# endif + +#endif /* __STUMPLESS_SEVERITY_H */ diff --git a/src/prival.c b/src/prival.c new file mode 100644 index 000000000..7a545687c --- /dev/null +++ b/src/prival.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2018-2022 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "private/prival.h" +#include "private/severity.h" +#include "private/facility.h" +#include "private/prival.h" +#include "private/strhelper.h" +#include "private/memory.h" +#include "private/validate.h" + +static char stumpless_get_prival_string( int prival ) { + VALIDATE_ARG_NOT_NULL( prival ); + + const char *severity = stumpless_get_severity_string( get_severity( prival ) ); + const char *facility = stumpless_get_facility_string( get_facility( prival ) ); + + size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting + const char *prival_string = alloc_mem( prival_string_length ); + + snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); + + return prival_string; +} + +static char *severity_enum_to_string[] = { + STUMPLESS_FOREACH_SEVERITY( GENERATE_STRING ) +}; diff --git a/src/windows/stumpless.def b/src/windows/stumpless.def index bbfebecdf..69eaa70f9 100644 --- a/src/windows/stumpless.def +++ b/src/windows/stumpless.def @@ -243,3 +243,6 @@ EXPORTS stumpless_close_chain_only @226 stumpless_get_chain_length @227 stumpless_new_chain @228 + +; added in prival branch + stumpless_get_prival_string @229 \ No newline at end of file diff --git a/test/function/prival.cpp b/test/function/prival.cpp new file mode 100644 index 000000000..8847a0bd6 --- /dev/null +++ b/test/function/prival.cpp @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2019-2021 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace { + + class PrivalTest : public::testing::Test { + }; + + TEST(GetPrivalString, ValidPrival) { + const char *result; + + result = stumpless_get_prival_string( 11 ); \ + EXPECT_STREQ( result, "3 | 8" ); + } +} \ No newline at end of file diff --git a/tools/check_headers/stumpless.yml b/tools/check_headers/stumpless.yml index 59e23449a..f6b374b45 100644 --- a/tools/check_headers/stumpless.yml +++ b/tools/check_headers/stumpless.yml @@ -638,3 +638,4 @@ "STUMPLESS_FOREACH_TARGET_TYPE" : "stumpless/target.h" "STUMPLESS_FOREACH_SEVERITY" : "stumpless/severity.h" "stumpless_prival_from_string" : "stumpless/priority.h" +"stumpless_get_prival_string" : "stumpless/prival.h" \ No newline at end of file From cb53656268d65ff055c86df6bacf00a61333e629 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:14:38 -0400 Subject: [PATCH 02/38] Updated CMakeLists to include prival --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31c2339d8..fd4aa1f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,6 +233,7 @@ set(STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/version.c ${PROJECT_SOURCE_DIR}/src/validate.c ${PROJECT_SOURCE_DIR}/src/priority.c + ${PROJECT_SOURCE_DIR}/src/prival.c ) @@ -698,6 +699,7 @@ install(FILES ${PROJECT_SOURCE_DIR}/include/stumpless/target.h ${PROJECT_SOURCE_DIR}/include/stumpless/version.h ${PROJECT_SOURCE_DIR}/include/stumpless/priority.h + ${PROJECT_SOURCE_DIR}/include/stumpless/prival.h DESTINATION "include/stumpless" ) From 2574d1473d1bffb816d14d3ff915b71efb40f185 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:23:59 -0400 Subject: [PATCH 03/38] Fixed header issues --- include/private/prival.h | 42 ++++++++++++++++++++++++++++++++++++++ include/stumpless/prival.h | 4 ++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 include/private/prival.h diff --git a/include/private/prival.h b/include/private/prival.h new file mode 100644 index 000000000..1a1113324 --- /dev/null +++ b/include/private/prival.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* + * Copyright 2018-2022 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __STUMPLESS_PRIVAL_STRING +# define __STUMPLESS_PRIVAL_STRING + +/** + * Function for converting prival from int to string + * + * **Thread Safety: MT-Safe** + * This function is thread safe. + * + * **Async Signal Safety: AS-Safe** + * This function is safe to call from signal handlers. + * + * **Async Cancel Safety: AC-Safe** + * This function is safe to call from threads that may be asynchronously + * cancelled. + * + * @param prival int to get the string from. + * + * @return The string representation of the given prival. + */ +int +get_prival_string( int prival ); + +#endif /* __STUMPLESS_PRIVAL_STRING diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 722e7bdb8..ded4c43e5 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -20,8 +20,8 @@ * Function for converting prival from int to string */ -#ifndef __STUMPLESS_PRIVAL_H -# define __STUMPLESS_PRIVAL_H +#ifndef __STUMPLESS_PRIVAL_STRING +# define __STUMPLESS_PRIVAL_STRING # include From d18372ab78401b2f92a01b07c3e28501f512bb61 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:30:15 -0400 Subject: [PATCH 04/38] Fixing compile issues --- include/private/prival.h | 2 +- src/prival.c | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/include/private/prival.h b/include/private/prival.h index 1a1113324..797d95856 100644 --- a/include/private/prival.h +++ b/include/private/prival.h @@ -39,4 +39,4 @@ int get_prival_string( int prival ); -#endif /* __STUMPLESS_PRIVAL_STRING +#endif /* __STUMPLESS_PRIVAL_STRING */ diff --git a/src/prival.c b/src/prival.c index 7a545687c..f038749fc 100644 --- a/src/prival.c +++ b/src/prival.c @@ -27,22 +27,15 @@ #include "private/prival.h" #include "private/strhelper.h" #include "private/memory.h" -#include "private/validate.h" -static char stumpless_get_prival_string( int prival ) { - VALIDATE_ARG_NOT_NULL( prival ); - +static char* stumpless_get_prival_string( int prival ) { const char *severity = stumpless_get_severity_string( get_severity( prival ) ); const char *facility = stumpless_get_facility_string( get_facility( prival ) ); size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting - const char *prival_string = alloc_mem( prival_string_length ); + char *prival_string = alloc_mem( prival_string_length ); snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); - return prival_string; + return *prival_string; } - -static char *severity_enum_to_string[] = { - STUMPLESS_FOREACH_SEVERITY( GENERATE_STRING ) -}; From 9a7446aaaf651c90a55b4794dd15e1df4254d3d5 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:33:23 -0400 Subject: [PATCH 05/38] Fix more compiling issues --- src/prival.c | 3 ++- src/prival.c.bak | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/prival.c.bak diff --git a/src/prival.c b/src/prival.c index f038749fc..a3bfe8bfc 100644 --- a/src/prival.c +++ b/src/prival.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,7 @@ #include "private/strhelper.h" #include "private/memory.h" -static char* stumpless_get_prival_string( int prival ) { +const char* stumpless_get_prival_string( int prival ) { const char *severity = stumpless_get_severity_string( get_severity( prival ) ); const char *facility = stumpless_get_facility_string( get_facility( prival ) ); diff --git a/src/prival.c.bak b/src/prival.c.bak new file mode 100644 index 000000000..437a060c6 --- /dev/null +++ b/src/prival.c.bak @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2018-2022 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "private/prival.h" +#include "private/severity.h" +#include "private/facility.h" +#include "private/prival.h" +#include "private/strhelper.h" +#include "private/memory.h" + +const char* stumpless_get_prival_string( int prival ) { + const char *severity = stumpless_get_severity_string( get_severity( prival ) ); + const char *facility = stumpless_get_facility_string( get_facility( prival ) ); + + size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting + char *prival_string = alloc_mem( prival_string_length ); + + snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); + + return *prival_string; +} From c8b8bb1133fdb919ad9df325e5ed13c8cd5f165c Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:35:40 -0400 Subject: [PATCH 06/38] More compile errors --- src/prival.c | 2 +- src/prival.c.bak | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index a3bfe8bfc..839ed775e 100644 --- a/src/prival.c +++ b/src/prival.c @@ -29,7 +29,7 @@ #include "private/strhelper.h" #include "private/memory.h" -const char* stumpless_get_prival_string( int prival ) { +char* stumpless_get_prival_string( int prival ) { const char *severity = stumpless_get_severity_string( get_severity( prival ) ); const char *facility = stumpless_get_facility_string( get_facility( prival ) ); diff --git a/src/prival.c.bak b/src/prival.c.bak index 437a060c6..a3bfe8bfc 100644 --- a/src/prival.c.bak +++ b/src/prival.c.bak @@ -18,6 +18,7 @@ #include #include +#include #include #include #include From 515023a8f600334c132ed476c1a8e2c824296608 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:36:32 -0400 Subject: [PATCH 07/38] Revert "More compile errors" This reverts commit c8b8bb1133fdb919ad9df325e5ed13c8cd5f165c. --- src/prival.c | 2 +- src/prival.c.bak | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/prival.c b/src/prival.c index 839ed775e..a3bfe8bfc 100644 --- a/src/prival.c +++ b/src/prival.c @@ -29,7 +29,7 @@ #include "private/strhelper.h" #include "private/memory.h" -char* stumpless_get_prival_string( int prival ) { +const char* stumpless_get_prival_string( int prival ) { const char *severity = stumpless_get_severity_string( get_severity( prival ) ); const char *facility = stumpless_get_facility_string( get_facility( prival ) ); diff --git a/src/prival.c.bak b/src/prival.c.bak index a3bfe8bfc..437a060c6 100644 --- a/src/prival.c.bak +++ b/src/prival.c.bak @@ -18,7 +18,6 @@ #include #include -#include #include #include #include From 0dd26c73f15cd6abffefb4b0dae5fb4ddca7c25a Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:39:06 -0400 Subject: [PATCH 08/38] More compile errors --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index a3bfe8bfc..9f8dd9382 100644 --- a/src/prival.c +++ b/src/prival.c @@ -38,5 +38,5 @@ const char* stumpless_get_prival_string( int prival ) { snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); - return *prival_string; + return prival_string; } From 7651ca53b0181dacb3a52044fd567eeb2442d157 Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 00:45:33 -0400 Subject: [PATCH 09/38] Corrected comment typo --- include/stumpless/prival.h | 2 +- src/prival.c.bak | 41 -------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 src/prival.c.bak diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index ded4c43e5..6040c5283 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -56,4 +56,4 @@ stumpless_get_prival_string( int prival ); } /* extern "C" */ # endif -#endif /* __STUMPLESS_SEVERITY_H */ +#endif /* __STUMPLESS_PRIVAL_STRING */ diff --git a/src/prival.c.bak b/src/prival.c.bak deleted file mode 100644 index 437a060c6..000000000 --- a/src/prival.c.bak +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -/* - * Copyright 2018-2022 Joel E. Anderson - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include "private/prival.h" -#include "private/severity.h" -#include "private/facility.h" -#include "private/prival.h" -#include "private/strhelper.h" -#include "private/memory.h" - -const char* stumpless_get_prival_string( int prival ) { - const char *severity = stumpless_get_severity_string( get_severity( prival ) ); - const char *facility = stumpless_get_facility_string( get_facility( prival ) ); - - size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting - char *prival_string = alloc_mem( prival_string_length ); - - snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); - - return *prival_string; -} From 037dbcf5791b0a3a1c22dc834078f938aa9ab83b Mon Sep 17 00:00:00 2001 From: uFarad Date: Thu, 4 Apr 2024 23:33:51 -0400 Subject: [PATCH 10/38] Removed hanging } --- include/stumpless/prival.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 6040c5283..d7c646aba 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -52,8 +52,4 @@ STUMPLESS_PUBLIC_FUNCTION const char * stumpless_get_prival_string( int prival ); -# ifdef __cplusplus -} /* extern "C" */ -# endif - #endif /* __STUMPLESS_PRIVAL_STRING */ From 6961429581831abea0f21a1e0d085ac034329840 Mon Sep 17 00:00:00 2001 From: uFarad Date: Fri, 5 Apr 2024 23:09:14 -0400 Subject: [PATCH 11/38] Fixed over-allocation --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 9f8dd9382..385d80096 100644 --- a/src/prival.c +++ b/src/prival.c @@ -36,7 +36,7 @@ const char* stumpless_get_prival_string( int prival ) { size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting char *prival_string = alloc_mem( prival_string_length ); - snprintf(prival_string, prival_string_length + 3, "%s | %s", severity, facility); + snprintf(prival_string, prival_string_length, "%s | %s", severity, facility); return prival_string; } From 5de7dca611efc65cbbbfad2e3f856346dcb55253 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 21:52:23 -0400 Subject: [PATCH 12/38] Fixed ordering so that test function is built --- CMakeLists.txt | 8 +- CMakeLists.txt.bak | 1214 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1218 insertions(+), 4 deletions(-) create mode 100644 CMakeLists.txt.bak diff --git a/CMakeLists.txt b/CMakeLists.txt index fd4aa1f58..f6dc3f633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1018,6 +1018,10 @@ add_function_test(priority SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp ) +add_function_test(prival + SOURCES test/function/prival.cpp +) + add_custom_target(build-test DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) @@ -1027,10 +1031,6 @@ add_custom_target(check DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) -add_function_test(prival - SOURCES test/function/prival.cpp -) - # examples add_example(basic ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c diff --git a/CMakeLists.txt.bak b/CMakeLists.txt.bak new file mode 100644 index 000000000..fd4aa1f58 --- /dev/null +++ b/CMakeLists.txt.bak @@ -0,0 +1,1214 @@ +cmake_minimum_required(VERSION 3.2.3) + +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + +project(stumpless VERSION 2.2.0) +set(CMAKE_PROJECT_HOMEPAGE_URL "https://goatshriek.github.io/stumpless/") + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) + +string(CONCAT enable_cpp_help_string + "Build the C++ language binding library. The library will be added to the " + "'all' target and will be installed via the 'install' target, alongside the " + "C library. Other targets (such as 'docs' and 'check') will have a '-cpp' " + "version that takes the same action for the C++ library. For example, build " + "the 'check-cpp' target to build and run the test suite for the C++ library." +) +option(ENABLE_CPP ${enable_cpp_help_string} OFF) +option(BUILD_PYTHON "include the python libary" OFF) + +option(ENABLE_THREAD_SAFETY "support thread-safe functionality" ON) + +option(ENABLE_CHAIN_TARGETS "support chain targets" ON) +option(ENABLE_JOURNALD_TARGETS "support systemd journald service targets" ON) +option(ENABLE_NETWORK_TARGETS "support network targets" ON) +option(ENABLE_SOCKET_TARGETS "support unix domain socket targets" ON) +option(ENABLE_SQLITE3_TARGETS "support sqlite3 targets" ON) +option(ENABLE_WINDOWS_EVENT_LOG_TARGETS "support windows event log targets" ON) + +option(INSTALL_EXAMPLES "install examples" ON) +option(INSTALL_MANPAGES "install generated manpages" ON) + +option(COVERAGE "Include coverage information" OFF) +option(FUZZ "Support fuzzing with libFuzzer" OFF) + +string(CONCAT enable_deprecation_warnings_help_string + "Print warnings to the standard output when deprecated functionality is used." +) +option(ENABLE_DEPRECATION_WARNINGS ${enable_deprecation_warnings_help_string} ON) + + +# default settings +set(CHAIN_TARGET_ARRAY_LENGTH 4 + CACHE STRING "the chain target static array size" +) + +string(CONCAT default_facility_help_string + "The facility code to use for messages where one is not explicitly provided." +) +set(DEFAULT_FACILITY "STUMPLESS_FACILITY_USER" + CACHE STRING ${default_facility_help_string} +) + +string(CONCAT default_file_help_string + "The name of the file opened if the default target is to a file." +) +set(DEFAULT_FILE "stumpless-default.log" + CACHE STRING "${default_file_help_string}" +) + +string(CONCAT default_severity_help_string + "The severity code to use for messages where one is not explicitly provided." +) +set(DEFAULT_SEVERITY "STUMPLESS_SEVERITY_INFO" + CACHE STRING ${default_severity_help_string} +) + +set(FALLBACK_PAGESIZE 4096 + CACHE STRING "the memory page size to use if it cannot be detected at runtime" +) + +string(CONCAT sqlite3_src_path_help_string + "The path to a SQLite3 source file, referred to as an 'amalgamation' in " + "SQLite documentation. If this variable is set, it is used to link SQLite3 " + "statically with Stumpless, instead of the default dynamic linking." +) +set(SQLITE3_SRC_PATH "" + CACHE FILEPATH ${sqlite3_src_path_help_string} +) + +string(CONCAT sqlite3_include_path_help_string + "The path to the sqlite3.h header matching the source file provided in " + "SQLITE3_SRC_PATH. If the header is already in the include directores, this " + "does not need to be specified." +) +set(SQLITE3_INCLUDE_PATH "" + CACHE FILEPATH ${sqlite3_include_path_help_string} +) + +set(SQLITE3_DEFAULT_TABLE_NAME "logs" + CACHE STRING "the name of the table used by default for SQLite3 targets" +) + +set(SQLITE3_RETRY_MAX 3 + CACHE STRING "the maximum number of retries on SQLite3 operations" +) + +string(CONCAT benchmark_path_help_string + "A directory with a build of google benchmark that can be used instead of " + "downloading and building the library during build. " + "In order for this to be used the directory must include ALL of the " + "following at configuration time: the benchmark and benchmark_main " + "libraries, and the benchmark/benchmark.h header. " + "If the necessary files are not found, the benchmark library will be " + "downloaded and built when it is needed, and the export-benchmark target " + "can be used to populate the provided directory for future builds." +) +set(BENCHMARK_PATH ${PROJECT_BINARY_DIR} + CACHE PATH ${benchmark_path_help_string} +) + +string(CONCAT gtest_path_help_string + "A directory with a build of google test that can be used instead of " + "downloading and building the library during build. " + "In order for this to be used the directory must include ALL of the " + "following at configuration time: the gtest, gtest_main, and gmock " + "libraries, the gtest/gtest.h header, and the gmock/gmock.h header. " + "If the necessary files are not found, the gtest library will be " + "downloaded and built when it is needed, and the export-gtest target " + "can be used to populate the provided directory for future builds." +) +set(GTEST_PATH ${PROJECT_BINARY_DIR} + CACHE PATH ${gtest_path_help_string} +) + +string(CONCAT locale_help_string + "The locale used for strings passed by the library, for example error " + "messages. If this is not set it will use the LANG environment variable " + "of the build system." +) +set(LOCALE $ENV{LANG} + CACHE STRING ${locale_help_string} +) + + +# single file build paths +set(SINGLE_SOURCE_FILE "${PROJECT_BINARY_DIR}/stumpless.c") +set(SINGLE_INCLUDE_DIR "${PROJECT_BINARY_DIR}/include/single_file") +set(SINGLE_HEADER_FILE "${SINGLE_INCLUDE_DIR}/stumpless.h") + + +# load modules +include(CheckIncludeFiles) +include(CheckSymbolExists) +include(ExternalProject) +include(FindDoxygen QUIET) +include(GNUInstallDirs) + + +# load utilities +include(tools/cmake/google_libs.cmake) +include(tools/cmake/add_found_library.cmake) +# the above two need to be before benchmark and gtest + +include(tools/cmake/benchmark.cmake) +include(tools/cmake/example.cmake) +include(tools/cmake/gtest.cmake) +include(tools/cmake/l10n.cmake) +include(tools/cmake/swig.cmake) +include(tools/cmake/test.cmake) + + +# building configuration +if(EXISTS ${SQLITE3_INCLUDE_PATH}) + file(COPY + "${SQLITE3_INCLUDE_PATH}" + DESTINATION "${PROJECT_BINARY_DIR}/include" + ) +endif() + +check_include_files(pthread.h HAVE_PTHREAD_H) +check_include_files(stdatomic.h HAVE_STDATOMIC_H) +check_include_files("sqlite3.h" HAVE_SQLITE3_H) +check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) +check_include_files(syslog.h STUMPLESS_SYSLOG_H_COMPATIBLE) +check_include_files(systemd/sd-journal.h HAVE_SYSTEMD_SD_JOURNAL_H) +check_include_files(unistd.h HAVE_UNISTD_H) +check_include_files(windows.h HAVE_WINDOWS_H) +check_include_files(winsock2.h HAVE_WINSOCK2_H) + +check_symbol_exists(fopen_s stdio.h HAVE_FOPEN_S) +check_symbol_exists(getaddrinfo netdb.h HAVE_GETADDRINFO) +check_symbol_exists(gethostname unistd.h HAVE_UNISTD_GETHOSTNAME) +check_symbol_exists(gethostbyname netdb.h HAVE_GETHOSTBYNAME) +check_symbol_exists(gethostbyname2 netdb.h HAVE_GETHOSTBYNAME2) +check_symbol_exists(getpagesize unistd.h HAVE_UNISTD_GETPAGESIZE) +check_symbol_exists(gmtime time.h HAVE_GMTIME) +check_symbol_exists(gmtime_r time.h HAVE_GMTIME_R) +check_symbol_exists(_SC_PAGESIZE unistd.h HAVE_UNISTD_SC_PAGESIZE) +check_symbol_exists(sprintf_s stdio.h HAVE_SPRINTF_S) +check_symbol_exists(sysconf unistd.h HAVE_UNISTD_SYSCONF) +check_symbol_exists(vsnprintf_s stdio.h HAVE_VSNPRINTF_S) +check_symbol_exists(wcsrtombs_s wchar.h HAVE_WCSRTOMBS_S) +check_symbol_exists(wcstombs_s windows.h HAVE_WCSTOMBS_S) + +find_program(HAVE_WRAPTURE NAMES wrapture) + +if(ENABLE_DEPRECATION_WARNINGS) + set(STUMPLESS_DEPRECATION_WARNINGS_ENABLED TRUE) +else() + set(STUMPLESS_DEPRECATION_WARNINGS_ENABLED OFF) +endif() + +if(EXISTS "/var/run/syslog") + set(STUMPLESS_DEFAULT_SOCKET "/var/run/syslog") +else() + set(STUMPLESS_DEFAULT_SOCKET "/dev/log") +endif() + + +# standard source files +set(STUMPLESS_SOURCES + ${PROJECT_SOURCE_DIR}/src/cache.c + ${PROJECT_SOURCE_DIR}/src/element.c + ${PROJECT_SOURCE_DIR}/src/entry.c + ${PROJECT_SOURCE_DIR}/src/error.c + ${PROJECT_SOURCE_DIR}/src/facility.c + ${PROJECT_SOURCE_DIR}/src/filter.c + ${PROJECT_SOURCE_DIR}/src/formatter.c + ${PROJECT_SOURCE_DIR}/src/inthelper.c + ${PROJECT_SOURCE_DIR}/src/log.c + ${PROJECT_SOURCE_DIR}/src/memory.c + ${PROJECT_SOURCE_DIR}/src/param.c + ${PROJECT_SOURCE_DIR}/src/severity.c + ${PROJECT_SOURCE_DIR}/src/strbuilder.c + ${PROJECT_SOURCE_DIR}/src/strhelper.c + ${PROJECT_SOURCE_DIR}/src/target.c + ${PROJECT_SOURCE_DIR}/src/target/buffer.c + ${PROJECT_SOURCE_DIR}/src/target/file.c + ${PROJECT_SOURCE_DIR}/src/target/function.c + ${PROJECT_SOURCE_DIR}/src/target/stream.c + ${PROJECT_SOURCE_DIR}/src/version.c + ${PROJECT_SOURCE_DIR}/src/validate.c + ${PROJECT_SOURCE_DIR}/src/priority.c + ${PROJECT_SOURCE_DIR}/src/prival.c +) + + +# wrapture support +set(WRAPTURE_SPECS + # template files must be first + ${PROJECT_SOURCE_DIR}/tools/wrapture/error_templates.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/target_templates.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/buffer_target.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/element.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/entry.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/error.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/facility.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/file_target.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/function_target.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/memory.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/param.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/severity.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/stream_target.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/target.yml + ${PROJECT_SOURCE_DIR}/tools/wrapture/version.yml +) + + +# documentation and doxygen steup +set(DOXYGEN_MANPAGES + ${PROJECT_BINARY_DIR}/docs/man/man3/stumpless.h.3 + ${PROJECT_BINARY_DIR}/docs/man/man3/config.h.3 +) + +set(PROJECT_DOCS_DIR ${PROJECT_BINARY_DIR}/docs) +if(DOXYGEN_FOUND) + set(INCLUDE_MANPAGES_IN_INSTALL ${INSTALL_MANPAGES}) +else() + if(INSTALL_MANPAGES) + message("doxygen is required to generate and install manpages") + endif() + + set(INCLUDE_MANPAGES_IN_INSTALL FALSE) +endif() + +if(${INCLUDE_MANPAGES_IN_INSTALL}) + # we need to do this before any other install commands that depend on the + # manpages generated by doxygen, so that they are generated before use + install(CODE + "execute_process(COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target docs)" + ) +endif() + + +# configuration-specific source files +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(SUPPORT_ABSTRACT_SOCKET_NAMES TRUE) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_supported.c) +else() + set(SUPPORT_ABSTRACT_SOCKET_NAMES FALSE) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_unsupported.c) +endif() + +if(HAVE_FOPEN_S) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_fopen_s.c) +endif(HAVE_FOPEN_S) + +if(HAVE_PTHREAD_H) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_pthread.c) +endif() + +if(HAVE_STDATOMIC_H) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_stdatomic.c) +endif() + +if(HAVE_UNISTD_H) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd.c) +endif(HAVE_UNISTD_H) + +if(HAVE_VSNPRINTF_S) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_vsnprintf_s.c) +else() + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_vsnprintf_s.c) +endif(HAVE_VSNPRINTF_S) + +if(NOT HAVE_WCSRTOMBS_S) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_wcsrtombs_s.c) +endif() + +if(HAVE_WINDOWS_H) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_windows.c) +endif(HAVE_WINDOWS_H) + +if(WIN32) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/windows/stumpless.def) +endif(WIN32) + +if(HAVE_WINDOWS_H AND HAVE_SPRINTF_S) + set(SUPPORT_WINDOWS_GET_NOW TRUE) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/windows_get_now_supported.c) +endif() + +if(HAVE_GMTIME_R) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_gmtime_r.c) +elseif(NOT SUPPORT_WINDOWS_GET_NOW AND HAVE_GMTIME) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_gmtime.c) +else() + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_gmtime.c) +endif() + +if(HAVE_UNISTD_GETHOSTNAME) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd_gethostname.c) +elseif(NOT HAVE_WINSOCK2_H) + # need the fallback gethostname definition in this case + set(NEED_FALLBACK TRUE) +endif() + +if(HAVE_UNISTD_SYSCONF AND HAVE_UNISTD_SC_PAGESIZE) + set(SUPPORT_UNISTD_SYSCONF_GETPAGESIZE TRUE) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/unistd_sysconf_getpagesize_supported.c) +elseif(HAVE_UNISTD_GETPAGESIZE) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd_getpagesize.c) +elseif(NOT HAVE_WINDOWS_H) + # need the fallback getpagesize definition in this case + set(NEED_FALLBACK TRUE) +endif() + +if(NOT HAVE_UNISTD_H AND NOT HAVE_WINDOWS_H) + # need the fallback getpid definition in this case + set(NEED_FALLBACK TRUE) +endif() + +if(NEED_FALLBACK) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/fallback.c) +endif() + + +# thread safety support check +if(NOT ENABLE_THREAD_SAFETY) + set(STUMPLESS_THREAD_SAFETY_SUPPORTED FALSE) +elseif(NOT HAVE_WINDOWS_H AND (NOT HAVE_PTHREAD_H OR NOT HAVE_STDATOMIC_H)) + message("thread safety is not supported without either windows.h or both pthread.h and stdatomic.h") + set(STUMPLESS_THREAD_SAFETY_SUPPORTED FALSE) +else() + set(STUMPLESS_THREAD_SAFETY_SUPPORTED TRUE) +endif() + + +# chain target support +if(NOT ENABLE_CHAIN_TARGETS) + set(STUMPLESS_CHAIN_TARGETS_SUPPORTED FALSE) +else() + set(STUMPLESS_CHAIN_TARGETS_SUPPORTED TRUE) +endif() + +if(STUMPLESS_CHAIN_TARGETS_SUPPORTED) + include(tools/cmake/chain.cmake) +else() + if(WIN32) + list(APPEND STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/config/chain_unsupported.c") + endif(WIN32) +endif() + + +# journald target support +if(NOT ENABLE_JOURNALD_TARGETS) + set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) +elseif(ENABLE_JOURNALD_TARGETS AND NOT HAVE_SYSTEMD_SD_JOURNAL_H) + message("journald targets are not supported without systemd/sd-journal.h") + set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) +else() + find_library(LIBSYSTEMD_FOUND systemd) + if(LIBSYSTEMD_FOUND) + set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED TRUE) + else() + message("journald targets are not supported without libsystemd") + set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) + endif() +endif() + +if(STUMPLESS_JOURNALD_TARGETS_SUPPORTED) + include(tools/cmake/journald.cmake) +else() + add_function_test(journald_unsupported + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/config/journald_unsupported.cpp + $ + ) +endif() + + +# network target support +if(NOT ENABLE_NETWORK_TARGETS) + set(STUMPLESS_NETWORK_TARGETS_SUPPORTED FALSE) +elseif(NOT HAVE_WINSOCK2_H AND NOT HAVE_SYS_SOCKET_H) + message("network targets are not supported without either winsock2.h or sys/socket.h") + set(STUMPLESS_NETWORK_TARGETS_SUPPORTED FALSE) +else() + set(STUMPLESS_NETWORK_TARGETS_SUPPORTED TRUE) +endif() + +if(STUMPLESS_NETWORK_TARGETS_SUPPORTED) + include(tools/cmake/network.cmake) +else() + if(WIN32) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/network_unsupported.c) + endif(WIN32) + + add_function_test(network_unsupported + SOURCES ${PROJECT_SOURCE_DIR}/test/function/config/network_unsupported.cpp + ) +endif() + + +# socket target support +if(NOT ENABLE_SOCKET_TARGETS) + set(STUMPLESS_SOCKET_TARGETS_SUPPORTED FALSE) +elseif(NOT HAVE_SYS_SOCKET_H) + message("socket targets are not supported without sys/socket.h") + set(STUMPLESS_SOCKET_TARGETS_SUPPORTED FALSE) +else() + set(STUMPLESS_SOCKET_TARGETS_SUPPORTED TRUE) +endif() + +if(STUMPLESS_SOCKET_TARGETS_SUPPORTED) + include(tools/cmake/socket.cmake) +else() + add_function_test(socket_unsupported + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/config/socket_unsupported.cpp + $ + ) +endif() + + +# sqlite3 target support +if(NOT ENABLE_SQLITE3_TARGETS) + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) +elseif(SQLITE3_SRC_PATH) + if(NOT EXISTS "${SQLITE3_SRC_PATH}") + message("the specified sqlite3 source file does not exist") + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) + else() + list(APPEND STUMPLESS_SOURCES "${SQLITE3_SRC_PATH}") + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE) + endif() +elseif(NOT HAVE_SQLITE3_H) + message("sqlite3 targets are not supported without sqlite3.h") + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) +else() + find_library(LIBSQLITE3_FOUND sqlite3) + if(LIBSQLITE3_FOUND) + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE) + else() + message("sqlite3 targets are not supported without libsqlite3") + set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) + endif() +endif() + +if(STUMPLESS_SQLITE3_TARGETS_SUPPORTED) + include(tools/cmake/sqlite3.cmake) +else() + list(APPEND + STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/config/sqlite3_unsupported.c" + ) + + add_function_test(sqlite3_unsupported + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/config/sqlite3_unsupported.cpp + $ + ) +endif() + + +# windows event log target support +if(NOT ENABLE_WINDOWS_EVENT_LOG_TARGETS) + set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED FALSE) +elseif(ENABLE_WINDOWS_EVENT_LOG_TARGETS AND NOT HAVE_WINDOWS_H) + message("windows event log targets are not supported without windows.h") + set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED FALSE) +else() + set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED TRUE) +endif() + +if(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED) + include(tools/cmake/wel.cmake) +else() + list(INSERT WRAPTURE_SPECS 0 ${PROJECT_SOURCE_DIR}/tools/wrapture/no_wel_templates.yml) + + add_function_test(wel_unsupported + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/config/wel_unsupported.cpp + $ + ) +endif() + + +# thread safety support +if(NOT STUMPLESS_THREAD_SAFETY_SUPPORTED) + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/thread_safety_unsupported.c) +else() + list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/thread_safety_supported.c) + + # thread safety tests + add_thread_safety_test(buffer + SOURCES + test/thread_safety/target/buffer.cpp + $ + $ + ) + + add_thread_safety_test(element + SOURCES + test/thread_safety/element.cpp + ) + + add_thread_safety_test(entry + SOURCES + test/thread_safety/entry.cpp + $ + ) + + add_thread_safety_test(file + SOURCES + test/thread_safety/target/file.cpp + $ + $ + ) + + add_thread_safety_test(function + SOURCES + ${PROJECT_SOURCE_DIR}/test/thread_safety/target/function.cpp + $ + ) + + add_thread_safety_test(param + SOURCES + test/thread_safety/param.cpp + ) + + add_thread_safety_test(stream + SOURCES + test/thread_safety/target/stream.cpp + $ + $ + ) + + add_thread_safety_test(target + SOURCES + test/thread_safety/target.cpp + ) + + add_custom_target(check-thread-safety + DEPENDS ${STUMPLESS_THREAD_SAFETY_TEST_RUNNERS} + ) +endif() + + +# library definition +add_library(stumpless ${STUMPLESS_SOURCES}) +set_target_properties(stumpless PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(stumpless PROPERTIES PUBLIC_HEADER include/stumpless.h) + +target_link_libraries(stumpless PRIVATE ${STUMPLESS_LINK_LIBRARIES}) + +if(MINGW) + target_compile_options(stumpless PRIVATE -D__USE_MINGW_ANSI_STDIO) + set_target_properties(stumpless PROPERTIES PREFIX "") +endif() + +if(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED) + add_dependencies(stumpless default_events) +endif() + +if(HAVE_STDATOMIC_H) + find_library(LIBATOMIC_FOUND atomic) + if(LIBATOMIC_FOUND) + target_link_libraries(stumpless PRIVATE atomic) + endif() +endif() + +if(HAVE_WINSOCK2_H) + target_link_libraries(stumpless PRIVATE Ws2_32) +endif(HAVE_WINSOCK2_H) + +if(COVERAGE) + target_compile_options(stumpless PRIVATE --coverage) + target_link_libraries(stumpless PRIVATE --coverage) +endif(COVERAGE) + +if(FUZZ) + target_compile_options(stumpless PRIVATE "-fsanitize=fuzzer,address") + target_link_libraries(stumpless PRIVATE "-fsanitize=fuzzer,address") +endif(FUZZ) + +target_include_directories(stumpless + PRIVATE + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR}/include +) + + +# optimization options +if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + set(PUBLIC_FUNCTION_DECORATION "__attribute__ ((visibility (\"default\")))") + set(UNLIKELY_FUNCTION "__builtin_expect( ( EXPRESSION ), 0 )") + set(COLD_FUNCTION "__attribute__ ((cold))") +else() + set(PUBLIC_FUNCTION_DECORATION "") + set(UNLIKELY_FUNCTION "( EXPRESSION )") + set(COLD_FUNCTION "") +endif() + +if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + target_compile_options(stumpless + PRIVATE "-fvisibility=hidden") + + target_link_libraries(stumpless + PRIVATE "-s") + + if(NOT CYGWIN) + target_compile_options(stumpless + PRIVATE "-flto") + + target_link_libraries(stumpless + PRIVATE "-flto") + endif() + endif() +endif() + + + +# generating configuration files +set(FUZZ_CORPORA_DIR ${PROJECT_SOURCE_DIR}/test/corpora) +configure_file(${PROJECT_SOURCE_DIR}/include/stumpless/config.h.in ${PROJECT_BINARY_DIR}/include/stumpless/config.h) +configure_file(${PROJECT_SOURCE_DIR}/include/private/config.h.in ${PROJECT_BINARY_DIR}/include/private/config.h) +configure_file(${PROJECT_SOURCE_DIR}/include/test/config.hpp.in ${PROJECT_BINARY_DIR}/include/test/config.hpp) +configure_file(${PROJECT_SOURCE_DIR}/tools/portage/stumpless.ebuild.in + ${PROJECT_BINARY_DIR}/tools/portage/stumpless-${PROJECT_VERSION}.ebuild + @ONLY +) + + +# installation of the library +install(TARGETS stumpless + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +install(FILES + ${PROJECT_BINARY_DIR}/include/stumpless/config.h + ${PROJECT_SOURCE_DIR}/include/stumpless/element.h + ${PROJECT_SOURCE_DIR}/include/stumpless/entry.h + ${PROJECT_SOURCE_DIR}/include/stumpless/error.h + ${PROJECT_SOURCE_DIR}/include/stumpless/facility.h + ${PROJECT_SOURCE_DIR}/include/stumpless/filter.h + ${PROJECT_SOURCE_DIR}/include/stumpless/generator.h + ${PROJECT_SOURCE_DIR}/include/stumpless/id.h + ${PROJECT_SOURCE_DIR}/include/stumpless/log.h + ${PROJECT_SOURCE_DIR}/include/stumpless/memory.h + ${PROJECT_SOURCE_DIR}/include/stumpless/option.h + ${PROJECT_SOURCE_DIR}/include/stumpless/param.h + ${PROJECT_SOURCE_DIR}/include/stumpless/severity.h + ${PROJECT_SOURCE_DIR}/include/stumpless/target.h + ${PROJECT_SOURCE_DIR}/include/stumpless/version.h + ${PROJECT_SOURCE_DIR}/include/stumpless/priority.h + ${PROJECT_SOURCE_DIR}/include/stumpless/prival.h + DESTINATION "include/stumpless" +) + +install(FILES + ${PROJECT_SOURCE_DIR}/include/stumpless/level/alert.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/crit.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/debug.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/emerg.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/err.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/info.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/mask.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/notice.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/trace.h + ${PROJECT_SOURCE_DIR}/include/stumpless/level/warning.h + DESTINATION "include/stumpless/level" +) + +install(FILES + ${PROJECT_SOURCE_DIR}/include/stumpless/target/buffer.h + ${PROJECT_SOURCE_DIR}/include/stumpless/target/file.h + ${PROJECT_SOURCE_DIR}/include/stumpless/target/function.h + ${PROJECT_SOURCE_DIR}/include/stumpless/target/sqlite3.h + ${PROJECT_SOURCE_DIR}/include/stumpless/target/stream.h + DESTINATION "include/stumpless/target" +) + +include(tools/cmake/cpack.cmake) + +include(FindPkgConfig QUIET) +if(PKG_CONFIG_FOUND) + configure_file("${PROJECT_SOURCE_DIR}/tools/pkg-config/stumpless.pc.in" "${PROJECT_BINARY_DIR}/tools/pkg-config/stumpless.pc" @ONLY) + install(FILES "${PROJECT_BINARY_DIR}/tools/pkg-config/stumpless.pc" + DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") +endif() + + +# installation of examples if enabled +if(INSTALL_EXAMPLES) + install(DIRECTORY + ${PROJECT_SOURCE_DIR}/docs/examples + DESTINATION ${CMAKE_INSTALL_DOCDIR} + ) +endif() + + +# installation of manpages if enabled and supported +if(INCLUDE_MANPAGES_IN_INSTALL) + include(tools/cmake/install_manpages.cmake) +endif() + + +# functionality tests +add_function_test(buffer + SOURCES + test/function/target/buffer.cpp + $ + $ +) + +add_function_test(buffer_leak + SOURCES + test/function/leak/buffer.cpp + $ +) + +add_function_test(current_target + SOURCES test/function/startup/current_target.cpp +) + +add_function_test(element + SOURCES test/function/element.cpp +) + +add_function_test(element_leak + SOURCES test/function/leak/element.cpp +) + +add_function_test(entry + SOURCES + test/function/entry.cpp + $ +) + +add_function_test(entry_leak + SOURCES + test/function/leak/entry.cpp + $ +) + +add_function_test(entry_memory_failure + SOURCES test/function/startup/entry_memory_failure.cpp +) + +add_function_test(error + SOURCES + test/function/error.cpp + $ +) + +add_function_test(error_leak + SOURCES test/function/leak/error.cpp +) + +add_function_test(error_memory_failure + SOURCES test/function/startup/error_memory_failure.cpp +) + +add_function_test(facility + SOURCES test/function/facility.cpp +) + +add_function_test(file + SOURCES + test/function/target/file.cpp + $ +) + +add_function_test(filter + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/filter.cpp + $ +) + +add_function_test(function + SOURCES ${PROJECT_SOURCE_DIR}/test/function/target/function.cpp +) + +add_function_test(get_error_stream + SOURCES ${PROJECT_SOURCE_DIR}/test/function/startup/get_error_stream.cpp +) + +add_function_test(level_all_disabled + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/all_disabled.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_ALL_LEVELS +) + +add_function_test(level_all_enabled + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/all_enabled.cpp + $ +) + +add_function_test(level_disabled_downto_alert + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_emerg.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_ALERT +) + +add_function_test(level_disabled_downto_emerg + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/all_disabled.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_EMERG +) + +add_function_test(level_disabled_downto_err + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_crit.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_ERR +) + +add_function_test(level_disabled_downto_crit + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_alert.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_CRIT +) + +add_function_test(level_disabled_downto_debug + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_info.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_DEBUG +) + +add_function_test(level_disabled_downto_info + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_notice.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_INFO +) + +add_function_test(level_disabled_downto_notice + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_warning.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_NOTICE +) + +add_function_test(level_disabled_downto_trace + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_debug.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_TRACE +) + +add_function_test(level_disabled_downto_warning + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_err.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_WARNING +) + +add_function_test(level_enable_upto_alert + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_alert.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_ALERT +) + +add_function_test(level_enable_upto_crit + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_crit.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_CRIT +) + +add_function_test(level_enable_upto_debug + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_debug.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_DEBUG +) + +add_function_test(level_enable_upto_emerg + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_emerg.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_EMERG +) + +add_function_test(level_enable_upto_err + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_err.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_ERR +) + +add_function_test(level_enable_upto_info + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_info.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_INFO +) + +add_function_test(level_enable_upto_notice + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_notice.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_NOTICE +) + +add_function_test(level_enable_upto_trace + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/all_enabled.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_TRACE +) + +add_function_test(level_enable_upto_warning + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_warning.cpp + $ + COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_WARNING +) + +add_function_test(log + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/log.cpp + $ +) + +add_function_test(memory + SOURCES ${PROJECT_SOURCE_DIR}/test/function/memory.cpp +) + +add_function_test(param + SOURCES ${PROJECT_SOURCE_DIR}/test/function/param.cpp +) + +add_function_test(perror + SOURCES ${PROJECT_SOURCE_DIR}/test/function/startup/perror.cpp +) + +add_function_test(severity + SOURCES ${PROJECT_SOURCE_DIR}/test/function/severity.cpp +) + +add_function_test(stream + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/target/stream.cpp + $ + $ +) + +add_function_test(target + SOURCES + ${PROJECT_SOURCE_DIR}/test/function/target.cpp + $ + $ +) + +add_function_test(target_leak + SOURCES ${PROJECT_SOURCE_DIR}/test/function/leak/target.cpp +) + +add_function_test(version + SOURCES ${PROJECT_SOURCE_DIR}/test/function/version.cpp +) + +add_function_test(priority + SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp +) + +add_custom_target(build-test + DEPENDS ${STUMPLESS_FUNCTION_TESTS} +) + +add_custom_target(check + COMMAND ${CMAKE_CTEST_COMMAND} -C ${CMAKE_BUILD_TYPE} + DEPENDS ${STUMPLESS_FUNCTION_TESTS} +) + +add_function_test(prival + SOURCES test/function/prival.cpp +) + +# examples +add_example(basic + ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c +) + +add_example(entry + ${PROJECT_SOURCE_DIR}/docs/examples/entry/entry_example.c +) + +add_example(file + ${PROJECT_SOURCE_DIR}/docs/examples/file/file_example.c +) + +add_example(filter + ${PROJECT_SOURCE_DIR}/docs/examples/filter/filter_example.c +) + +add_example(function + ${PROJECT_SOURCE_DIR}/docs/examples/function/function_example.c +) + +add_example(severity_level + ${PROJECT_SOURCE_DIR}/docs/examples/severity_level/severity_level_example.c +) + +add_example(stream + ${PROJECT_SOURCE_DIR}/docs/examples/stream/stream_example.c +) + +add_custom_target(examples + DEPENDS ${STUMPLESS_EXAMPLE_RUNNERS} +) + + +# performance tests +add_performance_test(element +SOURCES test/performance/element.cpp +) + +add_performance_test(priority +SOURCES test/performance/priority.cpp +) + +add_performance_test(entry + SOURCES + ${PROJECT_SOURCE_DIR}/test/performance/entry.cpp + $ +) + +add_performance_test(function + SOURCES + ${PROJECT_SOURCE_DIR}/test/performance/target/function.cpp + $ +) + +add_performance_test(log + SOURCES test/performance/log.cpp +) + +add_performance_test(param + SOURCES + ${PROJECT_SOURCE_DIR}/test/performance/param.cpp + $ +) + +add_performance_test(target + SOURCES + ${PROJECT_SOURCE_DIR}/test/performance/target.cpp + $ +) + +add_performance_test(version + SOURCES ${PROJECT_SOURCE_DIR}/test/performance/version.cpp +) + +add_custom_target(bench + DEPENDS ${STUMPLESS_PERFORMANCE_TEST_RUNNERS} +) + +if(FUZZ) + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz-corpora) + + add_fuzz_test(add_message_str + SOURCES ${PROJECT_SOURCE_DIR}/test/fuzz/add_message_str.cpp + CORPUS_NAME cstring + ) + + add_fuzz_test(stump_str + SOURCES ${PROJECT_SOURCE_DIR}/test/fuzz/stump_str.cpp + CORPUS_NAME cstring + ) + + add_custom_target(fuzz + DEPENDS ${STUMPLESS_FUZZ_TESTS} + ) +endif() + + +# single file generation +include(tools/cmake/single_file.cmake) + + +# c++ support +if(ENABLE_CPP) + if(HAVE_WRAPTURE) + include(tools/cmake/cpp.cmake) + else() + message(WARNING "C++ library cannot be built without wrapture. You can install wrapture using standard gem installation tools, e.g. 'gem install wrapture'") + endif(HAVE_WRAPTURE) +endif() + + +# python support +if(BUILD_PYTHON) + add_swig_project() + + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c + COMMAND ${CMAKE_COMMAND} -E env SWIG_LIB=${source_dir}/Lib ${binary_dir}/swig -python -I${PROJECT_SOURCE_DIR}/include -I${CMAKE_BINARY_DIR}/include -o ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c -outdir ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/swig/stumpless.i + MAIN_DEPENDENCY swig + ) + + add_library(stumplesspython SHARED + ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c + ) + + target_link_libraries(stumplesspython + optimized stumpless + ) + + target_include_directories(stumplesspython + PRIVATE /usr/include/python2.7 + ${PROJECT_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include + ) + + set_target_properties(stumplesspython + PROPERTIES + PREFIX "_" + OUTPUT_NAME stumpless + ) + + set(CTEST_ENVIRONMENT + "PYTHONPATH=${CMAKE_BINARY_DIR}" + ) + + add_dependencies(check + stumplesspython + ) + + add_test(NAME python-version + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR} python ${PROJECT_SOURCE_DIR}/test/function/python/version.py + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + +endif() + + +# doxygen build target +if(DOXYGEN_FOUND) + configure_file(${PROJECT_SOURCE_DIR}/tools/doxygen/Doxyfile.in ${PROJECT_BINARY_DIR}/tools/doxygen/Doxyfile) + + file(GLOB_RECURSE DOXYGEN_PUBLIC_HEADERS ${DOXYGEN_INCLUDE_DIR}/stumpless/*.h) + set(EXAMPLE_SOURCES + ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c + ) + + add_custom_command( + OUTPUT ${DOXYGEN_MANPAGES} + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/tools/doxygen/Doxyfile + MAIN_DEPENDENCY ${PROJECT_BINARY_DIR}/tools/doxygen/Doxyfile + DEPENDS + ${DOXYGEN_PUBLIC_HEADERS} + ${EXAMPLE_SOURCES} + ${DOXYGEN_INCLUDE_DIR}/stumpless.h + ${PROJECT_BINARY_DIR}/include/stumpless/config.h + VERBATIM + ) + + add_custom_target(docs DEPENDS ${DOXYGEN_MANPAGES}) +endif() From e205e0129013eabb439cbf55fd335bad4e3b8ace Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 21:54:21 -0400 Subject: [PATCH 13/38] Corrected source dir --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6dc3f633..ae434c874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1019,7 +1019,7 @@ add_function_test(priority ) add_function_test(prival - SOURCES test/function/prival.cpp + SOURCES ${PROJECT_SOURCE_DIR}/test/function/prival.cpp ) add_custom_target(build-test From 3e7bf70a416bbad576ba9653e2a110c96ff88c3a Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:00:49 -0400 Subject: [PATCH 14/38] Fixed function name in header --- include/private/prival.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/private/prival.h b/include/private/prival.h index 797d95856..6091eb5da 100644 --- a/include/private/prival.h +++ b/include/private/prival.h @@ -37,6 +37,6 @@ * @return The string representation of the given prival. */ int -get_prival_string( int prival ); +stumpless_get_prival_string( int prival ); #endif /* __STUMPLESS_PRIVAL_STRING */ From 767d26354b6853b16b761c21052e2adaadfcf2f0 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:10:06 -0400 Subject: [PATCH 15/38] Adding cstdlib --- test/function/prival.cpp | 1 + test/function/prival.cpp.bak | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/function/prival.cpp.bak diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 8847a0bd6..6e6f97f24 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #include diff --git a/test/function/prival.cpp.bak b/test/function/prival.cpp.bak new file mode 100644 index 000000000..8847a0bd6 --- /dev/null +++ b/test/function/prival.cpp.bak @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2019-2021 Joel E. Anderson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace { + + class PrivalTest : public::testing::Test { + }; + + TEST(GetPrivalString, ValidPrival) { + const char *result; + + result = stumpless_get_prival_string( 11 ); \ + EXPECT_STREQ( result, "3 | 8" ); + } +} \ No newline at end of file From f2c8e5f54cc0ca9ab0559537a6d00b474b0a7937 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:23:11 -0400 Subject: [PATCH 16/38] Trying to include headers in extern C --- test/function/prival.cpp | 4 +++- test/function/prival.cpp.bak | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 6e6f97f24..8293d1a33 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -16,9 +16,11 @@ * limitations under the License. */ -#include + +extern "C" { #include #include +} namespace { diff --git a/test/function/prival.cpp.bak b/test/function/prival.cpp.bak index 8847a0bd6..6e6f97f24 100644 --- a/test/function/prival.cpp.bak +++ b/test/function/prival.cpp.bak @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #include From cafd1a3a0fb6505cb8a302be7f9c1da506004e32 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:25:28 -0400 Subject: [PATCH 17/38] Revert "Trying to include headers in extern C" This reverts commit f2c8e5f54cc0ca9ab0559537a6d00b474b0a7937. --- test/function/prival.cpp | 4 +--- test/function/prival.cpp.bak | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 8293d1a33..6e6f97f24 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -16,11 +16,9 @@ * limitations under the License. */ - -extern "C" { +#include #include #include -} namespace { diff --git a/test/function/prival.cpp.bak b/test/function/prival.cpp.bak index 6e6f97f24..8847a0bd6 100644 --- a/test/function/prival.cpp.bak +++ b/test/function/prival.cpp.bak @@ -16,7 +16,6 @@ * limitations under the License. */ -#include #include #include From 2fd1dd6ec01ed58421986c321558f2291fa8e997 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:29:35 -0400 Subject: [PATCH 18/38] Revert "Adding cstdlib" This reverts commit 767d26354b6853b16b761c21052e2adaadfcf2f0. --- test/function/prival.cpp | 1 - test/function/prival.cpp.bak | 33 --------------------------------- 2 files changed, 34 deletions(-) delete mode 100644 test/function/prival.cpp.bak diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 6e6f97f24..8847a0bd6 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ -#include #include #include diff --git a/test/function/prival.cpp.bak b/test/function/prival.cpp.bak deleted file mode 100644 index 8847a0bd6..000000000 --- a/test/function/prival.cpp.bak +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -/* - * Copyright 2019-2021 Joel E. Anderson - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace { - - class PrivalTest : public::testing::Test { - }; - - TEST(GetPrivalString, ValidPrival) { - const char *result; - - result = stumpless_get_prival_string( 11 ); \ - EXPECT_STREQ( result, "3 | 8" ); - } -} \ No newline at end of file From 3d763ce0bdc60350625d5463197c4df34e348891 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:31:59 -0400 Subject: [PATCH 19/38] Revert "Corrected source dir" This reverts commit e205e0129013eabb439cbf55fd335bad4e3b8ace. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae434c874..f6dc3f633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1019,7 +1019,7 @@ add_function_test(priority ) add_function_test(prival - SOURCES ${PROJECT_SOURCE_DIR}/test/function/prival.cpp + SOURCES test/function/prival.cpp ) add_custom_target(build-test From 9b6513a099a3b7e9514ad894561729d6a392d1a8 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:32:03 -0400 Subject: [PATCH 20/38] Revert "Fixed ordering so that test function is built" This reverts commit 5de7dca611efc65cbbbfad2e3f856346dcb55253. --- CMakeLists.txt | 8 +- CMakeLists.txt.bak | 1214 -------------------------------------------- 2 files changed, 4 insertions(+), 1218 deletions(-) delete mode 100644 CMakeLists.txt.bak diff --git a/CMakeLists.txt b/CMakeLists.txt index f6dc3f633..fd4aa1f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1018,10 +1018,6 @@ add_function_test(priority SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp ) -add_function_test(prival - SOURCES test/function/prival.cpp -) - add_custom_target(build-test DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) @@ -1031,6 +1027,10 @@ add_custom_target(check DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) +add_function_test(prival + SOURCES test/function/prival.cpp +) + # examples add_example(basic ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c diff --git a/CMakeLists.txt.bak b/CMakeLists.txt.bak deleted file mode 100644 index fd4aa1f58..000000000 --- a/CMakeLists.txt.bak +++ /dev/null @@ -1,1214 +0,0 @@ -cmake_minimum_required(VERSION 3.2.3) - -if(POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) -endif() - -project(stumpless VERSION 2.2.0) -set(CMAKE_PROJECT_HOMEPAGE_URL "https://goatshriek.github.io/stumpless/") - -option(BUILD_SHARED_LIBS "Build using shared libraries" ON) - -string(CONCAT enable_cpp_help_string - "Build the C++ language binding library. The library will be added to the " - "'all' target and will be installed via the 'install' target, alongside the " - "C library. Other targets (such as 'docs' and 'check') will have a '-cpp' " - "version that takes the same action for the C++ library. For example, build " - "the 'check-cpp' target to build and run the test suite for the C++ library." -) -option(ENABLE_CPP ${enable_cpp_help_string} OFF) -option(BUILD_PYTHON "include the python libary" OFF) - -option(ENABLE_THREAD_SAFETY "support thread-safe functionality" ON) - -option(ENABLE_CHAIN_TARGETS "support chain targets" ON) -option(ENABLE_JOURNALD_TARGETS "support systemd journald service targets" ON) -option(ENABLE_NETWORK_TARGETS "support network targets" ON) -option(ENABLE_SOCKET_TARGETS "support unix domain socket targets" ON) -option(ENABLE_SQLITE3_TARGETS "support sqlite3 targets" ON) -option(ENABLE_WINDOWS_EVENT_LOG_TARGETS "support windows event log targets" ON) - -option(INSTALL_EXAMPLES "install examples" ON) -option(INSTALL_MANPAGES "install generated manpages" ON) - -option(COVERAGE "Include coverage information" OFF) -option(FUZZ "Support fuzzing with libFuzzer" OFF) - -string(CONCAT enable_deprecation_warnings_help_string - "Print warnings to the standard output when deprecated functionality is used." -) -option(ENABLE_DEPRECATION_WARNINGS ${enable_deprecation_warnings_help_string} ON) - - -# default settings -set(CHAIN_TARGET_ARRAY_LENGTH 4 - CACHE STRING "the chain target static array size" -) - -string(CONCAT default_facility_help_string - "The facility code to use for messages where one is not explicitly provided." -) -set(DEFAULT_FACILITY "STUMPLESS_FACILITY_USER" - CACHE STRING ${default_facility_help_string} -) - -string(CONCAT default_file_help_string - "The name of the file opened if the default target is to a file." -) -set(DEFAULT_FILE "stumpless-default.log" - CACHE STRING "${default_file_help_string}" -) - -string(CONCAT default_severity_help_string - "The severity code to use for messages where one is not explicitly provided." -) -set(DEFAULT_SEVERITY "STUMPLESS_SEVERITY_INFO" - CACHE STRING ${default_severity_help_string} -) - -set(FALLBACK_PAGESIZE 4096 - CACHE STRING "the memory page size to use if it cannot be detected at runtime" -) - -string(CONCAT sqlite3_src_path_help_string - "The path to a SQLite3 source file, referred to as an 'amalgamation' in " - "SQLite documentation. If this variable is set, it is used to link SQLite3 " - "statically with Stumpless, instead of the default dynamic linking." -) -set(SQLITE3_SRC_PATH "" - CACHE FILEPATH ${sqlite3_src_path_help_string} -) - -string(CONCAT sqlite3_include_path_help_string - "The path to the sqlite3.h header matching the source file provided in " - "SQLITE3_SRC_PATH. If the header is already in the include directores, this " - "does not need to be specified." -) -set(SQLITE3_INCLUDE_PATH "" - CACHE FILEPATH ${sqlite3_include_path_help_string} -) - -set(SQLITE3_DEFAULT_TABLE_NAME "logs" - CACHE STRING "the name of the table used by default for SQLite3 targets" -) - -set(SQLITE3_RETRY_MAX 3 - CACHE STRING "the maximum number of retries on SQLite3 operations" -) - -string(CONCAT benchmark_path_help_string - "A directory with a build of google benchmark that can be used instead of " - "downloading and building the library during build. " - "In order for this to be used the directory must include ALL of the " - "following at configuration time: the benchmark and benchmark_main " - "libraries, and the benchmark/benchmark.h header. " - "If the necessary files are not found, the benchmark library will be " - "downloaded and built when it is needed, and the export-benchmark target " - "can be used to populate the provided directory for future builds." -) -set(BENCHMARK_PATH ${PROJECT_BINARY_DIR} - CACHE PATH ${benchmark_path_help_string} -) - -string(CONCAT gtest_path_help_string - "A directory with a build of google test that can be used instead of " - "downloading and building the library during build. " - "In order for this to be used the directory must include ALL of the " - "following at configuration time: the gtest, gtest_main, and gmock " - "libraries, the gtest/gtest.h header, and the gmock/gmock.h header. " - "If the necessary files are not found, the gtest library will be " - "downloaded and built when it is needed, and the export-gtest target " - "can be used to populate the provided directory for future builds." -) -set(GTEST_PATH ${PROJECT_BINARY_DIR} - CACHE PATH ${gtest_path_help_string} -) - -string(CONCAT locale_help_string - "The locale used for strings passed by the library, for example error " - "messages. If this is not set it will use the LANG environment variable " - "of the build system." -) -set(LOCALE $ENV{LANG} - CACHE STRING ${locale_help_string} -) - - -# single file build paths -set(SINGLE_SOURCE_FILE "${PROJECT_BINARY_DIR}/stumpless.c") -set(SINGLE_INCLUDE_DIR "${PROJECT_BINARY_DIR}/include/single_file") -set(SINGLE_HEADER_FILE "${SINGLE_INCLUDE_DIR}/stumpless.h") - - -# load modules -include(CheckIncludeFiles) -include(CheckSymbolExists) -include(ExternalProject) -include(FindDoxygen QUIET) -include(GNUInstallDirs) - - -# load utilities -include(tools/cmake/google_libs.cmake) -include(tools/cmake/add_found_library.cmake) -# the above two need to be before benchmark and gtest - -include(tools/cmake/benchmark.cmake) -include(tools/cmake/example.cmake) -include(tools/cmake/gtest.cmake) -include(tools/cmake/l10n.cmake) -include(tools/cmake/swig.cmake) -include(tools/cmake/test.cmake) - - -# building configuration -if(EXISTS ${SQLITE3_INCLUDE_PATH}) - file(COPY - "${SQLITE3_INCLUDE_PATH}" - DESTINATION "${PROJECT_BINARY_DIR}/include" - ) -endif() - -check_include_files(pthread.h HAVE_PTHREAD_H) -check_include_files(stdatomic.h HAVE_STDATOMIC_H) -check_include_files("sqlite3.h" HAVE_SQLITE3_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(syslog.h STUMPLESS_SYSLOG_H_COMPATIBLE) -check_include_files(systemd/sd-journal.h HAVE_SYSTEMD_SD_JOURNAL_H) -check_include_files(unistd.h HAVE_UNISTD_H) -check_include_files(windows.h HAVE_WINDOWS_H) -check_include_files(winsock2.h HAVE_WINSOCK2_H) - -check_symbol_exists(fopen_s stdio.h HAVE_FOPEN_S) -check_symbol_exists(getaddrinfo netdb.h HAVE_GETADDRINFO) -check_symbol_exists(gethostname unistd.h HAVE_UNISTD_GETHOSTNAME) -check_symbol_exists(gethostbyname netdb.h HAVE_GETHOSTBYNAME) -check_symbol_exists(gethostbyname2 netdb.h HAVE_GETHOSTBYNAME2) -check_symbol_exists(getpagesize unistd.h HAVE_UNISTD_GETPAGESIZE) -check_symbol_exists(gmtime time.h HAVE_GMTIME) -check_symbol_exists(gmtime_r time.h HAVE_GMTIME_R) -check_symbol_exists(_SC_PAGESIZE unistd.h HAVE_UNISTD_SC_PAGESIZE) -check_symbol_exists(sprintf_s stdio.h HAVE_SPRINTF_S) -check_symbol_exists(sysconf unistd.h HAVE_UNISTD_SYSCONF) -check_symbol_exists(vsnprintf_s stdio.h HAVE_VSNPRINTF_S) -check_symbol_exists(wcsrtombs_s wchar.h HAVE_WCSRTOMBS_S) -check_symbol_exists(wcstombs_s windows.h HAVE_WCSTOMBS_S) - -find_program(HAVE_WRAPTURE NAMES wrapture) - -if(ENABLE_DEPRECATION_WARNINGS) - set(STUMPLESS_DEPRECATION_WARNINGS_ENABLED TRUE) -else() - set(STUMPLESS_DEPRECATION_WARNINGS_ENABLED OFF) -endif() - -if(EXISTS "/var/run/syslog") - set(STUMPLESS_DEFAULT_SOCKET "/var/run/syslog") -else() - set(STUMPLESS_DEFAULT_SOCKET "/dev/log") -endif() - - -# standard source files -set(STUMPLESS_SOURCES - ${PROJECT_SOURCE_DIR}/src/cache.c - ${PROJECT_SOURCE_DIR}/src/element.c - ${PROJECT_SOURCE_DIR}/src/entry.c - ${PROJECT_SOURCE_DIR}/src/error.c - ${PROJECT_SOURCE_DIR}/src/facility.c - ${PROJECT_SOURCE_DIR}/src/filter.c - ${PROJECT_SOURCE_DIR}/src/formatter.c - ${PROJECT_SOURCE_DIR}/src/inthelper.c - ${PROJECT_SOURCE_DIR}/src/log.c - ${PROJECT_SOURCE_DIR}/src/memory.c - ${PROJECT_SOURCE_DIR}/src/param.c - ${PROJECT_SOURCE_DIR}/src/severity.c - ${PROJECT_SOURCE_DIR}/src/strbuilder.c - ${PROJECT_SOURCE_DIR}/src/strhelper.c - ${PROJECT_SOURCE_DIR}/src/target.c - ${PROJECT_SOURCE_DIR}/src/target/buffer.c - ${PROJECT_SOURCE_DIR}/src/target/file.c - ${PROJECT_SOURCE_DIR}/src/target/function.c - ${PROJECT_SOURCE_DIR}/src/target/stream.c - ${PROJECT_SOURCE_DIR}/src/version.c - ${PROJECT_SOURCE_DIR}/src/validate.c - ${PROJECT_SOURCE_DIR}/src/priority.c - ${PROJECT_SOURCE_DIR}/src/prival.c -) - - -# wrapture support -set(WRAPTURE_SPECS - # template files must be first - ${PROJECT_SOURCE_DIR}/tools/wrapture/error_templates.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/target_templates.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/buffer_target.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/element.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/entry.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/error.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/facility.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/file_target.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/function_target.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/memory.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/param.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/severity.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/stream_target.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/target.yml - ${PROJECT_SOURCE_DIR}/tools/wrapture/version.yml -) - - -# documentation and doxygen steup -set(DOXYGEN_MANPAGES - ${PROJECT_BINARY_DIR}/docs/man/man3/stumpless.h.3 - ${PROJECT_BINARY_DIR}/docs/man/man3/config.h.3 -) - -set(PROJECT_DOCS_DIR ${PROJECT_BINARY_DIR}/docs) -if(DOXYGEN_FOUND) - set(INCLUDE_MANPAGES_IN_INSTALL ${INSTALL_MANPAGES}) -else() - if(INSTALL_MANPAGES) - message("doxygen is required to generate and install manpages") - endif() - - set(INCLUDE_MANPAGES_IN_INSTALL FALSE) -endif() - -if(${INCLUDE_MANPAGES_IN_INSTALL}) - # we need to do this before any other install commands that depend on the - # manpages generated by doxygen, so that they are generated before use - install(CODE - "execute_process(COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target docs)" - ) -endif() - - -# configuration-specific source files -if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - set(SUPPORT_ABSTRACT_SOCKET_NAMES TRUE) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_supported.c) -else() - set(SUPPORT_ABSTRACT_SOCKET_NAMES FALSE) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_unsupported.c) -endif() - -if(HAVE_FOPEN_S) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_fopen_s.c) -endif(HAVE_FOPEN_S) - -if(HAVE_PTHREAD_H) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_pthread.c) -endif() - -if(HAVE_STDATOMIC_H) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_stdatomic.c) -endif() - -if(HAVE_UNISTD_H) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd.c) -endif(HAVE_UNISTD_H) - -if(HAVE_VSNPRINTF_S) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_vsnprintf_s.c) -else() - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_vsnprintf_s.c) -endif(HAVE_VSNPRINTF_S) - -if(NOT HAVE_WCSRTOMBS_S) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_wcsrtombs_s.c) -endif() - -if(HAVE_WINDOWS_H) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_windows.c) -endif(HAVE_WINDOWS_H) - -if(WIN32) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/windows/stumpless.def) -endif(WIN32) - -if(HAVE_WINDOWS_H AND HAVE_SPRINTF_S) - set(SUPPORT_WINDOWS_GET_NOW TRUE) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/windows_get_now_supported.c) -endif() - -if(HAVE_GMTIME_R) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_gmtime_r.c) -elseif(NOT SUPPORT_WINDOWS_GET_NOW AND HAVE_GMTIME) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_gmtime.c) -else() - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/no_gmtime.c) -endif() - -if(HAVE_UNISTD_GETHOSTNAME) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd_gethostname.c) -elseif(NOT HAVE_WINSOCK2_H) - # need the fallback gethostname definition in this case - set(NEED_FALLBACK TRUE) -endif() - -if(HAVE_UNISTD_SYSCONF AND HAVE_UNISTD_SC_PAGESIZE) - set(SUPPORT_UNISTD_SYSCONF_GETPAGESIZE TRUE) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/unistd_sysconf_getpagesize_supported.c) -elseif(HAVE_UNISTD_GETPAGESIZE) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/have_unistd_getpagesize.c) -elseif(NOT HAVE_WINDOWS_H) - # need the fallback getpagesize definition in this case - set(NEED_FALLBACK TRUE) -endif() - -if(NOT HAVE_UNISTD_H AND NOT HAVE_WINDOWS_H) - # need the fallback getpid definition in this case - set(NEED_FALLBACK TRUE) -endif() - -if(NEED_FALLBACK) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/fallback.c) -endif() - - -# thread safety support check -if(NOT ENABLE_THREAD_SAFETY) - set(STUMPLESS_THREAD_SAFETY_SUPPORTED FALSE) -elseif(NOT HAVE_WINDOWS_H AND (NOT HAVE_PTHREAD_H OR NOT HAVE_STDATOMIC_H)) - message("thread safety is not supported without either windows.h or both pthread.h and stdatomic.h") - set(STUMPLESS_THREAD_SAFETY_SUPPORTED FALSE) -else() - set(STUMPLESS_THREAD_SAFETY_SUPPORTED TRUE) -endif() - - -# chain target support -if(NOT ENABLE_CHAIN_TARGETS) - set(STUMPLESS_CHAIN_TARGETS_SUPPORTED FALSE) -else() - set(STUMPLESS_CHAIN_TARGETS_SUPPORTED TRUE) -endif() - -if(STUMPLESS_CHAIN_TARGETS_SUPPORTED) - include(tools/cmake/chain.cmake) -else() - if(WIN32) - list(APPEND STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/config/chain_unsupported.c") - endif(WIN32) -endif() - - -# journald target support -if(NOT ENABLE_JOURNALD_TARGETS) - set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) -elseif(ENABLE_JOURNALD_TARGETS AND NOT HAVE_SYSTEMD_SD_JOURNAL_H) - message("journald targets are not supported without systemd/sd-journal.h") - set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) -else() - find_library(LIBSYSTEMD_FOUND systemd) - if(LIBSYSTEMD_FOUND) - set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED TRUE) - else() - message("journald targets are not supported without libsystemd") - set(STUMPLESS_JOURNALD_TARGETS_SUPPORTED FALSE) - endif() -endif() - -if(STUMPLESS_JOURNALD_TARGETS_SUPPORTED) - include(tools/cmake/journald.cmake) -else() - add_function_test(journald_unsupported - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/config/journald_unsupported.cpp - $ - ) -endif() - - -# network target support -if(NOT ENABLE_NETWORK_TARGETS) - set(STUMPLESS_NETWORK_TARGETS_SUPPORTED FALSE) -elseif(NOT HAVE_WINSOCK2_H AND NOT HAVE_SYS_SOCKET_H) - message("network targets are not supported without either winsock2.h or sys/socket.h") - set(STUMPLESS_NETWORK_TARGETS_SUPPORTED FALSE) -else() - set(STUMPLESS_NETWORK_TARGETS_SUPPORTED TRUE) -endif() - -if(STUMPLESS_NETWORK_TARGETS_SUPPORTED) - include(tools/cmake/network.cmake) -else() - if(WIN32) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/network_unsupported.c) - endif(WIN32) - - add_function_test(network_unsupported - SOURCES ${PROJECT_SOURCE_DIR}/test/function/config/network_unsupported.cpp - ) -endif() - - -# socket target support -if(NOT ENABLE_SOCKET_TARGETS) - set(STUMPLESS_SOCKET_TARGETS_SUPPORTED FALSE) -elseif(NOT HAVE_SYS_SOCKET_H) - message("socket targets are not supported without sys/socket.h") - set(STUMPLESS_SOCKET_TARGETS_SUPPORTED FALSE) -else() - set(STUMPLESS_SOCKET_TARGETS_SUPPORTED TRUE) -endif() - -if(STUMPLESS_SOCKET_TARGETS_SUPPORTED) - include(tools/cmake/socket.cmake) -else() - add_function_test(socket_unsupported - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/config/socket_unsupported.cpp - $ - ) -endif() - - -# sqlite3 target support -if(NOT ENABLE_SQLITE3_TARGETS) - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) -elseif(SQLITE3_SRC_PATH) - if(NOT EXISTS "${SQLITE3_SRC_PATH}") - message("the specified sqlite3 source file does not exist") - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) - else() - list(APPEND STUMPLESS_SOURCES "${SQLITE3_SRC_PATH}") - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE) - endif() -elseif(NOT HAVE_SQLITE3_H) - message("sqlite3 targets are not supported without sqlite3.h") - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) -else() - find_library(LIBSQLITE3_FOUND sqlite3) - if(LIBSQLITE3_FOUND) - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED TRUE) - else() - message("sqlite3 targets are not supported without libsqlite3") - set(STUMPLESS_SQLITE3_TARGETS_SUPPORTED FALSE) - endif() -endif() - -if(STUMPLESS_SQLITE3_TARGETS_SUPPORTED) - include(tools/cmake/sqlite3.cmake) -else() - list(APPEND - STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/config/sqlite3_unsupported.c" - ) - - add_function_test(sqlite3_unsupported - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/config/sqlite3_unsupported.cpp - $ - ) -endif() - - -# windows event log target support -if(NOT ENABLE_WINDOWS_EVENT_LOG_TARGETS) - set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED FALSE) -elseif(ENABLE_WINDOWS_EVENT_LOG_TARGETS AND NOT HAVE_WINDOWS_H) - message("windows event log targets are not supported without windows.h") - set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED FALSE) -else() - set(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED TRUE) -endif() - -if(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED) - include(tools/cmake/wel.cmake) -else() - list(INSERT WRAPTURE_SPECS 0 ${PROJECT_SOURCE_DIR}/tools/wrapture/no_wel_templates.yml) - - add_function_test(wel_unsupported - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/config/wel_unsupported.cpp - $ - ) -endif() - - -# thread safety support -if(NOT STUMPLESS_THREAD_SAFETY_SUPPORTED) - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/thread_safety_unsupported.c) -else() - list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/thread_safety_supported.c) - - # thread safety tests - add_thread_safety_test(buffer - SOURCES - test/thread_safety/target/buffer.cpp - $ - $ - ) - - add_thread_safety_test(element - SOURCES - test/thread_safety/element.cpp - ) - - add_thread_safety_test(entry - SOURCES - test/thread_safety/entry.cpp - $ - ) - - add_thread_safety_test(file - SOURCES - test/thread_safety/target/file.cpp - $ - $ - ) - - add_thread_safety_test(function - SOURCES - ${PROJECT_SOURCE_DIR}/test/thread_safety/target/function.cpp - $ - ) - - add_thread_safety_test(param - SOURCES - test/thread_safety/param.cpp - ) - - add_thread_safety_test(stream - SOURCES - test/thread_safety/target/stream.cpp - $ - $ - ) - - add_thread_safety_test(target - SOURCES - test/thread_safety/target.cpp - ) - - add_custom_target(check-thread-safety - DEPENDS ${STUMPLESS_THREAD_SAFETY_TEST_RUNNERS} - ) -endif() - - -# library definition -add_library(stumpless ${STUMPLESS_SOURCES}) -set_target_properties(stumpless PROPERTIES VERSION ${PROJECT_VERSION}) -set_target_properties(stumpless PROPERTIES PUBLIC_HEADER include/stumpless.h) - -target_link_libraries(stumpless PRIVATE ${STUMPLESS_LINK_LIBRARIES}) - -if(MINGW) - target_compile_options(stumpless PRIVATE -D__USE_MINGW_ANSI_STDIO) - set_target_properties(stumpless PROPERTIES PREFIX "") -endif() - -if(STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED) - add_dependencies(stumpless default_events) -endif() - -if(HAVE_STDATOMIC_H) - find_library(LIBATOMIC_FOUND atomic) - if(LIBATOMIC_FOUND) - target_link_libraries(stumpless PRIVATE atomic) - endif() -endif() - -if(HAVE_WINSOCK2_H) - target_link_libraries(stumpless PRIVATE Ws2_32) -endif(HAVE_WINSOCK2_H) - -if(COVERAGE) - target_compile_options(stumpless PRIVATE --coverage) - target_link_libraries(stumpless PRIVATE --coverage) -endif(COVERAGE) - -if(FUZZ) - target_compile_options(stumpless PRIVATE "-fsanitize=fuzzer,address") - target_link_libraries(stumpless PRIVATE "-fsanitize=fuzzer,address") -endif(FUZZ) - -target_include_directories(stumpless - PRIVATE - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_BINARY_DIR}/include -) - - -# optimization options -if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") - set(PUBLIC_FUNCTION_DECORATION "__attribute__ ((visibility (\"default\")))") - set(UNLIKELY_FUNCTION "__builtin_expect( ( EXPRESSION ), 0 )") - set(COLD_FUNCTION "__attribute__ ((cold))") -else() - set(PUBLIC_FUNCTION_DECORATION "") - set(UNLIKELY_FUNCTION "( EXPRESSION )") - set(COLD_FUNCTION "") -endif() - -if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") - target_compile_options(stumpless - PRIVATE "-fvisibility=hidden") - - target_link_libraries(stumpless - PRIVATE "-s") - - if(NOT CYGWIN) - target_compile_options(stumpless - PRIVATE "-flto") - - target_link_libraries(stumpless - PRIVATE "-flto") - endif() - endif() -endif() - - - -# generating configuration files -set(FUZZ_CORPORA_DIR ${PROJECT_SOURCE_DIR}/test/corpora) -configure_file(${PROJECT_SOURCE_DIR}/include/stumpless/config.h.in ${PROJECT_BINARY_DIR}/include/stumpless/config.h) -configure_file(${PROJECT_SOURCE_DIR}/include/private/config.h.in ${PROJECT_BINARY_DIR}/include/private/config.h) -configure_file(${PROJECT_SOURCE_DIR}/include/test/config.hpp.in ${PROJECT_BINARY_DIR}/include/test/config.hpp) -configure_file(${PROJECT_SOURCE_DIR}/tools/portage/stumpless.ebuild.in - ${PROJECT_BINARY_DIR}/tools/portage/stumpless-${PROJECT_VERSION}.ebuild - @ONLY -) - - -# installation of the library -install(TARGETS stumpless - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) - -install(FILES - ${PROJECT_BINARY_DIR}/include/stumpless/config.h - ${PROJECT_SOURCE_DIR}/include/stumpless/element.h - ${PROJECT_SOURCE_DIR}/include/stumpless/entry.h - ${PROJECT_SOURCE_DIR}/include/stumpless/error.h - ${PROJECT_SOURCE_DIR}/include/stumpless/facility.h - ${PROJECT_SOURCE_DIR}/include/stumpless/filter.h - ${PROJECT_SOURCE_DIR}/include/stumpless/generator.h - ${PROJECT_SOURCE_DIR}/include/stumpless/id.h - ${PROJECT_SOURCE_DIR}/include/stumpless/log.h - ${PROJECT_SOURCE_DIR}/include/stumpless/memory.h - ${PROJECT_SOURCE_DIR}/include/stumpless/option.h - ${PROJECT_SOURCE_DIR}/include/stumpless/param.h - ${PROJECT_SOURCE_DIR}/include/stumpless/severity.h - ${PROJECT_SOURCE_DIR}/include/stumpless/target.h - ${PROJECT_SOURCE_DIR}/include/stumpless/version.h - ${PROJECT_SOURCE_DIR}/include/stumpless/priority.h - ${PROJECT_SOURCE_DIR}/include/stumpless/prival.h - DESTINATION "include/stumpless" -) - -install(FILES - ${PROJECT_SOURCE_DIR}/include/stumpless/level/alert.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/crit.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/debug.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/emerg.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/err.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/info.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/mask.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/notice.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/trace.h - ${PROJECT_SOURCE_DIR}/include/stumpless/level/warning.h - DESTINATION "include/stumpless/level" -) - -install(FILES - ${PROJECT_SOURCE_DIR}/include/stumpless/target/buffer.h - ${PROJECT_SOURCE_DIR}/include/stumpless/target/file.h - ${PROJECT_SOURCE_DIR}/include/stumpless/target/function.h - ${PROJECT_SOURCE_DIR}/include/stumpless/target/sqlite3.h - ${PROJECT_SOURCE_DIR}/include/stumpless/target/stream.h - DESTINATION "include/stumpless/target" -) - -include(tools/cmake/cpack.cmake) - -include(FindPkgConfig QUIET) -if(PKG_CONFIG_FOUND) - configure_file("${PROJECT_SOURCE_DIR}/tools/pkg-config/stumpless.pc.in" "${PROJECT_BINARY_DIR}/tools/pkg-config/stumpless.pc" @ONLY) - install(FILES "${PROJECT_BINARY_DIR}/tools/pkg-config/stumpless.pc" - DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") -endif() - - -# installation of examples if enabled -if(INSTALL_EXAMPLES) - install(DIRECTORY - ${PROJECT_SOURCE_DIR}/docs/examples - DESTINATION ${CMAKE_INSTALL_DOCDIR} - ) -endif() - - -# installation of manpages if enabled and supported -if(INCLUDE_MANPAGES_IN_INSTALL) - include(tools/cmake/install_manpages.cmake) -endif() - - -# functionality tests -add_function_test(buffer - SOURCES - test/function/target/buffer.cpp - $ - $ -) - -add_function_test(buffer_leak - SOURCES - test/function/leak/buffer.cpp - $ -) - -add_function_test(current_target - SOURCES test/function/startup/current_target.cpp -) - -add_function_test(element - SOURCES test/function/element.cpp -) - -add_function_test(element_leak - SOURCES test/function/leak/element.cpp -) - -add_function_test(entry - SOURCES - test/function/entry.cpp - $ -) - -add_function_test(entry_leak - SOURCES - test/function/leak/entry.cpp - $ -) - -add_function_test(entry_memory_failure - SOURCES test/function/startup/entry_memory_failure.cpp -) - -add_function_test(error - SOURCES - test/function/error.cpp - $ -) - -add_function_test(error_leak - SOURCES test/function/leak/error.cpp -) - -add_function_test(error_memory_failure - SOURCES test/function/startup/error_memory_failure.cpp -) - -add_function_test(facility - SOURCES test/function/facility.cpp -) - -add_function_test(file - SOURCES - test/function/target/file.cpp - $ -) - -add_function_test(filter - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/filter.cpp - $ -) - -add_function_test(function - SOURCES ${PROJECT_SOURCE_DIR}/test/function/target/function.cpp -) - -add_function_test(get_error_stream - SOURCES ${PROJECT_SOURCE_DIR}/test/function/startup/get_error_stream.cpp -) - -add_function_test(level_all_disabled - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/all_disabled.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_ALL_LEVELS -) - -add_function_test(level_all_enabled - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/all_enabled.cpp - $ -) - -add_function_test(level_disabled_downto_alert - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_emerg.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_ALERT -) - -add_function_test(level_disabled_downto_emerg - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/all_disabled.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_EMERG -) - -add_function_test(level_disabled_downto_err - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_crit.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_ERR -) - -add_function_test(level_disabled_downto_crit - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_alert.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_CRIT -) - -add_function_test(level_disabled_downto_debug - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_info.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_DEBUG -) - -add_function_test(level_disabled_downto_info - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_notice.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_INFO -) - -add_function_test(level_disabled_downto_notice - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_warning.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_NOTICE -) - -add_function_test(level_disabled_downto_trace - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_debug.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_TRACE -) - -add_function_test(level_disabled_downto_warning - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_err.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_DISABLE_DOWNTO_WARNING -) - -add_function_test(level_enable_upto_alert - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_alert.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_ALERT -) - -add_function_test(level_enable_upto_crit - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_crit.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_CRIT -) - -add_function_test(level_enable_upto_debug - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_debug.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_DEBUG -) - -add_function_test(level_enable_upto_emerg - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_emerg.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_EMERG -) - -add_function_test(level_enable_upto_err - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_err.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_ERR -) - -add_function_test(level_enable_upto_info - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_info.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_INFO -) - -add_function_test(level_enable_upto_notice - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_notice.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_NOTICE -) - -add_function_test(level_enable_upto_trace - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/all_enabled.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_TRACE -) - -add_function_test(level_enable_upto_warning - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/level/enable_upto_warning.cpp - $ - COMPILE_DEFINITIONS STUMPLESS_ENABLE_UPTO_WARNING -) - -add_function_test(log - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/log.cpp - $ -) - -add_function_test(memory - SOURCES ${PROJECT_SOURCE_DIR}/test/function/memory.cpp -) - -add_function_test(param - SOURCES ${PROJECT_SOURCE_DIR}/test/function/param.cpp -) - -add_function_test(perror - SOURCES ${PROJECT_SOURCE_DIR}/test/function/startup/perror.cpp -) - -add_function_test(severity - SOURCES ${PROJECT_SOURCE_DIR}/test/function/severity.cpp -) - -add_function_test(stream - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/target/stream.cpp - $ - $ -) - -add_function_test(target - SOURCES - ${PROJECT_SOURCE_DIR}/test/function/target.cpp - $ - $ -) - -add_function_test(target_leak - SOURCES ${PROJECT_SOURCE_DIR}/test/function/leak/target.cpp -) - -add_function_test(version - SOURCES ${PROJECT_SOURCE_DIR}/test/function/version.cpp -) - -add_function_test(priority - SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp -) - -add_custom_target(build-test - DEPENDS ${STUMPLESS_FUNCTION_TESTS} -) - -add_custom_target(check - COMMAND ${CMAKE_CTEST_COMMAND} -C ${CMAKE_BUILD_TYPE} - DEPENDS ${STUMPLESS_FUNCTION_TESTS} -) - -add_function_test(prival - SOURCES test/function/prival.cpp -) - -# examples -add_example(basic - ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c -) - -add_example(entry - ${PROJECT_SOURCE_DIR}/docs/examples/entry/entry_example.c -) - -add_example(file - ${PROJECT_SOURCE_DIR}/docs/examples/file/file_example.c -) - -add_example(filter - ${PROJECT_SOURCE_DIR}/docs/examples/filter/filter_example.c -) - -add_example(function - ${PROJECT_SOURCE_DIR}/docs/examples/function/function_example.c -) - -add_example(severity_level - ${PROJECT_SOURCE_DIR}/docs/examples/severity_level/severity_level_example.c -) - -add_example(stream - ${PROJECT_SOURCE_DIR}/docs/examples/stream/stream_example.c -) - -add_custom_target(examples - DEPENDS ${STUMPLESS_EXAMPLE_RUNNERS} -) - - -# performance tests -add_performance_test(element -SOURCES test/performance/element.cpp -) - -add_performance_test(priority -SOURCES test/performance/priority.cpp -) - -add_performance_test(entry - SOURCES - ${PROJECT_SOURCE_DIR}/test/performance/entry.cpp - $ -) - -add_performance_test(function - SOURCES - ${PROJECT_SOURCE_DIR}/test/performance/target/function.cpp - $ -) - -add_performance_test(log - SOURCES test/performance/log.cpp -) - -add_performance_test(param - SOURCES - ${PROJECT_SOURCE_DIR}/test/performance/param.cpp - $ -) - -add_performance_test(target - SOURCES - ${PROJECT_SOURCE_DIR}/test/performance/target.cpp - $ -) - -add_performance_test(version - SOURCES ${PROJECT_SOURCE_DIR}/test/performance/version.cpp -) - -add_custom_target(bench - DEPENDS ${STUMPLESS_PERFORMANCE_TEST_RUNNERS} -) - -if(FUZZ) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz-corpora) - - add_fuzz_test(add_message_str - SOURCES ${PROJECT_SOURCE_DIR}/test/fuzz/add_message_str.cpp - CORPUS_NAME cstring - ) - - add_fuzz_test(stump_str - SOURCES ${PROJECT_SOURCE_DIR}/test/fuzz/stump_str.cpp - CORPUS_NAME cstring - ) - - add_custom_target(fuzz - DEPENDS ${STUMPLESS_FUZZ_TESTS} - ) -endif() - - -# single file generation -include(tools/cmake/single_file.cmake) - - -# c++ support -if(ENABLE_CPP) - if(HAVE_WRAPTURE) - include(tools/cmake/cpp.cmake) - else() - message(WARNING "C++ library cannot be built without wrapture. You can install wrapture using standard gem installation tools, e.g. 'gem install wrapture'") - endif(HAVE_WRAPTURE) -endif() - - -# python support -if(BUILD_PYTHON) - add_swig_project() - - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c - COMMAND ${CMAKE_COMMAND} -E env SWIG_LIB=${source_dir}/Lib ${binary_dir}/swig -python -I${PROJECT_SOURCE_DIR}/include -I${CMAKE_BINARY_DIR}/include -o ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c -outdir ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/swig/stumpless.i - MAIN_DEPENDENCY swig - ) - - add_library(stumplesspython SHARED - ${CMAKE_BINARY_DIR}/stumpless_python_wrap.c - ) - - target_link_libraries(stumplesspython - optimized stumpless - ) - - target_include_directories(stumplesspython - PRIVATE /usr/include/python2.7 - ${PROJECT_SOURCE_DIR}/include - ${CMAKE_BINARY_DIR}/include - ) - - set_target_properties(stumplesspython - PROPERTIES - PREFIX "_" - OUTPUT_NAME stumpless - ) - - set(CTEST_ENVIRONMENT - "PYTHONPATH=${CMAKE_BINARY_DIR}" - ) - - add_dependencies(check - stumplesspython - ) - - add_test(NAME python-version - COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR} python ${PROJECT_SOURCE_DIR}/test/function/python/version.py - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - -endif() - - -# doxygen build target -if(DOXYGEN_FOUND) - configure_file(${PROJECT_SOURCE_DIR}/tools/doxygen/Doxyfile.in ${PROJECT_BINARY_DIR}/tools/doxygen/Doxyfile) - - file(GLOB_RECURSE DOXYGEN_PUBLIC_HEADERS ${DOXYGEN_INCLUDE_DIR}/stumpless/*.h) - set(EXAMPLE_SOURCES - ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c - ) - - add_custom_command( - OUTPUT ${DOXYGEN_MANPAGES} - COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/tools/doxygen/Doxyfile - MAIN_DEPENDENCY ${PROJECT_BINARY_DIR}/tools/doxygen/Doxyfile - DEPENDS - ${DOXYGEN_PUBLIC_HEADERS} - ${EXAMPLE_SOURCES} - ${DOXYGEN_INCLUDE_DIR}/stumpless.h - ${PROJECT_BINARY_DIR}/include/stumpless/config.h - VERBATIM - ) - - add_custom_target(docs DEPENDS ${DOXYGEN_MANPAGES}) -endif() From f26f711adabf06873ca5b5ea4b2ee89ddbd07619 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:32:41 -0400 Subject: [PATCH 21/38] Fixed cmakelists order --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd4aa1f58..ae434c874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1018,6 +1018,10 @@ add_function_test(priority SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp ) +add_function_test(prival + SOURCES ${PROJECT_SOURCE_DIR}/test/function/prival.cpp +) + add_custom_target(build-test DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) @@ -1027,10 +1031,6 @@ add_custom_target(check DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) -add_function_test(prival - SOURCES test/function/prival.cpp -) - # examples add_example(basic ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c From 4128458507c4aed0098ef45de4d3a9645a94dc27 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:33:25 -0400 Subject: [PATCH 22/38] Trying extern C for prival.h --- test/function/prival.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 8847a0bd6..cadd90c0c 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -19,6 +19,10 @@ #include #include +extern "C" { +#include +} + namespace { class PrivalTest : public::testing::Test { From 4f6962e5ae82f546a997c8429a4959dd4808adac Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:38:25 -0400 Subject: [PATCH 23/38] Trying another way --- test/function/prival.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index cadd90c0c..6dea03a2b 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -17,10 +17,8 @@ */ #include -#include - extern "C" { -#include +#include } namespace { From d903d8afbbbe24ccf916bdf71f05ab44a25eb406 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 22:42:37 -0400 Subject: [PATCH 24/38] Fiixing header to use extern C --- include/stumpless/prival.h | 7 +++++++ test/function/prival.cpp | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index d7c646aba..9930796cd 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -29,6 +29,9 @@ # include # endif +#ifdef __cplusplus +extern "C" { +#endif /** * Gets the string representation of the given prival. * @@ -52,4 +55,8 @@ STUMPLESS_PUBLIC_FUNCTION const char * stumpless_get_prival_string( int prival ); +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif /* __STUMPLESS_PRIVAL_STRING */ diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 6dea03a2b..8847a0bd6 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -17,9 +17,7 @@ */ #include -extern "C" { #include -} namespace { From 8b2fb8a3e78f505655ef5ee293e761443743d669 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 23:00:37 -0400 Subject: [PATCH 25/38] Testing resultant string length --- src/prival.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prival.c b/src/prival.c index 385d80096..8fe41ae11 100644 --- a/src/prival.c +++ b/src/prival.c @@ -33,7 +33,7 @@ const char* stumpless_get_prival_string( int prival ) { const char *severity = stumpless_get_severity_string( get_severity( prival ) ); const char *facility = stumpless_get_facility_string( get_facility( prival ) ); - size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 3); //+3 for formatting + size_t prival_string_length = ( strlen( severity ) + strlen( facility ) + 4); //+3 for formatting, +1 for termination char *prival_string = alloc_mem( prival_string_length ); snprintf(prival_string, prival_string_length, "%s | %s", severity, facility); From 6f9d86850bce2a81cf2ab2c2c4e8a1b7f6cbb446 Mon Sep 17 00:00:00 2001 From: uFarad Date: Sun, 14 Apr 2024 23:16:43 -0400 Subject: [PATCH 26/38] Fixed test to comply with RFC --- test/function/prival.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/function/prival.cpp b/test/function/prival.cpp index 8847a0bd6..9acc830dc 100644 --- a/test/function/prival.cpp +++ b/test/function/prival.cpp @@ -28,6 +28,6 @@ namespace { const char *result; result = stumpless_get_prival_string( 11 ); \ - EXPECT_STREQ( result, "3 | 8" ); + EXPECT_STREQ( result, "STUMPLESS_SEVERITY_ERR | STUMPLESS_FACILITY_USER" ); } } \ No newline at end of file From ded8f4703c68a2add67b2310d7324f63ec47a259 Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:30:26 -0400 Subject: [PATCH 27/38] Readded divider newline --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae434c874..eae691e4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1031,6 +1031,7 @@ add_custom_target(check DEPENDS ${STUMPLESS_FUNCTION_TESTS} ) + # examples add_example(basic ${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c From 41472a9b29b4cf1a70b2c05c478ab6e546921575 Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:31:15 -0400 Subject: [PATCH 28/38] Remove unused header --- include/private/prival.h | 42 ---------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 include/private/prival.h diff --git a/include/private/prival.h b/include/private/prival.h deleted file mode 100644 index 6091eb5da..000000000 --- a/include/private/prival.h +++ /dev/null @@ -1,42 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -/* - * Copyright 2018-2022 Joel E. Anderson - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __STUMPLESS_PRIVAL_STRING -# define __STUMPLESS_PRIVAL_STRING - -/** - * Function for converting prival from int to string - * - * **Thread Safety: MT-Safe** - * This function is thread safe. - * - * **Async Signal Safety: AS-Safe** - * This function is safe to call from signal handlers. - * - * **Async Cancel Safety: AC-Safe** - * This function is safe to call from threads that may be asynchronously - * cancelled. - * - * @param prival int to get the string from. - * - * @return The string representation of the given prival. - */ -int -stumpless_get_prival_string( int prival ); - -#endif /* __STUMPLESS_PRIVAL_STRING */ From 37458a2b03a15c782e63b71bc53302fb457027ec Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:36:23 -0400 Subject: [PATCH 29/38] Renamed header guard to meet project requirements --- include/stumpless/prival.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 9930796cd..c12893544 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -20,8 +20,8 @@ * Function for converting prival from int to string */ -#ifndef __STUMPLESS_PRIVAL_STRING -# define __STUMPLESS_PRIVAL_STRING +#ifndef __STUMPLESS_PRIVAL_H +# define __STUMPLESS_PRIVAL_H # include @@ -59,4 +59,4 @@ stumpless_get_prival_string( int prival ); } /* extern "C" */ #endif -#endif /* __STUMPLESS_PRIVAL_STRING */ +#endif /* __STUMPLESS_PRIVAL_H */ From e0554246614f9414e8aa3fc114acc2326659879b Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:40:56 -0400 Subject: [PATCH 30/38] Corrected comments that returned string should be freed --- include/stumpless/prival.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index c12893544..a2a846fca 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -35,7 +35,7 @@ extern "C" { /** * Gets the string representation of the given prival. * - * This is a string literal that should not be modified or freed by the caller. + * This is a string that must be freed by the caller * * **Thread Safety: MT-Safe** * This function is thread safe. From 97d531c761f4945d72ef2c7f6285b7823d852f9e Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:46:34 -0400 Subject: [PATCH 31/38] Used specific language for memory free notice --- include/stumpless/prival.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index a2a846fca..52f5deec3 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -35,7 +35,8 @@ extern "C" { /** * Gets the string representation of the given prival. * - * This is a string that must be freed by the caller + * The string returned must be freed by the caller when it is no longer + * needed to avoid memory leaks. * * **Thread Safety: MT-Safe** * This function is thread safe. From c57d53db2727cf779370fc75d668c2e5b31f2e5d Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:54:26 -0400 Subject: [PATCH 32/38] Added since tag --- include/stumpless/prival.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 52f5deec3..5e63203e5 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -48,6 +48,8 @@ extern "C" { * This function is safe to call from threads that may be asynchronously * cancelled. * + * @since release v2.2.0 + * * @param prival int to get the string from. * * @return The string representation of the given prival. From 72b0d6afbef5e2f4e6be4ac43e2d45603b97006f Mon Sep 17 00:00:00 2001 From: uFarad Date: Tue, 16 Apr 2024 23:55:23 -0400 Subject: [PATCH 33/38] Corrected safety information --- include/stumpless/prival.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 5e63203e5..376e52ba2 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -41,12 +41,13 @@ extern "C" { * **Thread Safety: MT-Safe** * This function is thread safe. * - * **Async Signal Safety: AS-Safe** - * This function is safe to call from signal handlers. + * **Async Signal Safety: AS-Unsafe heap** + * This function is not safe to call from signal handlers due to the use of + * memory management functions. * - * **Async Cancel Safety: AC-Safe** - * This function is safe to call from threads that may be asynchronously - * cancelled. + * **Async Cancel Safety: AC-Unsafe heap** + * This function is not safe to call from threads that may be asynchronously + * cancelled due to the use of memory management functions. * * @since release v2.2.0 * From 3381591504970a2bcbf8b21fefdf3c5fb13bf3d8 Mon Sep 17 00:00:00 2001 From: uFarad Date: Wed, 17 Apr 2024 00:00:25 -0400 Subject: [PATCH 34/38] Remove unused include --- include/stumpless/prival.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/stumpless/prival.h b/include/stumpless/prival.h index 376e52ba2..e3bfebc8b 100644 --- a/include/stumpless/prival.h +++ b/include/stumpless/prival.h @@ -25,10 +25,6 @@ # include -# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE -# include -# endif - #ifdef __cplusplus extern "C" { #endif From 24226ce7d015cd5207f7dbdb805a8c5f4d0d6049 Mon Sep 17 00:00:00 2001 From: uFarad Date: Wed, 17 Apr 2024 21:30:02 -0400 Subject: [PATCH 35/38] Removed unused headers --- src/prival.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/prival.c b/src/prival.c index 8fe41ae11..8b7e47ba7 100644 --- a/src/prival.c +++ b/src/prival.c @@ -22,10 +22,8 @@ #include #include #include -#include "private/prival.h" #include "private/severity.h" #include "private/facility.h" -#include "private/prival.h" #include "private/strhelper.h" #include "private/memory.h" From 5e117cd904fa04f21550679ea3a75c6ff06812f4 Mon Sep 17 00:00:00 2001 From: uFarad Date: Wed, 17 Apr 2024 21:42:54 -0400 Subject: [PATCH 36/38] Removed more unused includes --- src/prival.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/prival.c b/src/prival.c index 8b7e47ba7..41be348dc 100644 --- a/src/prival.c +++ b/src/prival.c @@ -16,15 +16,12 @@ * limitations under the License. */ -#include -#include #include #include #include #include #include "private/severity.h" #include "private/facility.h" -#include "private/strhelper.h" #include "private/memory.h" const char* stumpless_get_prival_string( int prival ) { From e904ae3892cda0f0d656232194809c1fab1e138a Mon Sep 17 00:00:00 2001 From: uFarad Date: Wed, 17 Apr 2024 21:43:55 -0400 Subject: [PATCH 37/38] Revert "Removed more unused includes" This reverts commit 5e117cd904fa04f21550679ea3a75c6ff06812f4. --- src/prival.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/prival.c b/src/prival.c index 41be348dc..8b7e47ba7 100644 --- a/src/prival.c +++ b/src/prival.c @@ -16,12 +16,15 @@ * limitations under the License. */ +#include +#include #include #include #include #include #include "private/severity.h" #include "private/facility.h" +#include "private/strhelper.h" #include "private/memory.h" const char* stumpless_get_prival_string( int prival ) { From c50a81e326a9d1d7b058ec0ac4f43c589b6be46a Mon Sep 17 00:00:00 2001 From: uFarad Date: Wed, 17 Apr 2024 21:46:20 -0400 Subject: [PATCH 38/38] Re-added string.h --- src/prival.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/prival.c b/src/prival.c index 8b7e47ba7..955b0c599 100644 --- a/src/prival.c +++ b/src/prival.c @@ -16,7 +16,6 @@ * limitations under the License. */ -#include #include #include #include @@ -24,7 +23,6 @@ #include #include "private/severity.h" #include "private/facility.h" -#include "private/strhelper.h" #include "private/memory.h" const char* stumpless_get_prival_string( int prival ) {