From c9896e575a23a4b3bfe48586257f4029128f0f72 Mon Sep 17 00:00:00 2001 From: reshmadev12 <141902375+reshmadev12@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:03:21 +0530 Subject: [PATCH 1/5] Updates to generate windows library --- CMakeLists.txt | 25 +++++++++++++++++-------- src/genericCMPClient_util.c | 25 +++++++++++++++++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2414f2a3..5cd23944 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ endif() # its dynamic libs have been installed in ./${LIB} when using the libs # see for binaries dynamically linked to OpenSSL the output of ${LDD} if(CMAKE_SYSTEM_NAME MATCHES "Windows") - set(USERS "^(\w:)?\\Users\\") + set(USERS "^([a-zA-Z]:)?\\\\Users\\\\") set(LIB "bin") else() set(USERS "^/(home|Users)/") @@ -208,13 +208,22 @@ endif() add_compile_definitions(DEBUG_UNUSED) add_compile_definitions(PEDANTIC) -add_compile_options(-pedantic) # -Werror is enabled only for development and CI, using Makefile_v1 without NDEBUG -add_compile_options( - -Wall -Woverflow -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wswitch - -Wsign-compare -Wformat -Wtype-limits -Wundef -Wconversion -Wunused-parameter) -add_compile_options(-Wno-c99-extensions -Wno-language-extension-token -Wno-declaration-after-statement -Wno-expansion-to-defined) -if(NOT DEFINED GENCMP_NO_SECUTILS) - add_compile_options(-Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-shadow) + +if(MSVC) + # MSVC compiler flags + add_compile_options(/W4) # High warning level + add_compile_options(/wd4996) # Disable deprecated function warnings + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +else() + # GCC/Clang compiler flags + add_compile_options(-pedantic) # -Werror is enabled only for development and CI, using Makefile_v1 without NDEBUG + add_compile_options( + -Wall -Woverflow -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wswitch + -Wsign-compare -Wformat -Wtype-limits -Wundef -Wconversion -Wunused-parameter) + add_compile_options(-Wno-c99-extensions -Wno-language-extension-token -Wno-declaration-after-statement -Wno-expansion-to-defined) + if(NOT DEFINED GENCMP_NO_SECUTILS) + add_compile_options(-Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-shadow) + endif() endif() # TODO maybe clean up code and re-enable property # set_property(TARGET ${LIBGENCMP_NAME} PROPERTY C_STANDARD 90) diff --git a/src/genericCMPClient_util.c b/src/genericCMPClient_util.c index 4b7cc976..446e10c1 100644 --- a/src/genericCMPClient_util.c +++ b/src/genericCMPClient_util.c @@ -38,15 +38,32 @@ void UTIL_cleanse_free(OPTIONAL char *str) /* log.c: */ -#include +#ifdef _WIN32 + /* Windows doesn't have syslog, so we'll use Windows Event Log or just disable syslog */ + #define LOG_EMERG 0 + #define LOG_ALERT 1 + #define LOG_CRIT 2 + #define LOG_ERR 3 + #define LOG_WARNING 4 + #define LOG_NOTICE 5 + #define LOG_INFO 6 + #define LOG_DEBUG 7 + static void syslog(int priority, const char *format, ...) { + /* Stub implementation for Windows - could be enhanced to use Windows Event Log */ + (void)priority; + (void)format; + } +#else + #include +#endif static const char *const GENCMP_NAME = "genCMPClient"; -static const size_t loc_len = 256; +#define loc_len 256 /*!< these variables are shared between threads */ static LOG_cb_t LOG_fn = 0; -static const char *app_name = GENCMP_NAME; -static severity verbosity = LOG_WARNING; +static const char *app_name = "genCMPClient"; +static severity verbosity = 4; /* LOG_WARNING equivalent */ BIO *bio_err = 0; BIO *bio_trace = 0; From 0cac485b8c4226e276a0e455ee7b65b29e7eadee Mon Sep 17 00:00:00 2001 From: Rajeev Ranjan Date: Fri, 24 Oct 2025 16:06:45 +0200 Subject: [PATCH 2/5] add workflow for Windows --- .github/workflows/windows.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..0c5cdf24 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,21 @@ +# GitHub Actions for genCMPClient +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) Siemens AG, 2021-2025 + +name: Windows + +on: push +jobs: + cmake: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: cmake + run: | + mkdir build + cd build + $env:GENCMP_NO_SECUTILS=1; cmake .. + cmake --build . --config Release + + + From 9754ab2cac8e6268e5123447a3de85aa05058ccb Mon Sep 17 00:00:00 2001 From: Rajeev Ranjan <111538666+rajeev-0@users.noreply.github.com> Date: Wed, 28 Jan 2026 14:06:00 +0100 Subject: [PATCH 3/5] Enhance OpenSSL library checks to handle debug and optimized versions --- CMakeLists.txt | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cd23944..f98b7699 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,8 +133,29 @@ if(NOT TARGET OpenSSL::Crypto) # not already done by superordinate module endif() endif() message(STATUS "using OpenSSL library ${OPENSSL_CRYPTO_LIBRARY}, ${OPENSSL_SSL_LIBRARY}") -if(NOT EXISTS "${OPENSSL_CRYPTO_LIBRARY}") - message(FATAL_ERROR "OpenSSL crypto library file does not exist: ${OPENSSL_CRYPTO_LIBRARY}") +# Handle cases where OPENSSL_CRYPTO_LIBRARY contains both debug and optimized versions +if(OPENSSL_CRYPTO_LIBRARY MATCHES "optimized|debug") + # Extract the actual library paths from the optimized/debug list + string(REGEX REPLACE ".*optimized;([^;]+).*" "\\1" OPENSSL_CRYPTO_LIB_RELEASE "${OPENSSL_CRYPTO_LIBRARY}") + string(REGEX REPLACE ".*debug;([^;]+).*" "\\1" OPENSSL_CRYPTO_LIB_DEBUG "${OPENSSL_CRYPTO_LIBRARY}") + + # Check if at least one version exists + set(CRYPTO_LIB_EXISTS FALSE) + if(DEFINED OPENSSL_CRYPTO_LIB_RELEASE AND EXISTS "${OPENSSL_CRYPTO_LIB_RELEASE}") + set(CRYPTO_LIB_EXISTS TRUE) + endif() + if(DEFINED OPENSSL_CRYPTO_LIB_DEBUG AND EXISTS "${OPENSSL_CRYPTO_LIB_DEBUG}") + set(CRYPTO_LIB_EXISTS TRUE) + endif() + + if(NOT CRYPTO_LIB_EXISTS) + message(FATAL_ERROR "Neither OpenSSL crypto library exists: ${OPENSSL_CRYPTO_LIBRARY}") + endif() +else() + # Single library path case + if(NOT EXISTS "${OPENSSL_CRYPTO_LIBRARY}") + message(FATAL_ERROR "OpenSSL crypto library file does not exist: ${OPENSSL_CRYPTO_LIBRARY}") + endif() endif() # workaround for using local OpenSSL builds by default expecting that From f123eed0e237ed7b73cf033bc87657dde94d0d47 Mon Sep 17 00:00:00 2001 From: reshmadev12 <141902375+reshmadev12@users.noreply.github.com> Date: Fri, 30 Jan 2026 00:33:41 +0530 Subject: [PATCH 4/5] Updated to address the review comments. Also made the changes to generate static library instead of dynamic library --- CMakeLists.txt | 6 +++--- src/genericCMPClient_util.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f98b7699..a45120b7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ if(NOT DEFINED GENCMPCLIENT_VERSION) set(GENCMPCLIENT_VERSION ${GENCMPCLIENT_VERSION_MAJOR}.${GENCMPCLIENT_VERSION_MINOR}) endif() message(STATUS "generic CMP client version " ${GENCMPCLIENT_VERSION}) +message(STATUS "Building STATIC library") # set(CMAKE_VERBOSE_MAKEFILE ON) # set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # needed for sonarCloud scanner when using CMake @@ -233,7 +234,6 @@ add_compile_definitions(PEDANTIC) if(MSVC) # MSVC compiler flags add_compile_options(/W4) # High warning level - add_compile_options(/wd4996) # Disable deprecated function warnings add_compile_definitions(_CRT_SECURE_NO_WARNINGS) else() # GCC/Clang compiler flags @@ -243,7 +243,7 @@ else() -Wsign-compare -Wformat -Wtype-limits -Wundef -Wconversion -Wunused-parameter) add_compile_options(-Wno-c99-extensions -Wno-language-extension-token -Wno-declaration-after-statement -Wno-expansion-to-defined) if(NOT DEFINED GENCMP_NO_SECUTILS) - add_compile_options(-Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-shadow) + message(FATAL_ERROR "Windows build is not (yet) supported for libSecUtils") endif() endif() # TODO maybe clean up code and re-enable property @@ -253,7 +253,7 @@ endif() # target_compile_features(${LIBGENCMP_NAME} PRIVATE c_std_90) # target_compile_features(cmpClient PRIVATE c_std_90) -add_library(${LIBGENCMP_NAME} SHARED +add_library(${LIBGENCMP_NAME} STATIC "${PROJECT_SOURCE_DIR}/.github/workflows/build.yml" ${SRC_DIR}/genericCMPClient.c ) diff --git a/src/genericCMPClient_util.c b/src/genericCMPClient_util.c index 446e10c1..484d68bb 100644 --- a/src/genericCMPClient_util.c +++ b/src/genericCMPClient_util.c @@ -57,13 +57,13 @@ void UTIL_cleanse_free(OPTIONAL char *str) #include #endif -static const char *const GENCMP_NAME = "genCMPClient"; +#define GENCMP_NAME "genCMPClient" #define loc_len 256 /*!< these variables are shared between threads */ static LOG_cb_t LOG_fn = 0; -static const char *app_name = "genCMPClient"; -static severity verbosity = 4; /* LOG_WARNING equivalent */ +static const char *app_name = GENCMP_NAME; +static severity verbosity = LOG_WARNING; /* LOG_WARNING equivalent */ BIO *bio_err = 0; BIO *bio_trace = 0; From 443b63fbffbeeb5caaee81de97dafe052e578a64 Mon Sep 17 00:00:00 2001 From: reshmadev12 <141902375+reshmadev12@users.noreply.github.com> Date: Sun, 1 Feb 2026 23:12:34 +0530 Subject: [PATCH 5/5] Reworked on review comments --- CMakeLists.txt | 20 +++++++++++++++----- README.md | 29 +++++++++++++++++++++++++++++ src/genericCMPClient_util.c | 2 +- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a45120b7..98472c7a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,16 @@ if(NOT DEFINED GENCMPCLIENT_VERSION) set(GENCMPCLIENT_VERSION ${GENCMPCLIENT_VERSION_MAJOR}.${GENCMPCLIENT_VERSION_MINOR}) endif() message(STATUS "generic CMP client version " ${GENCMPCLIENT_VERSION}) -message(STATUS "Building STATIC library") + +# Option to build shared or static library (default: SHARED) +option(BUILD_STATIC_LIBS "Build static libraries instead of shared" OFF) +if(BUILD_STATIC_LIBS) + set(GENCMP_LIB_TYPE STATIC) + message(STATUS "Building STATIC library") +else() + set(GENCMP_LIB_TYPE SHARED) + message(STATUS "Building SHARED library") +endif() # set(CMAKE_VERBOSE_MAKEFILE ON) # set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # needed for sonarCloud scanner when using CMake @@ -235,6 +244,9 @@ if(MSVC) # MSVC compiler flags add_compile_options(/W4) # High warning level add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + if(NOT DEFINED GENCMP_NO_SECUTILS) + message(FATAL_ERROR "Windows build is not (yet) supported for libSecUtils") + endif() else() # GCC/Clang compiler flags add_compile_options(-pedantic) # -Werror is enabled only for development and CI, using Makefile_v1 without NDEBUG @@ -242,9 +254,7 @@ else() -Wall -Woverflow -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wswitch -Wsign-compare -Wformat -Wtype-limits -Wundef -Wconversion -Wunused-parameter) add_compile_options(-Wno-c99-extensions -Wno-language-extension-token -Wno-declaration-after-statement -Wno-expansion-to-defined) - if(NOT DEFINED GENCMP_NO_SECUTILS) - message(FATAL_ERROR "Windows build is not (yet) supported for libSecUtils") - endif() + endif() # TODO maybe clean up code and re-enable property # set_property(TARGET ${LIBGENCMP_NAME} PROPERTY C_STANDARD 90) @@ -253,7 +263,7 @@ endif() # target_compile_features(${LIBGENCMP_NAME} PRIVATE c_std_90) # target_compile_features(cmpClient PRIVATE c_std_90) -add_library(${LIBGENCMP_NAME} STATIC +add_library(${LIBGENCMP_NAME} ${GENCMP_LIB_TYPE} "${PROJECT_SOURCE_DIR}/.github/workflows/build.yml" ${SRC_DIR}/genericCMPClient.c ) diff --git a/README.md b/README.md index 70a73acd..1b69902e 100644 --- a/README.md +++ b/README.md @@ -453,6 +453,35 @@ It is also possible to statically link with `libcmp.a`, by setting `STATIC_LIBCM For further details on optional environment variables, see the [`Makefile_v1`](Makefile_v1) and [`Makefile_src`](Makefile_src). +### Choosing between shared and static library + +When using CMake, by default a **shared library** (`.so` on Linux, `.dylib` on macOS, `.dll` on Windows) is built. + +To build a **static library** instead (`.a` on Linux/macOS, `.lib` on Windows), use the CMake option `-DBUILD_STATIC_LIBS=ON`: + +```bash +cmake -DBUILD_STATIC_LIBS=ON . +make +``` + +This will produce a static library (`libgencmp.a` or `gencmp.lib`) instead of a shared library. + +#### Examples: + +**Building shared library (default):** +```bash +cmake . +make +# Produces: libgencmp.so.2.0 (Linux), libgencmp.dylib (macOS), or gencmp.dll (Windows) +``` + +**Building static library:** +```bash +cmake -DBUILD_STATIC_LIBS=ON . +make +# Produces: libgencmp.a (Linux/macOS) or gencmp.lib (Windows) +``` + ## Building Build the software with diff --git a/src/genericCMPClient_util.c b/src/genericCMPClient_util.c index 484d68bb..80dd452f 100644 --- a/src/genericCMPClient_util.c +++ b/src/genericCMPClient_util.c @@ -63,7 +63,7 @@ void UTIL_cleanse_free(OPTIONAL char *str) /*!< these variables are shared between threads */ static LOG_cb_t LOG_fn = 0; static const char *app_name = GENCMP_NAME; -static severity verbosity = LOG_WARNING; /* LOG_WARNING equivalent */ +static severity verbosity = LOG_WARNING; BIO *bio_err = 0; BIO *bio_trace = 0;