diff --git a/.github/workflows/pikiwidb.yml b/.github/workflows/pikiwidb.yml index ce822fcff..97441c5fe 100644 --- a/.github/workflows/pikiwidb.yml +++ b/.github/workflows/pikiwidb.yml @@ -13,4 +13,26 @@ jobs: - name: Build run: | - sh build.sh \ No newline at end of file + sh build.sh + + - name: GTest + working-directory: ${{ github.workspace }}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest + + build_on_ubuntu: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build + run: | + bash build.sh + + - name: GTest + working-directory: ${{ github.workspace }}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c6ada246d..f46a87f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux") set(CMAKE_THREAD_LIBS_INIT "-lpthread") ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") - SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl") + SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl -Wno-restrict") ENDIF () ADD_DEFINITIONS(-DOS_LINUX) ELSE () diff --git a/build.sh b/build.sh index cbe0e124d..102f35325 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,71 @@ #!/bin/bash +#color code +C_RED="\033[31m" +C_GREEN="\033[32m" + +C_END="\033[0m" + BUILD_TIME=$(git log -1 --format=%ai) BUILD_TIME=${BUILD_TIME: 0: 10} COMMIT_ID=$(git rev-parse HEAD) SHORT_COMMIT_ID=${COMMIT_ID: 0: 8} +BUILD_TYPE=release +VERBOSE=0 +CMAKE_FLAGS="" +MAKE_FLAGS="" +PREFIX="build" + +ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"` +function show_help() { + echo " + -h --help show help + --debug compile with debug + --verbose compile with verbose + --prefix compile output path + " + exit 0 +} + +eval set -- "${ARGS}" +while true +do + case "$1" in + -h|--help) + show_help + ;; + --debug) + BUILD_TYPE=debug + ;; + --verbose) + CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" + MAKE_FLAGS="${MAKE_FLAGS} VERBOSE=1" + ;; + --prefix) + PREFIX=$2 + shift + ;; + --) + shift + break + ;; + esac +shift +done + +if [ ! -f "/proc/cpuinfo" ];then + CPU_CORE=$(sysctl -n hw.ncpu) +else + CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l) +fi +if [ ${CPU_CORE} -eq 0 ]; then + CPU_CORE=1 +fi + +echo "cpu core ${CPU_CORE}" + if [ -z "$SHORT_COMMIT_ID" ]; then echo "no git commit id" SHORT_COMMIT_ID="pikiwidb" @@ -14,5 +74,16 @@ fi echo "BUILD_TIME:" $BUILD_TIME echo "COMMIT_ID:" $SHORT_COMMIT_ID -cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build -cmake --build build -- -j 32 +echo "BUILD_TYPE:" $BUILD_TYPE +echo "CMAKE_FLAGS:" $CMAKE_FLAGS +echo "MAKE_FLAGS:" $MAKE_FLAGS + +cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID ${CMAKE_FLAGS} -S . -B ${PREFIX} +cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE} + +if [ $? -eq 0 ]; then + echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}" +else + echo -e "${C_RED} pika compile fail ${C_END}" + exit 1 +fi diff --git a/cmake/double-conversion.cmake b/cmake/double-conversion.cmake index c14726f13..88b69768e 100644 --- a/cmake/double-conversion.cmake +++ b/cmake/double-conversion.cmake @@ -11,5 +11,6 @@ FetchContent_DeclareGitHubWithMirror(double-conversion google/double-conversion v3.3.0 SHA256=4080014235f90854ffade6d1c423940b314bbca273a338235f049da296e47183 ) - -FetchContent_MakeAvailableWithArgs(double-conversion) +FetchContent_MakeAvailableWithArgs(double-conversion + BUILD_TESTING=OFF +) diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake index b069674d9..410b1b067 100644 --- a/cmake/gflags.cmake +++ b/cmake/gflags.cmake @@ -18,6 +18,7 @@ FetchContent_MakeAvailableWithArgs(gflags BUILD_SHARED_LIBS=OFF BUILD_gflags_LIB=ON BUILD_gflags_nothreads_LIB=OFF + BUILD_TESTING=OFF ) find_package(Threads REQUIRED) diff --git a/cmake/glog.cmake b/cmake/glog.cmake index b6a8497e4..fbbde6fe9 100644 --- a/cmake/glog.cmake +++ b/cmake/glog.cmake @@ -16,7 +16,7 @@ FetchContent_Declare(glog FetchContent_MakeAvailableWithArgs(glog CMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake/modules/glog WITH_GFLAGS=ON - WITH_GTEST=OFF + BUILD_TESTING=OFF BUILD_SHARED_LIBS=OFF WITH_UNWIND=ON ) diff --git a/src/pstd/tests/CMakeLists.txt b/src/pstd/tests/CMakeLists.txt index e78536cec..0320de8a5 100644 --- a/src/pstd/tests/CMakeLists.txt +++ b/src/pstd/tests/CMakeLists.txt @@ -16,7 +16,7 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE}) get_filename_component(pstd_test_filename ${pstd_test_source} NAME) string(REPLACE ".cc" "" pstd_test_name ${pstd_test_filename}) - set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) add_executable(${pstd_test_name} ${pstd_test_source}) target_include_directories(${pstd_test_name} PUBLIC ${PROJECT_SOURCE_DIR}/src @@ -27,6 +27,5 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE}) PUBLIC pstd PUBLIC gtest ) - gtest_discover_tests(${pstd_test_name} - WORKING_DIRECTORY .) + gtest_discover_tests(${pstd_test_name}) endforeach ()