refactor: cmake install (#177)

This commit is contained in:
PikachuHy 2023-02-07 11:00:35 +08:00 committed by GitHub
parent 5e31529507
commit 662eab15db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 274 additions and 57 deletions

View File

@ -67,7 +67,7 @@ jobs:
- name: Configure - name: Configure
run: | run: |
rm -rf ${{github.workspace}}/build 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 - name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}} run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}
@ -75,5 +75,3 @@ jobs:
- name: Test - name: Test
working-directory: ${{github.workspace}}/build working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.mode}} -j 1 `nproc` -V run: ctest -C ${{matrix.mode}} -j 1 `nproc` -V

View File

@ -1,2 +1,47 @@
# install public header files # 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()

View File

@ -165,7 +165,7 @@ function(protobuf_generate_struct_pb SRCS HDRS)
set(_outvar) set(_outvar)
protobuf_generate_modified(${_append_arg} ${_descriptors} protobuf_generate_modified(${_append_arg} ${_descriptors}
LANGUAGE struct_pb EXPORT_MACRO ${protobuf_generate_struct_pb_EXPORT_MACRO} LANGUAGE struct_pb EXPORT_MACRO ${protobuf_generate_struct_pb_EXPORT_MACRO}
PLUGIN $<TARGET_FILE:protoc-gen-struct_pb> PLUGIN $<TARGET_FILE:yalantinglibs::protoc-gen-struct_pb>
OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files} OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files}
PROTOC_OPTION ${_opt} PROTOC_OPTION ${_opt}
) )
@ -217,7 +217,7 @@ function(target_protos_struct_pb target)
protobuf_generate_modified( protobuf_generate_modified(
TARGET ${target} TARGET ${target}
LANGUAGE struct_pb EXPORT_MACRO ${target_protos_struct_pb_EXPORT_MACRO} LANGUAGE struct_pb EXPORT_MACRO ${target_protos_struct_pb_EXPORT_MACRO}
PLUGIN $<TARGET_FILE:protoc-gen-struct_pb> PLUGIN $<TARGET_FILE:yalantinglibs::protoc-gen-struct_pb>
${_import_arg} PROTOS ${_proto_files} ${_import_arg} PROTOS ${_proto_files}
PROTOC_OPTION ${_opt} PROTOC_OPTION ${_opt}
) )

View File

@ -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 ()

View File

@ -31,7 +31,7 @@
#include <util/meta_string.hpp> #include <util/meta_string.hpp>
#include <utility> #include <utility>
#include "../thirdparty/iguana/iguana/detail//dragonbox_to_chars.h" #include "iguana/detail/dragonbox_to_chars.h"
#if defined(_WIN32) #if defined(_WIN32)
#ifndef _WINDOWS_ #ifndef _WINDOWS_

View File

@ -1,29 +1,33 @@
add_library(libcoro_rpc INTERFACE) add_library(coro_rpc INTERFACE)
target_link_libraries(libcoro_rpc INTERFACE libstruct_pack)
target_include_directories(libcoro_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
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/yalantinglibs>
) )
target_link_libraries(libcoro_rpc INTERFACE target_link_libraries(coro_rpc INTERFACE
Threads::Threads Threads::Threads
asio::asio $<BUILD_INTERFACE:asio::asio>
async_simple::async_simple_header_only $<BUILD_INTERFACE:async_simple::async_simple_header_only>
) )
option(ENABLE_IO_URING "Enable io_uring" OFF) 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") message(STATUS "Use IO_URING for I/O in linux")
target_compile_definitions(libcoro_rpc INTERFACE ASIO_HAS_IO_URING) target_compile_definitions(coro_rpc INTERFACE ASIO_HAS_IO_URING)
target_compile_definitions(libcoro_rpc INTERFACE ASIO_DISABLE_EPOLL) target_compile_definitions(coro_rpc INTERFACE ASIO_DISABLE_EPOLL)
target_link_libraries(libcoro_rpc INTERFACE -luring) target_link_libraries(coro_rpc INTERFACE -luring)
endif() endif()
option(ENABLE_SSL "Enable ssl support" OFF) option(ENABLE_SSL "Enable ssl support" OFF)
if (ENABLE_SSL) if (ENABLE_SSL)
message(STATUS "Use SSL") message(STATUS "Use SSL")
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
target_compile_definitions(libcoro_rpc INTERFACE ENABLE_SSL) target_compile_definitions(coro_rpc INTERFACE ENABLE_SSL)
target_link_libraries(libcoro_rpc INTERFACE OpenSSL::SSL OpenSSL::Crypto) target_link_libraries(coro_rpc INTERFACE OpenSSL::SSL OpenSSL::Crypto)
endif () endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# When using coro_rpc_client, only remote function declarations are required. # 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'. # However, clang + ld(gold linker) + '-g' will report 'undefined reference to xxx'.
# We force use lld when compiler is clang. # We force use lld when compiler is clang.
# Note: gcc + ld + '-g' or clang + lld + '-g' work well # 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") message(STATUS "Force add link option: -fuse-ld=lld")
endif () 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)

View File

