From cdf31c145590433a64ee7bf3be46131d56469c5f Mon Sep 17 00:00:00 2001 From: holmes1412 Date: Mon, 17 Apr 2023 21:45:03 +0800 Subject: [PATCH 1/2] cmake : Add checking Gtest_VERSION for cmake 3.26.0; Use static link for macOS; --- GNUmakefile | 1 + benchmark/CMakeLists.txt | 19 ++++++------------- benchmark/GNUmakefile | 8 ++++---- test/CMakeLists.txt | 41 +++++++++++++++++++++++++--------------- tutorial/CMakeLists.txt | 22 ++++++--------------- 5 files changed, 43 insertions(+), 48 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index dc07abfa..1c428514 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -50,6 +50,7 @@ ifeq ("$(WORKFLOW)","Found") endif -make -C test clean -make -C tutorial clean + -make -C benchmark clean rm -rf $(DEFAULT_BUILD_DIR) rm -rf _include rm -rf _lib diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index ddf72196..78fa0684 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -41,17 +41,6 @@ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/workflow/workflow-config.cmake.in") find_package(Workflow REQUIRED CONFIG HINTS ../workflow) endif () -#if (APPLE) -# if (WORKFLOW_INCLUDE_DIR) -# set (WORKFLOW_INCLUDE_DIR ${Workflow_DIR}/_include) -# set (WORKFLOW_LIB_DIR ${Workflow_DIR}/_lib) -# else () -# find_package(Workflow REQUIRED) -# endif () -#else () -# find_package(Workflow REQUIRED) -#endif() - find_package(srpc REQUIRED CONFIG HINTS ..) include_directories( ${OPENSSL_INCLUDE_DIR} @@ -88,9 +77,13 @@ else () endif () if (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES}) + find_library(Workflow_LIB workflow HINTS ../workflow/_lib) + find_library(Srpc_LIB srpc HINTS ../_lib) + set(SRPC_LIB - srpc - workflow + ${Srpc_LIB} + ${Workflow_LIB} pthread OpenSSL::SSL OpenSSL::Crypto diff --git a/benchmark/GNUmakefile b/benchmark/GNUmakefile index 1cabeabe..032621a7 100644 --- a/benchmark/GNUmakefile +++ b/benchmark/GNUmakefile @@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ALL_TARGETS := all clean MAKE_FILE := Makefile -DEFAULT_BUILD_DIR := build +DEFAULT_BUILD_DIR := build.cmake BUILD_DIR := $(shell if [ -f $(MAKE_FILE) ]; then echo "."; else echo $(DEFAULT_BUILD_DIR); fi) CMAKE3 := $(shell if which cmake3>/dev/null ; then echo cmake3; else echo cmake; fi;) @@ -22,9 +22,9 @@ endif clean: ifeq ($(MAKE_FILE), $(wildcard $(MAKE_FILE))) -make -f Makefile clean -else ifeq (build, $(wildcard build)) - -make -C build clean +else ifeq ($(DEFAULT_BUILD_DIR), $(wildcard $(DEFAULT_BUILD_DIR))) + -make -C $(DEFAULT_BUILD_DIR) clean endif - rm -rf build + rm -rf $(DEFAULT_BUILD_DIR) #g++ -o thrift_server thrift_server.cc gen-cpp/*.cpp -O2 -g -lthrift -lthriftnb -levent -lpthread -std=c++11 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c59df2de..38ba53c0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,17 +38,6 @@ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/workflow/workflow-config.cmake.in") find_package(Workflow REQUIRED CONFIG HINTS ../workflow) endif () -#if (APPLE) -# if (WORKFLOW_INCLUDE_DIR) -# set (WORKFLOW_INCLUDE_DIR ${Workflow_DIR}/_include) -# set (WORKFLOW_LIB_DIR ${Workflow_DIR}/_lib) -# else () -# find_package(Workflow REQUIRED) -# endif () -#else () -# find_package(Workflow REQUIRED) -#endif() - include_directories( ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} @@ -72,18 +61,36 @@ set(memcheck_command ${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OP add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) enable_testing() + if (WIN32) find_package(GTest CONFIG REQUIRED) else () find_package(GTest REQUIRED) endif () +set(CXX_STD "c++11") +if (GTest_VERSION VERSION_GREATER_EQUAL "1.13.0") + set(CXX_STD "c++14") +else () + get_filename_component(GTEST_PATH ${GTEST_LIBRARY} DIRECTORY ABSOLUTE) + execute_process(COMMAND grep Version "${GTEST_PATH}/pkgconfig/gtest.pc" + RESULT_VARIABLE GTEST_VERSION_RESULT + OUTPUT_VARIABLE GTEST_VERSION_OUTPUT) + if (${GTEST_VERSION_RESULT} EQUAL "0") + string(REPLACE " " ";" GTEST_VERSION_STR ${GTEST_VERSION_OUTPUT}) + list(GET GTEST_VERSION_STR 1 GTEST_VERSION) + if (${GTEST_VERSION} VERSION_GREATER_EQUAL "1.13.0") + set(CXX_STD "c++14") + endif () + endif () +endif () + if (WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /wd4200") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /wd4200 /Zc:__cplusplus /std:c++14") else () set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC -pipe -std=gnu90") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC -pipe -std=c++11 -fno-exceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC -pipe -std=${CXX_STD} -fno-exceptions") endif () set(TEST_LIST @@ -102,9 +109,13 @@ add_custom_target( set(GTEST_LIB GTest::GTest GTest::Main) if (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES}) + find_library(Workflow_LIB workflow HINTS ../workflow/_lib) + find_library(Srpc_LIB srpc HINTS ../_lib) + set(SRPC_LIB - srpc - workflow + ${Srpc_LIB} + ${Workflow_LIB} pthread OpenSSL::SSL OpenSSL::Crypto @@ -157,7 +168,7 @@ endforeach() if (WIN32) set(memcheck nothing) -else () +elseif (NOT ${CMAKE_MEMORYCHECK_COMMAND} STREQUAL "CMAKE_MEMORYCHECK_COMMAND-NOTFOUND") foreach(src ${TEST_LIST}) add_test(${src}-memory-check ${memcheck_command} ./${src}) endforeach() diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index af9db366..c73e96dd 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -56,17 +56,6 @@ endif () find_package(ZLIB REQUIRED) -#if (APPLE) -# if (WORKFLOW_INCLUDE_DIR) -# set (WORKFLOW_INCLUDE_DIR ${Workflow_DIR}/_include) -# set (WORKFLOW_LIB_DIR ${Workflow_DIR}/_lib) -# else () -# find_package(Workflow REQUIRED) -# endif () -#else () -# find_package(Workflow REQUIRED) -#endif() - include_directories( ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} @@ -75,8 +64,6 @@ include_directories( ${SRPC_INCLUDE_DIR} ) - - if (WIN32) link_directories(${SRPC_LIB_DIR} ${WORKFLOW_LIB_DIR} ${Protobuf_LIB_DIR}) set(SRPC_GEN_PROGRAM ${SRPC_BIN_DIR}/Debug/srpc_generator.exe) @@ -97,7 +84,6 @@ add_custom_target( COMMENT "srpc generator..." ) - if (WIN32) if (SRPC_TUTORIAL_BUILD_STATIC_RUNTIME) set(CompilerFlags @@ -136,9 +122,13 @@ set(TUTORIAL_PB_LIST ) if (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES}) + find_library(Workflow_LIB workflow HINTS ../workflow/_lib) + find_library(Srpc_LIB srpc HINTS ../_lib) + set(SRPC_LIB - srpc - workflow + ${Srpc_LIB} + ${Workflow_LIB} pthread OpenSSL::SSL OpenSSL::Crypto From e5c6252db321a781078b089af1166cfb9fa247ac Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Tue, 18 Apr 2023 07:33:17 +0300 Subject: [PATCH 2/2] Add test on Fedora rawhide --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74abf8ba..c78e7ee0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,3 +30,34 @@ jobs: - name: make install run: sudo make install + test: + name: fedora + runs-on: ubuntu-latest + + steps: + - name: Setup Podman + run: | + sudo apt update + sudo apt-get -y install podman + podman pull fedora:rawhide + - name: Get source + uses: actions/checkout@v3 + with: + path: 'workflow' + - name: Create container and run tests + run: | + { + echo 'FROM fedora:rawhide' + echo 'RUN dnf -y update' + echo 'RUN dnf -y install cmake gcc-c++ gtest-devel make' + echo 'RUN dnf -y install openssl-devel protobuf-devel' + echo 'RUN dnf -y install lz4-devel snappy-devel workflow-devel' + echo 'RUN dnf clean all' + echo 'COPY workflow workflow' + echo 'WORKDIR /workflow' + echo "RUN cmake" + echo "RUN make" + echo "RUN make check" + echo "RUN make tutorial" + } > podmanfile + podman build --tag fedorarawhide -f ./podmanfile