From 3e1631c8f0c1eed2ed332f0de44d46fba02c8e5b Mon Sep 17 00:00:00 2001 From: Muggle Wei Date: Wed, 6 Dec 2023 22:49:59 +0800 Subject: [PATCH 1/4] update deps/mugglec version --- CMakeLists.txt | 10 +- build.sh | 7 +- dep_modules/mugglec.yml | 2 +- patch_scripts/mugglec_cmakelist.txt | 653 ---------------------------- 4 files changed, 8 insertions(+), 664 deletions(-) delete mode 100644 patch_scripts/mugglec_cmakelist.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c559497..e43349e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,13 +10,15 @@ message("-- use c++ compiler ${CMAKE_CXX_COMPILER}") # set compile parameter if (${CMAKE_C_COMPILER_ID} STREQUAL GNU) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -Wall -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") elseif (${CMAKE_C_COMPILER_ID} MATCHES Clang) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-missing-field-initializers") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") elseif (${CMAKE_C_COMPILER_ID} STREQUAL MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS=1 -D_UNICODE -DUNICODE) + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") endif() # set standard and print features diff --git a/build.sh b/build.sh index 0bc049c..e0e3fc9 100755 --- a/build.sh +++ b/build.sh @@ -71,7 +71,7 @@ if [ $build_mugglec -eq 1 ]; then cd $dep_dir mugglec_git=https://github.com/MuggleWei/mugglec.git - mugglec_tag=v1.3.2 + mugglec_tag=v1.4.3 mugglec_name=mugglec-$mugglec_tag mugglec_src_dir=$dep_dir/$mugglec_name mugglec_build_dir=$build_dir/_deps/mugglec @@ -86,11 +86,6 @@ if [ $build_mugglec -eq 1 ]; then fi cd $mugglec_build_dir - # patch for mac - if [[ "$OSTYPE" == "darwin"* ]]; then - cp $origin_dir/patch_scripts/mugglec_cmakelist.txt $mugglec_src_dir/CMakeLists.txt - fi - cmake \ -S $mugglec_src_dir -B $mugglec_build_dir \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ diff --git a/dep_modules/mugglec.yml b/dep_modules/mugglec.yml index 4bc5e37..37d34a5 100644 --- a/dep_modules/mugglec.yml +++ b/dep_modules/mugglec.yml @@ -1,7 +1,7 @@ name: mugglec variables: - build_type: release - - mugglec_tag: v1.3.5 + - mugglec_tag: v1.4.3 - mugglec_url: https://github.com/MuggleWei/mugglec.git source: maintainer: mugglewei diff --git a/patch_scripts/mugglec_cmakelist.txt b/patch_scripts/mugglec_cmakelist.txt deleted file mode 100644 index b1b64a9..0000000 --- a/patch_scripts/mugglec_cmakelist.txt +++ /dev/null @@ -1,653 +0,0 @@ -cmake_minimum_required (VERSION 3.18.6) -project(mugglec) - -################################ -# general config -################################ - -# print compiler -message("-- use c compiler ${CMAKE_C_COMPILER}") -message("-- use c++ compiler ${CMAKE_CXX_COMPILER}") - -# set compile parameter -if (${CMAKE_C_COMPILER_ID} STREQUAL GNU) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -Wall -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra") -elseif (${CMAKE_C_COMPILER_ID} MATCHES Clang) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-missing-field-initializers") -elseif (${CMAKE_C_COMPILER_ID} STREQUAL MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS=1 -D_UNICODE -DUNICODE) - add_compile_options("$<$:/utf-8>") - add_compile_options("$<$:/utf-8>") -endif() - -# set standard and print features -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) - -message("-- c compiler support features: ") -foreach(feature ${CMAKE_C_COMPILE_FEATURES}) - message("support feature: ${feature}") -endforeach() - -# set output directory -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -# for vim plugin - YCM -if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -endif() - -# set use folder in vs -set_property(GLOBAL PROPERTY USE_FOLDERS ON) - -################################ -# include cmake -################################ - -# cmake -include(${CMAKE_CURRENT_LIST_DIR}/cmake/muggle_utils.cmake) - -################################ -# options -################################ - -option(BUILD_SHARED_LIBS "Build shared or static library" ON) -option(BUILD_TESTING "Build testing" OFF) - -option(MUGGLE_BUILD_STATIC_PIC "build static library with position independent code flag" ON) -option(MUGGLE_BUILD_EXAMPLE "Build mugglec example" OFF) -option(MUGGLE_BUILD_BENCHMARK "Build mugglec benchmark" OFF) -option(MUGGLE_BUILD_TRACE "If build type is debug then build with trace info in source codes" OFF) -option(MUGGLE_BUILD_SANITIZER "Compile mugglec with sanitizer" OFF) -option(MUGGLE_INSTALL_BIN "Install example, unittest and benchmark binaries" OFF) -# option(MUGGLE_CRYPT_OPTIMIZATION "Enable crypt optimization(use source codes extract from openssl)" ON) -set(MUGGLE_CRYPT_OPTIMIZATION ON) -# option(MUGGLE_CRYPT_COMPARE_OPENSSL "Link openssl in unittest for compare result" OFF) -set(MUGGLE_CRYPT_COMPARE_OPENSSL ON) -set(MUGGLE_BUILD_WITH_COV OFF) -set(MUGGLE_TEST_LINK_OPENSSL OFF) - -if (BUILD_SHARED_LIBS) - set(MUGGLE_LIB_TYPE SHARED) - set(MUGGLE_C_USE_DLL ON) -else() - set(MUGGLE_LIB_TYPE STATIC) - set(MUGGLE_C_USE_DLL OFF) -endif() - -################################ -# coverage -################################ - -if (${CMAKE_BUILD_TYPE} MATCHES "[Cc]overage") - set(BUILD_TESTING ON) - - if (${CMAKE_C_COMPILER_ID} MATCHES Clang) - message("-- CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}, set MUGGLE_BUILD_WITH_COV ON") - set(MUGGLE_BUILD_WITH_COV ON) - set(COVERAGE_COMPILER_FLAGS "-fprofile-instr-generate -fcoverage-mapping") - elseif(${CMAKE_C_COMPILER_ID} STREQUAL GNU) - message("-- CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE} and find gcov in ${GCOV_PATH}, set MUGGLE_BUILD_WITH_COV ON") - set(MUGGLE_BUILD_WITH_COV ON) - set(COVERAGE_COMPILER_FLAGS "--coverage") - else() - message("-- Use compiler ${CMAKE_C_COMPILER_ID}, set MUGGLE_BUILD_WITH_COV OFF") - set(MUGGLE_BUILD_WITH_COV OFF) - endif() -else() - message("-- CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}, set MUGGLE_BUILD_WITH_COV OFF") - set(MUGGLE_BUILD_WITH_COV OFF) -endif() - -if (MUGGLE_BUILD_WITH_COV) - message("-- muggle build with cov, add compiler flags: ${COVERAGE_COMPILER_FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}") -endif() - -if (MUGGLE_BUILD_WITH_COV) - if (${CMAKE_C_COMPILER_ID} MATCHES Clang) - find_program(LLVM_PROFDATA llvm-profdata) - find_program(LLVM_COV_PATH llvm-cov) - if (LLVM_PROFDATA AND LLVM_COV_PATH) - set(COV_OUT_NAME mugglec_coverage) - add_custom_target( - coverage - COMMAND echo "run converage" - COMMAND rm -rf ${COV_OUT_NAME} - COMMAND rm -rf mugglec-*profraw - COMMAND rm -rf mugglec.profdata - COMMAND LLVM_PROFILE_FILE=mugglec-%m.profraw make test - COMMAND ${LLVM_PROFDATA} merge mugglec-*.profraw -o mugglec.profdata - COMMAND ${LLVM_COV_PATH} report ./lib/libmugglec.* -instr-profile=mugglec.profdata - COMMAND ${LLVM_COV_PATH} show ./lib/libmugglec.* -instr-profile=mugglec.profdata -output-dir=${COV_OUT_NAME} -format=html - ) - else() - message(SEND_ERROR "failed generate coverage report, llvm-profdata or llvm-cov not found") - endif() - elseif(${CMAKE_C_COMPILER_ID} STREQUAL GNU) - find_program(LCOV_PATH lcov) - find_program(GENHTML_PATH genhtml) - if (LCOV_PATH AND GENHTML_PATH) - set(COV_OUT_NAME mugglec_coverage) - set(COV_DIR ./CMakeFiles/mugglec.dir) - add_custom_target( - coverage - COMMAND echo "run converage" - COMMAND rm -rf ${COV_OUT_NAME}.info ${COV_OUT_NAME} - COMMAND ${LCOV_PATH} --zerocounters -d ${COV_DIR} - COMMAND rm -rf ${COV_OUT_NAME} ${COV_OUT_NAME}.info - COMMAND make test - COMMAND ${LCOV_PATH} -d ${COV_DIR} -c -o ${COV_OUT_NAME}.info - COMMAND ${GENHTML_PATH} ${COV_OUT_NAME}.info -o ${COV_OUT_NAME} - ) - else() - message(SEND_ERROR "failed generate coverage report, lcov or genhtml not found") - endif() - endif() -endif() - -################################ -# version -################################ - -# NTOE: don't use READ, it will add newline -#file(READ "version.txt" mugglec_version) -file(STRINGS "version.txt" mugglec_version) - -string(REPLACE "-" ";" mugglec_semver_ext ${mugglec_version}) -list(GET mugglec_semver_ext 0 mugglec_semver) -string(REPLACE "." ";" mugglec_semver_list ${mugglec_semver}) - -list(GET mugglec_semver_list 0 MUGGLE_C_VER_MAJOR) -list(GET mugglec_semver_list 1 MUGGLE_C_VER_MINOR) -list(GET mugglec_semver_list 2 MUGGLE_C_VER_PATCH) - -set(MUGGLE_C_VERSION "${mugglec_version}") -set(MUGGLE_C_SOVERSION "${MUGGLE_C_VER_MAJOR}") - -################################ -# output options -################################ - -message("-- c compiler flags: ${CMAKE_C_FLAGS}") -message("-- cxx compiler flags: ${CMAKE_CXX_FLAGS}") -message("-- mugglec version ${MUGGLE_C_VERSION}") - -message("-- mugglec option BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}") -message("-- mugglec option MUGGLE_BUILD_STATIC_PIC ${MUGGLE_BUILD_STATIC_PIC}") -message("-- mugglec option MUGGLE_BUILD_TRACE ${MUGGLE_BUILD_TRACE}") -message("-- mugglec option MUGGLE_BUILD_WITH_COV ${MUGGLE_BUILD_WITH_COV}") - -message("-- mugglec option BUILD_TESTING ${BUILD_TESTING}") -message("-- mugglec option MUGGLE_BUILD_EXAMPLE ${MUGGLE_BUILD_EXAMPLE}") -message("-- mugglec option MUGGLE_BUILD_BENCHMARK ${MUGGLE_BUILD_BENCHMARK}") - -message("-- mugglec option MUGGLE_CRYPT_OPTIMIZATION ${MUGGLE_CRYPT_OPTIMIZATION}") -message("-- mugglec option MUGGLE_CRYPT_COMPARE_OPENSSL ${MUGGLE_CRYPT_COMPARE_OPENSSL}") -message("-- mugglec option MUGGLE_INSTALL_BIN ${MUGGLE_INSTALL_BIN}") - -################################ -# configure -################################ - -# check support -include(CheckIncludeFile) -check_include_file(linux/futex.h MUGGLE_C_HAVE_LINUX_FUTEX) -check_include_file(sys/futex.h MUGGLE_C_HAVE_SYS_FUTEX) - -# detech endianness -include(TestBigEndian) -TEST_BIG_ENDIAN(IS_BIG_ENDIAN) # NOTE: big endian is 1, little endian is 0 -if (IS_BIG_ENDIAN) - set(MUGGLE_C_IS_BIG_ENDIAN 1) -else() - set(MUGGLE_C_IS_BIG_ENDIAN 0) -endif() - -if (CMAKE_HOST_UNIX) - find_package(Backtrace) - if (Backtrace_FOUND) - #message("Found Backtrace") - #message("Backtrace header: ${Backtrace_HEADER}") - #message("Backtrace libs: ${Backtrace_LIBRARIES}") - - set(MUGGLE_C_HAVE_BACKTRACE 1) - set(MUGGLE_C_BACKTRACE_HEADER ${Backtrace_HEADER}) - endif() -endif() - -set(mugglec_generated_dir ${CMAKE_CURRENT_BINARY_DIR}/generated) -configure_file( - "${CMAKE_CURRENT_LIST_DIR}/muggle/c/mugglec_config.h.in" - "${mugglec_generated_dir}/muggle/c/mugglec_config.h") - -################################ -# mugglec -################################ - -set(muggle_c mugglec) - -muggle_add_project(${muggle_c} ${CMAKE_CURRENT_LIST_DIR}/muggle ${MUGGLE_LIB_TYPE}) -target_include_directories(${muggle_c} PUBLIC - $ - $ - $) - -target_compile_definitions(${muggle_c} PRIVATE MUGGLE_C_EXPORTS) -set_target_properties(${muggle_c} PROPERTIES - LINKER_LANGUAGE C - VERSION ${MUGGLE_C_VERSION} - SOVERSION ${MUGGLE_C_SOVERSION} - DEBUG_POSTFIX d -) - -if ((NOT ${BUILD_SHARED_LIBS}) AND (${MUGGLE_BUILD_STATIC_PIC})) - set_target_properties(${muggle_c} PROPERTIES - POSITION_INDEPENDENT_CODE ON - ) -endif() - -# extra libraries -find_package(Threads) -if (Threads_FOUND) - message("-- mugglec link threads: ${CMAKE_THREAD_LIBS_INIT}") - target_link_libraries(${muggle_c} ${CMAKE_THREAD_LIBS_INIT}) -else() - message("Failed found threads") -endif() - -message("-- mugglec link dl libs: ${CMAKE_DL_LIBS}") -target_link_libraries(${muggle_c} ${CMAKE_DL_LIBS}) - -if (MSVC OR MINGW) - message("-- mugglec link sync: synchronization") - target_link_libraries(${muggle_c} synchronization) -endif() - -if (Backtrace_FOUND) - target_include_directories(${muggle_c} PRIVATE ${Backtrace_INCLUDE_DIRS}) - - message("-- mugglec link backtrace lib: ${Backtrace_LIBRARIES}") - target_link_libraries(${muggle_c} ${Backtrace_LIBRARIES}) -endif() - -if (MUGGLE_BUILD_TRACE) - if (MSVC OR MINGW) - message("-- mugglec link debug lib: debug Dbghelp") - target_link_libraries(${muggle_c} debug Dbghelp) - endif() -endif() - -if (MUGGLE_BUILD_SANITIZER) - if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR - (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) - target_compile_options(${muggle_c} PUBLIC - -fsanitize=undefined - -fsanitize=address - -fsanitize=leak) - target_link_options(${muggle_c} PUBLIC - -fsanitize=undefined - -fsanitize=address - -fsanitize=leak) - endif() -endif() - -# install -include(GNUInstallDirs) -install(TARGETS ${muggle_c} - EXPORT mugglecTargets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") -install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/muggle" "${mugglec_generated_dir}/muggle" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - FILES_MATCHING - PATTERN "*.h") - -# cmake package config -set(mugglec_export_dir "${CMAKE_INSTALL_LIBDIR}/cmake/mugglec") -install(EXPORT mugglecTargets - FILE mugglecTargets.cmake - DESTINATION ${mugglec_export_dir}) - -include(CMakePackageConfigHelpers) -configure_package_config_file( - "${CMAKE_CURRENT_LIST_DIR}/cmake/mugglecConfig.cmake.in" - "${mugglec_generated_dir}/mugglecConfig.cmake" - INSTALL_DESTINATION ${mugglec_export_dir} - NO_SET_AND_CHECK_MACRO - NO_CHECK_REQUIRED_COMPONENTS_MACRO) -write_basic_package_version_file( - "${mugglec_generated_dir}/mugglecConfigVersion.cmake" - VERSION ${MUGGLE_C_VERSION} - COMPATIBILITY SameMajorVersion) -install(FILES - "${mugglec_generated_dir}/mugglecConfig.cmake" - "${mugglec_generated_dir}/mugglecConfigVersion.cmake" - DESTINATION ${mugglec_export_dir}) - -# pkgconfig -configure_file( - "${CMAKE_CURRENT_LIST_DIR}/cmake/mugglec.pc.in" - "${mugglec_generated_dir}/mugglec.pc" @ONLY) -install(FILES - "${mugglec_generated_dir}/mugglec.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - -# cpack -include(InstallRequiredSystemLibraries) -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE") -set(CPACK_PACKAGE_VERSION_MAJOR ${MUGGLE_C_VER_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${MUGGLE_C_VER_MINOR}) -set(CPACK_PACKAGE_VERSION_PATCH ${MUGGLE_C_VER_PATCH}) -set(CPACK_PACKAGE_CONTACT "Muggle Wei ") -set(CPACK_SOURCE_GENERATOR "TGZ") -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/MuggleWei/mugglec") -include(CPack) - -################################ -# test & benchmark utils -################################ - -# test utils -if (${BUILD_TESTING}) - if (MUGGLE_CRYPT_COMPARE_OPENSSL) - find_package(OpenSSL 3 QUIET) - if (OPENSSL_FOUND) - message("-- Find openssl - for compare crypt result in unittest") - message("-- Openssl include dir: ${OPENSSL_INCLUDE_DIR}") - message("-- Openssl libraries: ${OPENSSL_LIBRARIES}") - set(MUGGLE_TEST_LINK_OPENSSL ON) - else() - message("-- Can't find Openssl, option MUGGLE_TEST_LINK_OPENSSL OFF") - endif() - endif() - - set(test_utils muggle_test_utils) - muggle_add_project(${test_utils} ${CMAKE_CURRENT_LIST_DIR}/test_utils SHARED) - add_dependencies(${test_utils} ${muggle_c}) - target_include_directories(${test_utils} PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ${mugglec_generated_dir}) -endif() - -# benchmark utils -if (${MUGGLE_BUILD_BENCHMARK}) - muggle_add_project(muggle_benchmark ${CMAKE_CURRENT_LIST_DIR}/muggle_benchmark ${MUGGLE_LIB_TYPE}) - set_target_properties(muggle_benchmark PROPERTIES - VERSION ${MUGGLE_C_VERSION} - SOVERSION ${MUGGLE_C_SOVERSION} - ) - set_target_properties(muggle_benchmark - PROPERTIES - DEBUG_POSTFIX d - ) - if ((NOT ${BUILD_SHARED_LIBS}) AND ${MUGGLE_BUILD_STATIC_PIC}) - set_target_properties(muggle_benchmark PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() - target_link_libraries(muggle_benchmark ${muggle_c}) - add_dependencies(muggle_benchmark ${muggle_c}) - - if (BUILD_SHARED_LIBS) - target_compile_definitions(muggle_benchmark - PUBLIC MUGGLE_BENCHMARK_USE_DLL - PRIVATE MUGGLE_BENCHMARK_EXPORTS - ) - endif() -endif() - -################################ -# functions -################################ - -# functions -function(add_example name folder) - message("add example ${name} ${folder}") - - set(name example_${name}) - - file(GLOB_RECURSE tmp_h ${folder}/*.h) - file(GLOB_RECURSE tmp_c ${folder}/*.c) - file(GLOB_RECURSE tmp_cpp ${folder}/*.cpp) - file(GLOB_RECURSE tmp_cc ${folder}/*.cc) - - if (MSVC OR MINGW) - add_executable(${name} ${tmp_h} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - set_target_properties(${name} - PROPERTIES - FOLDER "example" - VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)" - ) - else() - add_executable(${name} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - if (APPLE) - set_target_properties(${name} - PROPERTIES - INSTALL_RPATH "@executable_path/../lib" - ) - elseif (UNIX) - set_target_properties(${name} - PROPERTIES - INSTALL_RPATH "\$ORIGIN/../lib" - ) - endif() - endif(MSVC OR MINGW) - add_dependencies(${name} ${muggle_c}) - target_include_directories(${name} PUBLIC - ${folder} - ) - target_link_libraries(${name} ${muggle_c}) - - target_compile_definitions(${name} PRIVATE MUGGLE_HOLD_LOG_MACRO) - - if (MUGGLE_INSTALL_BIN) - install(TARGETS ${name} RUNTIME DESTINATION bin) - endif() -endfunction() - -function(add_benchmark name folder) - message("add benchmark ${name} ${folder}") - - set(name benchmark_${name}) - - file(GLOB tmp_h ${folder}/*.h) - file(GLOB tmp_c ${folder}/*.c) - file(GLOB tmp_cpp ${folder}/*.cpp) - file(GLOB tmp_cc ${folder}/*.cc) - - if (MSVC OR MINGW) - add_executable(${name} ${tmp_h} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - set_target_properties(${name} - PROPERTIES - FOLDER "benchmark" - VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)" - ) - else() - add_executable(${name} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - set_target_properties(${name} - PROPERTIES - INSTALL_RPATH "\$ORIGIN/../lib" - ) - endif(MSVC OR MINGW) - add_dependencies(${name} muggle_benchmark) - target_link_libraries(${name} muggle_benchmark) - target_compile_definitions(${name} PRIVATE MUGGLE_HOLD_LOG_MACRO) - - if (MUGGLE_INSTALL_BIN) - install(TARGETS ${name} RUNTIME DESTINATION bin) - endif() -endfunction() - -function(add_gtest name folder) - message("add test ${name} ${folder}") - - set(name test_${name}) - - file(GLOB tmp_h ${folder}/*.h) - file(GLOB tmp_c ${folder}/*.c) - file(GLOB tmp_cpp ${folder}/*.cpp) - file(GLOB tmp_cc ${folder}/*.cc) - - if (MSVC OR MINGW) - add_executable(${name} ${tmp_h} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - set_target_properties(${name} - PROPERTIES - FOLDER "test" - VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)" - ) - else() - add_executable(${name} ${tmp_c} ${tmp_cpp} ${tmp_cc}) - set_target_properties(${name} - PROPERTIES - INSTALL_RPATH "\$ORIGIN/../lib" - ) - endif(MSVC OR MINGW) - - add_dependencies(${name} ${muggle_c} ${test_utils}) - if (FOUND_GTEST_FROM_DOWNLOAD) - add_dependencies(${name} ${GTEST_BOTH_LIBRARIES}) - endif() - target_include_directories(${name} PUBLIC - ${GTEST_INCLUDE_DIRS} - ) - target_link_libraries(${name} - ${muggle_c} - ${test_utils} - ${GTEST_BOTH_LIBRARIES} - ) - - if (APPLE) - # NOTE: APPLE not support TIME_UTC until c11 or c++17 - set_target_properties(${name} PROPERTIES - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED ON - ) - else() - set_target_properties(${name} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED ON - ) - endif() - - # link openssl - if (MUGGLE_TEST_LINK_OPENSSL) - if (${name} MATCHES "^test_crypt*") - message("${name} link openssl") - target_link_libraries(${name} - ${OPENSSL_LIBRARIES} - ) - target_include_directories(${name} PUBLIC - ${OPENSSL_INCLUDE_DIR} - ) - target_compile_definitions(${name} - PRIVATE MUGGLE_TEST_LINK_OPENSSL - ) - endif() - endif() - - target_compile_definitions(${name} PRIVATE MUGGLE_HOLD_LOG_MACRO) - - add_test(NAME ${name} COMMAND ${name}) - - if (MUGGLE_INSTALL_BIN) - install(TARGETS ${name} RUNTIME DESTINATION bin) - endif() -endfunction() - -# test -if (BUILD_TESTING) - enable_testing() - - # search gtest first - find_package(GTest) - - if (GTEST_FOUND) - set(FOUND_GTEST_FROM_SEARCH ON) - - message("-- Find GTest - use gtest from search") - message("-- GTest include directories: ${GTEST_INCLUDE_DIRS}") - message("-- GTest both libraries: ${GTEST_BOTH_LIBRARIES}") - else() - # Download and unpack googletest at configure time - configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/googletest.cmake.in googletest-download/CMakeLists.txt) - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif() - - # Prevent overriding the parent project's compiler/linker - # settings on Windows - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL) - - # The gtest/gtest_main targets carry header search path - # dependencies automatically when using CMake 2.8.11 or - # later. Otherwise we have to add them here ourselves. - if (CMAKE_VERSION VERSION_LESS 2.8.11) - include_directories("${gtest_SOURCE_DIR}/include") - endif() - - # # Now simply link against gtest or gtest_main as needed. Eg - # add_executable(example src/test/example/example.cpp) - # target_link_libraries(example gtest_main) - # add_test(NAME example_test COMMAND example) - - set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include") - set(GTEST_BOTH_LIBRARIES gtest_main) - set(FOUND_GTEST_FROM_DOWNLOAD ON) - - message("-- Find GTest - use gtest from download") - endif() -endif() - -# example -if (${MUGGLE_BUILD_EXAMPLE}) - message("---------------------- examples ----------------------") - SUBDIRLIST(example_dirs ${CMAKE_CURRENT_LIST_DIR}/examples/src) - FOREACH(example_dir ${example_dirs}) - message("find example section directory: ${example_dir}") - SUBDIRLIST(sub_example_dirs ${CMAKE_CURRENT_LIST_DIR}/examples/src/${example_dir}) - FOREACH(sub_example_dir ${sub_example_dirs}) - add_example(${example_dir}_${sub_example_dir} - ${CMAKE_CURRENT_LIST_DIR}/examples/src/${example_dir}/${sub_example_dir}) - ENDFOREACH() - ENDFOREACH() -endif() - -# test -if (${BUILD_TESTING}) - message("---------------------- test ----------------------") - SUBDIRLIST(test_root_dir ${CMAKE_CURRENT_LIST_DIR}/test) - FOREACH(subdir ${test_root_dir}) - add_gtest(${subdir} ${CMAKE_CURRENT_LIST_DIR}/test/${subdir}) - ENDFOREACH() -endif() - -# benchmark -if (${MUGGLE_BUILD_BENCHMARK}) - message("---------------------- benchmark ----------------------") - SUBDIRLIST(benchmark_root_dir ${CMAKE_CURRENT_LIST_DIR}/benchmark) - FOREACH(subdir ${benchmark_root_dir}) - add_benchmark(${subdir} ${CMAKE_CURRENT_LIST_DIR}/benchmark/${subdir}) - ENDFOREACH() -endif() - -# coverage From 30ba0a7044d76016e718da493d6ee0562a7a8aa0 Mon Sep 17 00:00:00 2001 From: Muggle Wei Date: Thu, 7 Dec 2023 01:44:31 +0800 Subject: [PATCH 2/4] add build_android.sh, not completed yet, to be continued...... --- build.sh | 40 ++++++------ build_android.sh | 166 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 20 deletions(-) create mode 100755 build_android.sh diff --git a/build.sh b/build.sh index e0e3fc9..f14a0ff 100755 --- a/build.sh +++ b/build.sh @@ -19,9 +19,9 @@ build_openssl=1 # directories build_dir=$origin_dir/build -install_dir=$build_dir/usr +deps_dir=$origin_dir/_deps +dist_dir=$build_dir/usr pkg_dir=$origin_dir/dist -dep_dir=$origin_dir/_deps # function download_src() { @@ -49,9 +49,14 @@ if [ ! -d $build_dir ]; then mkdir -p $build_dir fi -if [ ! -d $install_dir ]; then +if [ ! -d $deps_dir ]; then + echo "create dependency directory" + mkdir -p $deps_dir +fi + +if [ ! -d $dist_dir ]; then echo "create install directory" - mkdir -p $install_dir + mkdir -p $dist_dir fi if [ ! -d $pkg_dir ]; then @@ -59,21 +64,16 @@ if [ ! -d $pkg_dir ]; then mkdir -p $pkg_dir fi -if [ ! -d $dep_dir ]; then - echo "create dependency directory" - mkdir -p $dep_dir -fi - # mugglec echo "------------------------" if [ $build_mugglec -eq 1 ]; then echo "build mugglec" - cd $dep_dir + cd $deps_dir mugglec_git=https://github.com/MuggleWei/mugglec.git mugglec_tag=v1.4.3 mugglec_name=mugglec-$mugglec_tag - mugglec_src_dir=$dep_dir/$mugglec_name + mugglec_src_dir=$deps_dir/$mugglec_name mugglec_build_dir=$build_dir/_deps/mugglec if [ ! -d $mugglec_src_dir ]; then @@ -96,7 +96,7 @@ if [ $build_mugglec -eq 1 ]; then -DBUILD_TESTING=OFF \ -DMUGGLE_BUILD_EXAMPLE=OFF \ -DMUGGLE_BUILD_BENCHMARK=OFF \ - -DCMAKE_INSTALL_PREFIX=$install_dir + -DCMAKE_INSTALL_PREFIX=$dist_dir cmake --build $mugglec_build_dir cmake --build $mugglec_build_dir --target install @@ -110,12 +110,12 @@ cd $origin_dir echo "------------------------" if [ $build_openssl -eq 1 ]; then echo "build openssl" - cd $dep_dir + cd $deps_dir openssl_git=https://github.com/openssl/openssl.git openssl_tag=openssl-3.1.4 openssl_name=openssl-$openssl_tag - openssl_src_dir=$dep_dir/$openssl_name + openssl_src_dir=$deps_dir/$openssl_name openssl_build_dir=$build_dir/_deps/openssl if [ ! -d $openssl_src_dir ]; then @@ -129,8 +129,8 @@ if [ $build_openssl -eq 1 ]; then cd $openssl_build_dir $openssl_src_dir/Configure \ - --prefix=$install_dir \ - --openssldir=$install_dir \ + --prefix=$dist_dir \ + --openssldir=$dist_dir \ --libdir=lib \ threads \ no-comp \ @@ -152,18 +152,18 @@ cd $origin_dir cmake \ -S $origin_dir -B $build_dir \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_PREFIX_PATH=$install_dir \ - -DCMAKE_INSTALL_PREFIX=$install_dir + -DCMAKE_PREFIX_PATH=$dist_dir \ + -DCMAKE_INSTALL_PREFIX=$dist_dir #ln -sf $build_dir/compile_commands.json $origin_dir/ cmake --build $build_dir cmake --build $build_dir --target install # package -cd $install_dir +cd $dist_dir if [[ "$OSTYPE" == "darwin"* ]]; then # force change rpath to openssl in yoauth if [ $build_openssl -eq 1 ]; then - install_name_tool -change "$install_dir/lib/libcrypto.3.dylib" @rpath/libcrypto.3.dylib bin/yoauth + install_name_tool -change "$dist_dir/lib/libcrypto.3.dylib" @rpath/libcrypto.3.dylib bin/yoauth fi tar -czvf yoauth.tar.gz bin/yoauth* lib/*.dylib* else diff --git a/build_android.sh b/build_android.sh new file mode 100755 index 0000000..01b6377 --- /dev/null +++ b/build_android.sh @@ -0,0 +1,166 @@ +#!/bin/bash + +# handle argv +if [ "$#" -lt 1 ]; then + echo "[WARNING] Usage: bootstrap.sh " + echo "[WARNING] bootstrap without build type, use release by default" + BUILD_TYPE=release +else + # to lowercase + BUILD_TYPE=$(echo $1 | tr '[:upper:]' '[:lower:]') +fi + +# project root directory +origin_dir="$(dirname "$(readlink -f "$0")")" + +# build option +build_mugglec=1 +build_openssl=1 + +# directories +build_dir=$origin_dir/build +deps_dir=$origin_dir/_deps +dist_dir=$build_dir/dist +pkg_dir=$origin_dir/dist + +abi=arm64-v8a + +# function +download_src() { + local name=$1 + local git_repo=$2 + local tag=$3 + local src_dir=$4 + + if [ -d $src_dir ]; then + echo "$name source directory already exists" + else + echo "$name source directory not exists, clone" + echo "name=$name" + echo "git_repo=$git_repo" + echo "tag=$tag" + echo "src_dir=$src_dir" + + git clone --branch $tag --depth 1 $git_repo $src_dir + fi +} + +# clean +if [ ! -d $build_dir ]; then + echo "create build directory" + mkdir -p $build_dir +fi + +if [ ! -d $deps_dir ]; then + echo "create dependency directory" + mkdir -p $deps_dir +fi + +if [ ! -d $dist_dir ]; then + echo "create install directory" + mkdir -p $dist_dir +fi + +if [ ! -d $pkg_dir ]; then + echo "create package directory" + mkdir -p $pkg_dir +fi + +# mugglec +echo "------------------------" +if [ $build_mugglec -eq 1 ]; then + echo "build mugglec" + cd $deps_dir + + mugglec_git=https://github.com/MuggleWei/mugglec.git + mugglec_tag=v1.4.3 + mugglec_name=mugglec-$mugglec_tag + mugglec_src_dir=$deps_dir/$mugglec_name + mugglec_build_dir=$build_dir/_deps/mugglec + + if [ ! -d $mugglec_src_dir ]; then + download_src $mugglec_name $mugglec_git $mugglec_tag ${mugglec_src_dir}_tmp + mv ${mugglec_src_dir}_tmp $mugglec_src_dir + fi + + if [ ! -d $mugglec_build_dir ]; then + mkdir -p $mugglec_build_dir + fi + cd $mugglec_build_dir + + cmake \ + -S $mugglec_src_dir -B $mugglec_build_dir \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_INSTALL_PREFIX=$dist_dir \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=$abi + cmake --build $mugglec_build_dir + cmake --build $mugglec_build_dir --target install +else + echo "option build mugglec off, ignore build mugglec" +fi +cd $origin_dir + +# openssl +echo "------------------------" +if [ $build_openssl -eq 1 ]; then + echo "build openssl" + cd $deps_dir + + openssl_git=https://github.com/openssl/openssl.git + openssl_tag=openssl-3.1.4 + openssl_name=openssl-$openssl_tag + openssl_src_dir=$deps_dir/$openssl_name + openssl_build_dir=$build_dir/_deps/openssl + + if [ ! -d $openssl_src_dir ]; then + download_src $openssl_name $openssl_git $openssl_tag ${openssl_src_dir}_tmp + mv ${openssl_src_dir}_tmp $openssl_src_dir + fi + + if [ ! -d $openssl_build_dir ]; then + mkdir -p $openssl_build_dir + fi + cd $openssl_build_dir + + PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH + $openssl_src_dir/Configure \ + android-arm64 \ + --prefix=$dist_dir \ + --openssldir=$dist_dir \ + --libdir=lib \ + threads \ + no-shared \ + no-comp \ + -Wl,-rpath,\\\$\$ORIGIN/../lib \ + no-tests \ + --$BUILD_TYPE + + #bear -- make + make + make install_sw + #ln -sf $openssl_build_dir/compile_commands.json $openssl_src_dir +else + echo "option build openssl off, ignore build openssl" +fi +cd $origin_dir + +# build +cd $origin_dir +cmake \ + -S $origin_dir -B $build_dir \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_PREFIX_PATH=$dist_dir \ + -DCMAKE_INSTALL_PREFIX=$dist_dir \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=$abi + #-DCMAKE_FIND_ROOT_PATH=$dist_dir \ +cmake --build $build_dir +cmake --build $build_dir --target install + +# package +cd $dist_dir +tar -czvf yoauth.tar.gz bin +mv yoauth.tar.gz $pkg_dir From 819258b78137a7559432ce2367c061c1ca34c7f9 Mon Sep 17 00:00:00 2001 From: Muggle Wei Date: Thu, 7 Dec 2023 11:23:05 +0800 Subject: [PATCH 3/4] fix compile error in Android NDK --- CMakeLists.txt | 13 +++++++++++++ build_android.sh | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e43349e..c72845b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,19 @@ foreach(path ${CMAKE_PREFIX_PATH}) message("# CMake Prefix Path: ${path}") endforeach() +# patch: find_package failed when use android toolchain +if (ANDROID) + message("# ANDROID PLATFORM: ${ANDROID_PLATFORM}") + message("# CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}") + message("# append CMAKE_PREFIX_PATH into CMAKE_FIND_ROOT_PATH") + foreach(path ${CMAKE_PREFIX_PATH}) + list(APPEND CMAKE_FIND_ROOT_PATH "${path}") + endforeach() + + # Or use NO_CMAKE_FIND_ROOT_PATH, but openssl still failed + #find_package(mugglec REQUIRED NO_CMAKE_FIND_ROOT_PATH) +endif() + find_package(mugglec REQUIRED) if (mugglec_FOUND) message("deps mugglec version: ${mugglec_VERSION}") diff --git a/build_android.sh b/build_android.sh index 01b6377..e25332b 100755 --- a/build_android.sh +++ b/build_android.sh @@ -24,6 +24,7 @@ dist_dir=$build_dir/dist pkg_dir=$origin_dir/dist abi=arm64-v8a +min_sdk=29 # function download_src() { @@ -45,6 +46,14 @@ download_src() { fi } +# check ndk +if [ -z "$ANDROID_NDK_ROOT" ]; then + echo "run without ANDROID_NDK_ROOT" + exit 1 +else + echo "ndk: $ANDROID_NDK_ROOT" +fi + # clean if [ ! -d $build_dir ]; then echo "create build directory" @@ -94,7 +103,8 @@ if [ $build_mugglec -eq 1 ]; then -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_INSTALL_PREFIX=$dist_dir \ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=$abi + -DANDROID_ABI=$abi \ + -DANDROID_PLATFORM=android-$min_sdk cmake --build $mugglec_build_dir cmake --build $mugglec_build_dir --target install else @@ -127,6 +137,8 @@ if [ $build_openssl -eq 1 ]; then PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH $openssl_src_dir/Configure \ android-arm64 \ + -U__ANDROID_API__ \ + -D__ANDROID_API__=$min_sdk \ --prefix=$dist_dir \ --openssldir=$dist_dir \ --libdir=lib \ @@ -155,12 +167,12 @@ cmake \ -DCMAKE_PREFIX_PATH=$dist_dir \ -DCMAKE_INSTALL_PREFIX=$dist_dir \ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \ - -DANDROID_ABI=$abi - #-DCMAKE_FIND_ROOT_PATH=$dist_dir \ + -DANDROID_ABI=$abi \ + -DANDROID_PLATFORM=android-$min_sdk cmake --build $build_dir cmake --build $build_dir --target install # package cd $dist_dir -tar -czvf yoauth.tar.gz bin +tar -czvf yoauth.tar.gz bin/yoauth* mv yoauth.tar.gz $pkg_dir From fe2282e5f422ee3dbe536cb15017e7cd2a4f0b3c Mon Sep 17 00:00:00 2001 From: Muggle Wei Date: Thu, 7 Dec 2023 11:26:28 +0800 Subject: [PATCH 4/4] update version to 1.0.17 --- build.yml | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.yml b/build.yml index 0068d67..885534f 100644 --- a/build.yml +++ b/build.yml @@ -1,7 +1,7 @@ name: yoauth variables: - build_type: release - - yoauth_tag: v1.0.0 + - yoauth_tag: v1.0.17 - mugglec_tag: v1.3.5 - openssl_tag: openssl-3.1.4 - unity_tag: v2.5.2 diff --git a/version.txt b/version.txt index b668c3b..8fc77d0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.16 +1.0.17