@ -1,5 +1,5 @@
add_executable(benchmark_client client.cpp) 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 . ..) 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}") message(STATUS "GENERATE_BENCHMARK_DATA: ${GENERATE_BENCHMARK_DATA}")
if (GENERATE_BENCHMARK_DATA) if (GENERATE_BENCHMARK_DATA)
add_executable(benchmark_data_gen data_gen.cpp) 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_include_directories(benchmark_data_gen PRIVATE . ..)
target_compile_definitions(benchmark_data_gen PRIVATE GENERATE_BENCHMARK_DATA) target_compile_definitions(benchmark_data_gen PRIVATE GENERATE_BENCHMARK_DATA)
add_custom_command( add_custom_command(

View File

@ -1,4 +1,4 @@
add_executable(benchmark_coro_server coro_server.cpp) 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 . ..) target_include_directories(benchmark_coro_server PRIVATE . ..)

View File

@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 20)
include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio) include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio)
include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple) include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple)
include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana)
add_definitions(-DASIO_HAS_STD_INVOKE_RESULT) add_definitions(-DASIO_HAS_STD_INVOKE_RESULT)
add_definitions(-DASYNC_SIMPLE_HAS_NOT_AIO) add_definitions(-DASYNC_SIMPLE_HAS_NOT_AIO)

View File

@ -1,6 +1,6 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON) 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 # After CMake 3.15, all dependencies handled automatically when linking CMake target
# No other code needed # No other code needed
######################################################################################### #########################################################################################
@ -8,12 +8,12 @@ add_executable(helloworld_server
server/main.cpp server/main.cpp
server/rpc_service.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) 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 # You must
# - define macro ASIO_HAS_STD_INVOKE_RESULT and ASYNC_SIMPLE_HAS_NOT_AIO manually # - define macro ASIO_HAS_STD_INVOKE_RESULT and ASYNC_SIMPLE_HAS_NOT_AIO manually
# - include coro_rpc folder if needed # - 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 target_include_directories(helloworld_server_manually PRIVATE
${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio ${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio
${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple ${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple
${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana
) )
target_include_directories(helloworld_client_manually PRIVATE target_include_directories(helloworld_client_manually PRIVATE
${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio ${yaLanTingLibs_SOURCE_DIR}/thirdparty/asio
${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple ${yaLanTingLibs_SOURCE_DIR}/thirdparty/async_simple
${yaLanTingLibs_SOURCE_DIR}/thirdparty/iguana
) )
target_link_libraries(helloworld_server_manually -lpthread) target_link_libraries(helloworld_server_manually -lpthread)
target_link_libraries(helloworld_client_manually -lpthread) target_link_libraries(helloworld_client_manually -lpthread)

View File

@ -18,7 +18,7 @@ add_executable(test_rpc
${TEST_SRCS} ${TEST_SRCS}
${TEST_COMMON} ${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 UNIT_TEST_INJECT)
target_compile_definitions(test_rpc PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) target_compile_definitions(test_rpc PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE)
add_custom_command( add_custom_command(
@ -33,7 +33,7 @@ foreach (_test_file ${TEST_SRCS})
${TEST_COMMON} ${TEST_COMMON}
) )
target_link_libraries(${_test_name} target_link_libraries(${_test_name}
libcoro_rpc yalantinglibs::coro_rpc
doctest doctest
) )
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
@ -59,7 +59,7 @@ foreach (_test_file ${TEST_REGISTER_DUPLICATION_SRCS})
rpc_service.cpp rpc_service.cpp
) )
target_link_libraries(${_test_name} target_link_libraries(${_test_name}
libcoro_rpc yalantinglibs::coro_rpc
doctest doctest
) )
add_test(${_test_name} ${_test_name}) add_test(${_test_name} ${_test_name})
@ -69,4 +69,4 @@ foreach (_test_file ${TEST_REGISTER_DUPLICATION_SRCS})
) )
endforeach () endforeach ()
add_executable(test_util test_util.cpp) add_executable(test_util test_util.cpp)
target_link_libraries(test_util PRIVATE libcoro_rpc) target_link_libraries(test_util PRIVATE yalantinglibs::coro_rpc)

View File

@ -1,5 +1,11 @@
add_library(libeasylog INTERFACE) add_library(easylog INTERFACE)
target_include_directories(libeasylog INTERFACE if (NOT TARGET yalantinglibs::easylog)
add_library(yalantinglibs::easylog ALIAS easylog)
endif ()
target_include_directories(easylog INTERFACE
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/yalantinglibs>
) )
target_link_libraries(easylog INTERFACE $<BUILD_INTERFACE:iguana>)
ylt_install(easylog)
install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/easylog" DESTINATION include/yalantinglibs)

View File

@ -3,6 +3,7 @@ find_package(glog)
add_executable(easylog_benchmark add_executable(easylog_benchmark
main.cpp main.cpp
) )
target_link_libraries(easylog_benchmark PRIVATE yalantinglibs::easylog)
add_test(NAME easylog_benchmark COMMAND easylog_benchmark) add_test(NAME easylog_benchmark COMMAND easylog_benchmark)
if (glog_FOUND) if (glog_FOUND)

View File

@ -6,4 +6,4 @@ add_executable(test_easylog
) )
add_test(NAME test_easylog COMMAND test_easylog) add_test(NAME test_easylog COMMAND test_easylog)
target_compile_definitions(test_easylog PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) 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)

