diff --git a/.github/workflows/linux_clang.yml b/.github/workflows/linux_clang.yml index 661b4815..2f873643 100644 --- a/.github/workflows/linux_clang.yml +++ b/.github/workflows/linux_clang.yml @@ -67,7 +67,7 @@ jobs: - name: Configure run: | rm -rf ${{github.workspace}}/build - CXX=clang++ CC=clang cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} -G Ninja + CXX=clang++ CC=clang cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} -G Ninja -DCMAKE_INSTALL_PREFIX="$(pwd)/installed" - name: Build run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}} @@ -75,5 +75,3 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build run: ctest -C ${{matrix.mode}} -j 1 `nproc` -V - - diff --git a/cmake/install.cmake b/cmake/install.cmake index 0a893077..9d79412a 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -1,2 +1,47 @@ # install public header files -install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include" DESTINATION include) +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${yaLanTingLibs_BINARY_DIR}/cmake/yalantinglibsConfigVersion.cmake" + VERSION ${yaLanTingLibs_VERSION} + COMPATIBILITY AnyNewerVersion +) +set(ConfigPackageLocation lib/cmake/yalantinglibs) + +configure_file(cmake/yalantinglibsConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/cmake/yalantinglibsConfig.cmake" + COPYONLY + ) +#install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/" DESTINATION include/yalantinglibs) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/yalantinglibsConfig.cmake" + "${yaLanTingLibs_BINARY_DIR}/cmake/yalantinglibsConfigVersion.cmake" + DESTINATION ${ConfigPackageLocation} +) +function(ylt_install target) + cmake_parse_arguments(ylt_install_lib " " "NAME" "EXPORT" ${ARGN}) + set(_export_name ${target}Targets) + if (ylt_install_lib_NAME) + set(_export_name ${ylt_install_lib_NAME}) + endif () + install( + TARGETS ${target} + EXPORT ${_export_name} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + ) + include(CMakePackageConfigHelpers) + write_basic_package_version_file( + ${target}ConfigVersion.cmake + VERSION ${yaLanTingLibs_VERSION} + COMPATIBILITY SameMajorVersion + ) + install( + EXPORT ${_export_name} + FILE ${target}Targets.cmake + NAMESPACE yalantinglibs:: + DESTINATION ${ConfigPackageLocation} + ) +endfunction() \ No newline at end of file diff --git a/cmake/struct_pb.cmake b/cmake/struct_pb.cmake index decd4e3b..2aac1a9e 100644 --- a/cmake/struct_pb.cmake +++ b/cmake/struct_pb.cmake @@ -165,7 +165,7 @@ function(protobuf_generate_struct_pb SRCS HDRS) set(_outvar) protobuf_generate_modified(${_append_arg} ${_descriptors} LANGUAGE struct_pb EXPORT_MACRO ${protobuf_generate_struct_pb_EXPORT_MACRO} - PLUGIN $ + PLUGIN $ OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files} PROTOC_OPTION ${_opt} ) @@ -217,7 +217,7 @@ function(target_protos_struct_pb target) protobuf_generate_modified( TARGET ${target} LANGUAGE struct_pb EXPORT_MACRO ${target_protos_struct_pb_EXPORT_MACRO} - PLUGIN $ + PLUGIN $ ${_import_arg} PROTOS ${_proto_files} PROTOC_OPTION ${_opt} ) diff --git a/cmake/yalantinglibsConfig.cmake.in b/cmake/yalantinglibsConfig.cmake.in new file mode 100644 index 00000000..b2089427 --- /dev/null +++ b/cmake/yalantinglibsConfig.cmake.in @@ -0,0 +1,27 @@ +include(CMakeFindDependencyMacro) +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/struct_packTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/struct_packTargets.cmake") + message(STATUS "Imported target: yalantinglibs::struct_pack") +endif () +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/struct_pbTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/struct_pbTargets.cmake") + message(STATUS "Imported target: yalantinglibs::struct_pb") +endif () +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/protoc-gen-struct_pbTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/protoc-gen-struct_pbTargets.cmake") + message(STATUS "Imported target: yalantinglibs::protoc-gen-struct_pb") + include("${CMAKE_CURRENT_LIST_DIR}/struct_pb.cmake") + message(STATUS "Now you can use cmake helper function protobuf_generate_struct_pb to generate xx.struct_pb.cc xx.struct_pb.h") +endif () +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/struct_jsonTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/struct_jsonTargets.cmake") + message(STATUS "Imported target: yalantinglibs::struct_json") +endif () +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/easylogTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/easylogTargets.cmake") + message(STATUS "Imported target: yalantinglibs::easylog") +endif () +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/coro_rpcTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/coro_rpcTargets.cmake") + message(STATUS "Imported target: yalantinglibs::coro_rpc") +endif () diff --git a/include/easylog/record.hpp b/include/easylog/record.hpp index 6d4d551e..ed4611a6 100644 --- a/include/easylog/record.hpp +++ b/include/easylog/record.hpp @@ -31,7 +31,7 @@ #include #include -#include "../thirdparty/iguana/iguana/detail//dragonbox_to_chars.h" +#include "iguana/detail/dragonbox_to_chars.h" #if defined(_WIN32) #ifndef _WINDOWS_ diff --git a/src/coro_rpc/CMakeLists.txt b/src/coro_rpc/CMakeLists.txt index 29746404..b4efc36b 100644 --- a/src/coro_rpc/CMakeLists.txt +++ b/src/coro_rpc/CMakeLists.txt @@ -1,29 +1,33 @@ -add_library(libcoro_rpc INTERFACE) -target_link_libraries(libcoro_rpc INTERFACE libstruct_pack) -target_include_directories(libcoro_rpc INTERFACE +add_library(coro_rpc INTERFACE) + +if (NOT TARGET yalantinglibs::coro_rpc) + add_library(yalantinglibs::coro_rpc ALIAS coro_rpc) +endif () +target_link_libraries(coro_rpc INTERFACE struct_pack easylog) +target_include_directories(coro_rpc INTERFACE $ - $ + $ ) -target_link_libraries(libcoro_rpc INTERFACE +target_link_libraries(coro_rpc INTERFACE Threads::Threads - asio::asio - async_simple::async_simple_header_only + $ + $ ) option(ENABLE_IO_URING "Enable io_uring" OFF) -if (ENABLE_IO_URING) +if (ENABLE_IO_URING) message(STATUS "Use IO_URING for I/O in linux") - target_compile_definitions(libcoro_rpc INTERFACE ASIO_HAS_IO_URING) - target_compile_definitions(libcoro_rpc INTERFACE ASIO_DISABLE_EPOLL) - target_link_libraries(libcoro_rpc INTERFACE -luring) + target_compile_definitions(coro_rpc INTERFACE ASIO_HAS_IO_URING) + target_compile_definitions(coro_rpc INTERFACE ASIO_DISABLE_EPOLL) + target_link_libraries(coro_rpc INTERFACE -luring) endif() option(ENABLE_SSL "Enable ssl support" OFF) if (ENABLE_SSL) message(STATUS "Use SSL") find_package(OpenSSL REQUIRED) - target_compile_definitions(libcoro_rpc INTERFACE ENABLE_SSL) - target_link_libraries(libcoro_rpc INTERFACE OpenSSL::SSL OpenSSL::Crypto) + target_compile_definitions(coro_rpc INTERFACE ENABLE_SSL) + target_link_libraries(coro_rpc INTERFACE OpenSSL::SSL OpenSSL::Crypto) endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # When using coro_rpc_client, only remote function declarations are required. @@ -31,6 +35,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # However, clang + ld(gold linker) + '-g' will report 'undefined reference to xxx'. # We force use lld when compiler is clang. # Note: gcc + ld + '-g' or clang + lld + '-g' work well - target_link_options(libcoro_rpc INTERFACE "-fuse-ld=lld") + target_link_options(coro_rpc INTERFACE "-fuse-ld=lld") message(STATUS "Force add link option: -fuse-ld=lld") -endif () \ No newline at end of file +endif () + + +ylt_install(coro_rpc) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/coro_rpc" DESTINATION include/yalantinglibs) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/asio_util" DESTINATION include/yalantinglibs) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/util" DESTINATION include/yalantinglibs) + diff --git a/src/coro_rpc/benchmark/client/CMakeLists.txt b/src/coro_rpc/benchmark/client/CMakeLists.txt index 19fcb096..d547b19f 100644 --- a/src/coro_rpc/benchmark/client/CMakeLists.txt +++ b/src/coro_rpc/benchmark/client/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(benchmark_client client.cpp) -target_link_libraries(benchmark_client PRIVATE libcoro_rpc) +target_link_libraries(benchmark_client PRIVATE yalantinglibs::coro_rpc) target_include_directories(benchmark_client PRIVATE . ..) @@ -7,7 +7,7 @@ option(GENERATE_BENCHMARK_DATA "Generate benchmark data" OFF) message(STATUS "GENERATE_BENCHMARK_DATA: ${GENERATE_BENCHMARK_DATA}") if (GENERATE_BENCHMARK_DATA) add_executable(benchmark_data_gen data_gen.cpp) - target_link_libraries(benchmark_data_gen PRIVATE libcoro_rpc) + target_link_libraries(benchmark_data_gen PRIVATE yalantinglibs::coro_rpc) target_include_directories(benchmark_data_gen PRIVATE . ..) target_compile_definitions(benchmark_data_gen PRIVATE GENERATE_BENCHMARK_DATA) add_custom_command( diff --git a/src/coro_rpc/benchmark/server/CMakeLists.txt b/src/coro_rpc/benchmark/server/CMakeLists.txt index f24e8869..147b95ff 100644 --- a/src/coro_rpc/benchmark/server/CMakeLists.txt +++ b/src/coro_rpc/benchmark/server/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(benchmark_coro_server coro_server.cpp) -target_link_libraries(benchmark_coro_server PRIVATE libcoro_rpc) +target_link_libraries(benchmark_coro_server PRIVATE yalantinglibs::coro_rpc) target_include_directories(benchmark_coro_server PRIVATE . ..) diff --git a/src/coro_rpc/examples/file_transfer/CMakeLists.txt b/src/coro_rpc/examples/file_transfer/CMakeLists.txt index aa42ef35..950fda5e 100644 --- a/src/coro_rpc/examples/file_transfer/CMakeLists.txt +++ b/src/coro_rpc/examples/file_transfer/CMakeLists.txt @@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 20) include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio) include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple) +include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana) add_definitions(-DASIO_HAS_STD_INVOKE_RESULT) add_definitions(-DASYNC_SIMPLE_HAS_NOT_AIO) diff --git a/src/coro_rpc/examples/helloworld/CMakeLists.txt b/src/coro_rpc/examples/helloworld/CMakeLists.txt index 912dadea..d8332723 100644 --- a/src/coro_rpc/examples/helloworld/CMakeLists.txt +++ b/src/coro_rpc/examples/helloworld/CMakeLists.txt @@ -1,6 +1,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) ######################################################################################### -# Example: Use coro_rpc with CMake target libcoro_rpc +# Example: Use coro_rpc with CMake target coro_rpc # After CMake 3.15, all dependencies handled automatically when linking CMake target # No other code needed ######################################################################################### @@ -8,12 +8,12 @@ add_executable(helloworld_server server/main.cpp server/rpc_service.cpp ) -target_link_libraries(helloworld_server PRIVATE libcoro_rpc) +target_link_libraries(helloworld_server PRIVATE yalantinglibs::coro_rpc) add_executable(helloworld_client client/main.cpp) -target_link_libraries(helloworld_client PRIVATE libcoro_rpc) +target_link_libraries(helloworld_client PRIVATE yalantinglibs::coro_rpc) ######################################################################################### -# Example: Use coro_rpc without CMake target libcoro_rpc +# Example: Use coro_rpc without CMake target coro_rpc # You must # - define macro ASIO_HAS_STD_INVOKE_RESULT and ASYNC_SIMPLE_HAS_NOT_AIO manually # - include coro_rpc folder if needed @@ -32,10 +32,12 @@ target_compile_definitions(helloworld_client_manually PRIVATE ASYNC_SIMPLE_HAS_N target_include_directories(helloworld_server_manually PRIVATE ${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio ${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple + ${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana ) target_include_directories(helloworld_client_manually PRIVATE ${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio ${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple + ${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana ) target_link_libraries(helloworld_server_manually -lpthread) target_link_libraries(helloworld_client_manually -lpthread) diff --git a/src/coro_rpc/tests/CMakeLists.txt b/src/coro_rpc/tests/CMakeLists.txt index a75c9ce3..ba0427c8 100644 --- a/src/coro_rpc/tests/CMakeLists.txt +++ b/src/coro_rpc/tests/CMakeLists.txt @@ -18,7 +18,7 @@ add_executable(test_rpc ${TEST_SRCS} ${TEST_COMMON} ) -target_link_libraries(test_rpc PRIVATE libcoro_rpc doctest) +target_link_libraries(test_rpc PRIVATE yalantinglibs::coro_rpc doctest) target_compile_definitions(test_rpc PRIVATE UNIT_TEST_INJECT) target_compile_definitions(test_rpc PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) add_custom_command( @@ -33,7 +33,7 @@ foreach (_test_file ${TEST_SRCS}) ${TEST_COMMON} ) target_link_libraries(${_test_name} - libcoro_rpc + yalantinglibs::coro_rpc doctest ) if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") @@ -59,7 +59,7 @@ foreach (_test_file ${TEST_REGISTER_DUPLICATION_SRCS}) rpc_service.cpp ) target_link_libraries(${_test_name} - libcoro_rpc + yalantinglibs::coro_rpc doctest ) add_test(${_test_name} ${_test_name}) @@ -69,4 +69,4 @@ foreach (_test_file ${TEST_REGISTER_DUPLICATION_SRCS}) ) endforeach () add_executable(test_util test_util.cpp) -target_link_libraries(test_util PRIVATE libcoro_rpc) +target_link_libraries(test_util PRIVATE yalantinglibs::coro_rpc) diff --git a/src/easylog/CMakeLists.txt b/src/easylog/CMakeLists.txt index d347a55b..845e4318 100644 --- a/src/easylog/CMakeLists.txt +++ b/src/easylog/CMakeLists.txt @@ -1,5 +1,11 @@ -add_library(libeasylog INTERFACE) -target_include_directories(libeasylog INTERFACE +add_library(easylog INTERFACE) +if (NOT TARGET yalantinglibs::easylog) + add_library(yalantinglibs::easylog ALIAS easylog) +endif () +target_include_directories(easylog INTERFACE $ - $ - ) \ No newline at end of file + $ + ) +target_link_libraries(easylog INTERFACE $) +ylt_install(easylog) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/easylog" DESTINATION include/yalantinglibs) diff --git a/src/easylog/benchmark/CMakeLists.txt b/src/easylog/benchmark/CMakeLists.txt index f52ede7e..37f09e4a 100644 --- a/src/easylog/benchmark/CMakeLists.txt +++ b/src/easylog/benchmark/CMakeLists.txt @@ -3,6 +3,7 @@ find_package(glog) add_executable(easylog_benchmark main.cpp ) +target_link_libraries(easylog_benchmark PRIVATE yalantinglibs::easylog) add_test(NAME easylog_benchmark COMMAND easylog_benchmark) if (glog_FOUND) diff --git a/src/easylog/tests/CMakeLists.txt b/src/easylog/tests/CMakeLists.txt index a788e9a3..10a02608 100644 --- a/src/easylog/tests/CMakeLists.txt +++ b/src/easylog/tests/CMakeLists.txt @@ -6,4 +6,4 @@ add_executable(test_easylog ) add_test(NAME test_easylog COMMAND test_easylog) target_compile_definitions(test_easylog PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) -target_link_libraries(test_easylog PRIVATE doctest) +target_link_libraries(test_easylog PRIVATE yalantinglibs::easylog doctest) diff --git a/src/struct_json/CMakeLists.txt b/src/struct_json/CMakeLists.txt index 00c2c90e..25b101a4 100644 --- a/src/struct_json/CMakeLists.txt +++ b/src/struct_json/CMakeLists.txt @@ -1,7 +1,12 @@ -add_library(libstruct_json INTERFACE) -target_include_directories(libstruct_json INTERFACE +add_library(struct_json INTERFACE) +if (NOT TARGET yalantinglibs::struct_json) + add_library(yalantinglibs::struct_json ALIAS struct_json) +endif () +target_include_directories(struct_json INTERFACE $ - $ + $ ) -target_link_libraries(libstruct_json INTERFACE iguana) \ No newline at end of file +target_link_libraries(struct_json INTERFACE $) +ylt_install(struct_json) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/struct_json" DESTINATION include/yalantinglibs) diff --git a/src/struct_json/examples/CMakeLists.txt b/src/struct_json/examples/CMakeLists.txt index 41a4d57e..02405b52 100644 --- a/src/struct_json/examples/CMakeLists.txt +++ b/src/struct_json/examples/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(struct_json_example - main.cpp -) -target_link_libraries(struct_json_example PRIVATE libstruct_json) + main.cpp + ) +target_link_libraries(struct_json_example PRIVATE struct_json) ## manual import struct_json include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/frozen) diff --git a/src/struct_pack/CMakeLists.txt b/src/struct_pack/CMakeLists.txt index c4cebdce..c65ede6c 100644 --- a/src/struct_pack/CMakeLists.txt +++ b/src/struct_pack/CMakeLists.txt @@ -1,6 +1,26 @@ -add_library(libstruct_pack INTERFACE) -target_include_directories(libstruct_pack INTERFACE +add_library(struct_pack INTERFACE) +if (NOT TARGET yalantinglibs::struct_pack) + add_library(yalantinglibs::struct_pack ALIAS struct_pack) +endif () +target_include_directories(struct_pack INTERFACE $ $ - $ + $ ) +#install(TARGETS struct_pack +# EXPORT struct_packTargets +# LIBRARY DESTINATION lib +# ARCHIVE DESTINATION lib +# RUNTIME DESTINATION bin +# ) +#export(EXPORT struct_packTargets +# FILE "${yaLanTingLibs_BINARY_DIR}/cmake/struct_packTargets.cmake" +# NAMESPACE yalantinglibs:: +# ) +#install(EXPORT struct_packTargets +# FILE struct_packTargets.cmake +# NAMESPACE yalantinglibs:: +# DESTINATION ${ConfigPackageLocation} +# ) +ylt_install(struct_pack) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/struct_pack" DESTINATION include/yalantinglibs) \ No newline at end of file diff --git a/src/struct_pack/tests/CMakeLists.txt b/src/struct_pack/tests/CMakeLists.txt index ef2697b7..e1114890 100644 --- a/src/struct_pack/tests/CMakeLists.txt +++ b/src/struct_pack/tests/CMakeLists.txt @@ -15,4 +15,4 @@ add_executable(test_serialize ) add_test(NAME test_serialize COMMAND test_serialize) target_compile_definitions(test_serialize PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) -target_link_libraries(test_serialize PRIVATE libstruct_pack doctest) +target_link_libraries(test_serialize PRIVATE yalantinglibs::struct_pack doctest) diff --git a/src/struct_pb/CMakeLists.txt b/src/struct_pb/CMakeLists.txt index 092f0c2d..3ccbb4f1 100644 --- a/src/struct_pb/CMakeLists.txt +++ b/src/struct_pb/CMakeLists.txt @@ -1,7 +1,22 @@ -add_library(libstruct_pb INTERFACE) -target_include_directories(libstruct_pb INTERFACE +add_library(struct_pb INTERFACE) +install(TARGETS struct_pb EXPORT struct_pb + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include + ) +if (NOT TARGET yalantinglibs::struct_pb) + add_library(yalantinglibs::struct_pb ALIAS struct_pb) +endif () +target_include_directories(struct_pb INTERFACE $ - $ + $ ) add_subdirectory(protoc-plugin) -add_subdirectory(conformance) \ No newline at end of file +add_subdirectory(conformance) + +ylt_install(struct_pb) +install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/struct_pb" DESTINATION include/yalantinglibs) +install(FILES "${yaLanTingLibs_SOURCE_DIR}/cmake/struct_pb.cmake" + DESTINATION ${ConfigPackageLocation} + ) diff --git a/src/struct_pb/conformance/CMakeLists.txt b/src/struct_pb/conformance/CMakeLists.txt index 46297038..5d43616b 100644 --- a/src/struct_pb/conformance/CMakeLists.txt +++ b/src/struct_pb/conformance/CMakeLists.txt @@ -40,6 +40,7 @@ add_test(NAME conformance_cpp_test add_executable(conformance_struct_pb conformance_struct_pb.cc ) +target_link_libraries(conformance_struct_pb PRIVATE yalantinglibs::struct_pb) protobuf_generate_struct_pb(SRCS HDRS conformance/conformance.proto google/protobuf/test_messages_proto2.proto diff --git a/src/struct_pb/examples/CMakeLists.txt b/src/struct_pb/examples/CMakeLists.txt index ee328a7c..921def15 100644 --- a/src/struct_pb/examples/CMakeLists.txt +++ b/src/struct_pb/examples/CMakeLists.txt @@ -2,9 +2,9 @@ find_package(Protobuf) if (Protobuf_FOUND) add_executable(struct_pb_example main.cpp) target_protos_struct_pb(struct_pb_example PUBLIC demo.proto) - target_link_libraries(struct_pb_example PRIVATE libstruct_pb) + target_link_libraries(struct_pb_example PRIVATE yalantinglibs::struct_pb) add_executable(struct_pb_tutorial tutorial.cpp) target_protos_struct_pb(struct_pb_tutorial PRIVATE addressbook.proto) - target_link_libraries(struct_pb_tutorial PRIVATE libstruct_pb) + target_link_libraries(struct_pb_tutorial PRIVATE yalantinglibs::struct_pb) endif() diff --git a/src/struct_pb/protoc-plugin/CMakeLists.txt b/src/struct_pb/protoc-plugin/CMakeLists.txt index 146c685b..446fec46 100644 --- a/src/struct_pb/protoc-plugin/CMakeLists.txt +++ b/src/struct_pb/protoc-plugin/CMakeLists.txt @@ -2,7 +2,11 @@ find_package(Protobuf) if (Protobuf_FOUND) file(GLOB SRCS "*.cpp" "*.h") add_executable(protoc-gen-struct_pb ${SRCS}) - target_link_libraries(protoc-gen-struct_pb PRIVATE protobuf::libprotoc protobuf::libprotobuf) + target_link_libraries(protoc-gen-struct_pb PUBLIC protobuf::libprotoc protobuf::libprotobuf) + if (NOT TARGET yalantinglibs::protoc-gen-struct_pb) + add_executable(yalantinglibs::protoc-gen-struct_pb ALIAS protoc-gen-struct_pb) + endif () + ylt_install(protoc-gen-struct_pb) else () message(WARNING "to build struct_pb protoc plugin, you must install libprotoc first!!!\n" "see https://alibaba.github.io/yalantinglibs/guide/struct-pb-generating-your-struct.html" diff --git a/src/struct_pb/tests/CMakeLists.txt b/src/struct_pb/tests/CMakeLists.txt index ca4d277f..a81c4908 100644 --- a/src/struct_pb/tests/CMakeLists.txt +++ b/src/struct_pb/tests/CMakeLists.txt @@ -9,7 +9,7 @@ add_executable(test_struct_pb target_sources(test_struct_pb PRIVATE main.cpp ) -target_link_libraries(test_struct_pb PRIVATE libstruct_pb doctest) +target_link_libraries(test_struct_pb PRIVATE yalantinglibs::struct_pb doctest) add_test(NAME test_struct_pb COMMAND test_struct_pb) target_include_directories(test_struct_pb PUBLIC ${yaLanTingLibs_SOURCE_DIR}/src/struct_pack/benchmark) if (Protobuf_FOUND) diff --git a/test_install.sh b/test_install.sh new file mode 100644 index 00000000..ca70d52c --- /dev/null +++ b/test_install.sh @@ -0,0 +1,67 @@ +# +# Copyright (c) 2023, Alibaba Group Holding Limited; +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +set -e +echo "test yaLanTingLibs install" +rm -rf tmp +mkdir tmp +cd tmp +echo "copy test code" +prj_list="struct_pack struct_pb coro_rpc easylog" +for lib in $prj_list +do + mkdir "$lib" + echo " copy $lib" + cp -r ../src/"$lib"/tests "$lib"/ +done +cp -r ../thirdparty/doctest . +cp -r ../src/struct_pb/conformance struct_pb/ +echo "add CMakeLists.txt" +prj_file=CMakeLists.txt +( +cat << EOF +cmake_minimum_required(VERSION 3.15) +project(yaLanTingLibs_install_tests + VERSION 1.0.0 + LANGUAGES CXX + ) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +enable_testing() +find_package(Threads REQUIRED) +find_package(OpenSSL) +find_package(yalantinglibs REQUIRED) +add_compile_definitions(ASYNC_SIMPLE_HAS_NOT_AIO) +############################# +# doctest +############################# +add_library(doctest INTERFACE) +target_include_directories(doctest INTERFACE doctest) +EOF +) > $prj_file +for lib in $prj_list +do + echo "add_subdirectory($lib/tests)" >> $prj_file +done +echo "add_subdirectory(struct_pb/conformance)" >> $prj_file +# workaround +cp -r ../src/struct_pack/benchmark struct_pack/ +echo "target_include_directories(test_struct_pb PUBLIC struct_pack/benchmark)" >> $prj_file + +echo "build tests" +cmake -B build -S . -DCMAKE_PREFIX_PATH="$(pwd)/../installed" +cmake --build build -j +echo "run tests" +cd build && ctest diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 88c4e22c..6a5f65c9 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -35,3 +35,17 @@ target_include_directories(frozen INTERFACE frozen) ############################# add_library(iguana INTERFACE) target_include_directories(iguana INTERFACE frozen iguana) + +# +# Install +# +install(DIRECTORY asio/ DESTINATION include/yalantinglibs) +install(DIRECTORY async_simple/ DESTINATION include/yalantinglibs + REGEX "test" EXCLUDE + REGEX "async_simple/uthread" EXCLUDE + PATTERN "*.cpp" EXCLUDE + ) +install(DIRECTORY frozen/ DESTINATION include/yalantinglibs + REGEX "CMakeLists.txt" EXCLUDE + ) +install(DIRECTORY iguana/ DESTINATION include/yalantinglibs)