From 969fd6f15f80e8090f4a1fc119c0fa638c625858 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 24 Feb 2023 07:25:00 +0100 Subject: [PATCH 1/4] Add -lcrypto library to link against Otherwise one gets quite some undefined references... --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7c7196..edad65c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ endif() if(OPENSSL_FOUND) add_definitions(-DHAVE_OPENSSL) target_link_libraries(redfish ${OPENSSL_SSL_LIBRARY}) + target_link_libraries(redfish ${OPENSSL_CRYPTO_LIBRARY}) endif() From d394c5bae0d2ea6913b223668d46cc6c55ece603 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 24 Feb 2023 07:28:13 +0100 Subject: [PATCH 2/4] Add pthread to be linked against For some reason this was not needed when I built in latest Tumbleweed env. It seems as if phtread code moved into glibc or something more general, but this helped to build against Leap 15.4 and Tumbleweed still built successfully. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index edad65c..4da627c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ find_package(Jansson REQUIRED) find_package(CZMQ) find_package(OpenSSL) find_package(Readline) +find_package(Threads) include_directories(${CURL_INCLUDE_DIR}) include_directories(${JANSSON_INCLUDE_DIRS}) @@ -70,6 +71,9 @@ if(OPENSSL_FOUND) target_link_libraries(redfish ${OPENSSL_CRYPTO_LIBRARY}) endif() +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG ON) +target_link_libraries(redfish Threads::Threads) add_executable(redfishtest "${CMAKE_CURRENT_SOURCE_DIR}/examples/test.c") target_link_libraries(redfishtest redfish) From f346c7997c63a8cd91f71b01599c29f18b3ffab6 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 24 Feb 2023 07:30:38 +0100 Subject: [PATCH 3/4] Make use of standard variables for installation otherwise %cmake rpm macros will not be able to install things to the right places. --- CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4da627c..b24c5a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,16 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +if(NOT DEFINED INCLUDE_INSTALL_DIR) + set(INCLUDE_INSTALL_DIR include) +endif() +if(NOT DEFINED CMAKE_INSTALL_BINDIR) + set(CMAKE_INSTALL_BINDIR bin) +endif() +if(NOT DEFINED CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR lib) +endif() + set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") @@ -97,10 +107,10 @@ if(CZMQ_FOUND) endif() install(TARGETS redfishtest redfish - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib) -install(FILES ${REDFISH_HDR_PUBLIC_RED} DESTINATION include) -install(FILES ${REDFISH_HDR_PUBLIC_ENTITIES} DESTINATION include/entities) + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") +install(FILES ${REDFISH_HDR_PUBLIC_RED} DESTINATION "${INCLUDE_INSTALL_DIR}") +install(FILES ${REDFISH_HDR_PUBLIC_ENTITIES} DESTINATION "${INCLUDE_INSTALL_DIR}/entities") ENABLE_TESTING() From 9ac1e419bad864b24d919b7d9e125df41a9eb456 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 24 Feb 2023 07:35:03 +0100 Subject: [PATCH 4/4] Add configure_file and pkg-config template This will generate a libredfish.pc file that can/should be placed to (in openSUSE at least): /usr/lib64/pkgconfig So that Linux systems making use of pkg-config are aware of libredfish library --- CMakeLists.txt | 2 ++ libredfish.pc.in | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 libredfish.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b24c5a0..2f61e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,3 +138,5 @@ elseif(MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LIBPATH:.. /LIBPATH:../curl/lib") endif() endif() + +configure_file(libredfish.pc.in libredfish.pc @ONLY) diff --git a/libredfish.pc.in b/libredfish.pc.in new file mode 100644 index 0000000..0690f26 --- /dev/null +++ b/libredfish.pc.in @@ -0,0 +1,19 @@ +# this template is filled-in by CMake `configure_file(... @ONLY)` +# the `@....@` are filled in by CMake configure_file(), +# from variables set in your CMakeLists.txt or by CMake itself +# +# Good tutoral for understanding .pc files: +# https://people.freedesktop.org/~dbn/pkg-config-guide.html + +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix="@CMAKE_INSTALL_BINDIR@ +libdir="@CMAKE_INSTALL_LIBDIR@" +includedir="@INCLUDE_INSTALL_DIR@" + +Name: @PROJECT_NAME@ +Description: Redfish library +URL: https://github.com/DMTF/libredfish +Version: @LIBREDFISH_VERSION_STRING@ +Requires: @pc_req_public@ +Cflags: -I"${includedir}" +Libs: -L"${libdir}" -lredfish