View File

@ -1,7 +1,12 @@
add_library(libstruct_json INTERFACE) add_library(struct_json INTERFACE)
target_include_directories(libstruct_json INTERFACE if (NOT TARGET yalantinglibs::struct_json)
add_library(yalantinglibs::struct_json ALIAS struct_json)
endif ()
target_include_directories(struct_json INTERFACE
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/yalantinglibs>
) )
target_link_libraries(libstruct_json INTERFACE iguana) target_link_libraries(struct_json INTERFACE $<BUILD_INTERFACE:iguana>)
ylt_install(struct_json)
install(DIRECTORY "${yaLanTingLibs_SOURCE_DIR}/include/struct_json" DESTINATION include/yalantinglibs)

View File

@ -1,7 +1,7 @@
add_executable(struct_json_example add_executable(struct_json_example
main.cpp main.cpp
) )
target_link_libraries(struct_json_example PRIVATE libstruct_json) target_link_libraries(struct_json_example PRIVATE struct_json)
## manual import struct_json ## manual import struct_json
include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/frozen) include_directories(${yaLanTingLibs_SOURCE_DIR}/thirdparty/frozen)

View File

@ -1,6 +1,26 @@
add_library(libstruct_pack INTERFACE) add_library(struct_pack INTERFACE)
target_include_directories(libstruct_pack INTERFACE if (NOT TARGET yalantinglibs::struct_pack)
add_library(yalantinglibs::struct_pack ALIAS struct_pack)
endif ()
target_include_directories(struct_pack INTERFACE
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/thirdparty/frozen> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/thirdparty/frozen>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/yalantinglibs>
) )
#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)

View File

@ -15,4 +15,4 @@ add_executable(test_serialize
) )
add_test(NAME test_serialize COMMAND test_serialize) add_test(NAME test_serialize COMMAND test_serialize)
target_compile_definitions(test_serialize PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE) 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)

View File

@ -1,7 +1,22 @@
add_library(libstruct_pb INTERFACE) add_library(struct_pb INTERFACE)
target_include_directories(libstruct_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
$<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include> $<BUILD_INTERFACE:${yaLanTingLibs_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/yalantinglibs>
) )
add_subdirectory(protoc-plugin) add_subdirectory(protoc-plugin)
add_subdirectory(conformance) 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}
)

View File

@ -40,6 +40,7 @@ add_test(NAME conformance_cpp_test
add_executable(conformance_struct_pb add_executable(conformance_struct_pb
conformance_struct_pb.cc conformance_struct_pb.cc
) )
target_link_libraries(conformance_struct_pb PRIVATE yalantinglibs::struct_pb)
protobuf_generate_struct_pb(SRCS HDRS protobuf_generate_struct_pb(SRCS HDRS
conformance/conformance.proto conformance/conformance.proto
google/protobuf/test_messages_proto2.proto google/protobuf/test_messages_proto2.proto

View File

@ -2,9 +2,9 @@ find_package(Protobuf)
if (Protobuf_FOUND) if (Protobuf_FOUND)
add_executable(struct_pb_example main.cpp) add_executable(struct_pb_example main.cpp)
target_protos_struct_pb(struct_pb_example PUBLIC demo.proto) 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) add_executable(struct_pb_tutorial tutorial.cpp)
target_protos_struct_pb(struct_pb_tutorial PRIVATE addressbook.proto) 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() endif()

View File

@ -2,7 +2,11 @@ find_package(Protobuf)
if (Protobuf_FOUND) if (Protobuf_FOUND)
file(GLOB SRCS "*.cpp" "*.h") file(GLOB SRCS "*.cpp" "*.h")
add_executable(protoc-gen-struct_pb ${SRCS}) 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 () else ()
message(WARNING "to build struct_pb protoc plugin, you must install libprotoc first!!!\n" 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" "see https://alibaba.github.io/yalantinglibs/guide/struct-pb-generating-your-struct.html"

View File

@ -9,7 +9,7 @@ add_executable(test_struct_pb
target_sources(test_struct_pb PRIVATE target_sources(test_struct_pb PRIVATE
main.cpp 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) add_test(NAME test_struct_pb COMMAND test_struct_pb)
target_include_directories(test_struct_pb PUBLIC ${yaLanTingLibs_SOURCE_DIR}/src/struct_pack/benchmark) target_include_directories(test_struct_pb PUBLIC ${yaLanTingLibs_SOURCE_DIR}/src/struct_pack/benchmark)
if (Protobuf_FOUND) if (Protobuf_FOUND)

67
test_install.sh Normal file
View File

@ -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

View File

@ -35,3 +35,17 @@ target_include_directories(frozen INTERFACE frozen)
############################# #############################
add_library(iguana INTERFACE) add_library(iguana INTERFACE)
target_include_directories(iguana INTERFACE frozen iguana) 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)