Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake][doc] rename cmake option, export it to find_package(), add doc. #601

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Configure
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=OFF -DENABLE_SSL=ON \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=OFF -DYLT_ENABLE_SSL=ON \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17
- name: Build with ${{ matrix.compiler }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_llvm_cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
cp -r src/coro_rpc/tests/openssl_files .
ls
mkdir build && cd build
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DENABLE_SSL=ON
CC=clang-17 CXX=clang++-17 cmake .. -DCOVERAGE_TEST=ON -DYLT_ENABLE_SSL=ON
make -j
export LLVM_PROFILE_FILE="test_ylt-%m.profraw"
cd output
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
key: ${{ github.job }}-${{ matrix.mode}}-ssl( ${{ matrix.ssl}} )

- name: Configure CMake
run: OPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 CXX=clang++ CC=clang cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.mode}} -DENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON
run: OPENSSL_ROOT_DIR=/usr/local/opt/openssl@3 CXX=clang++ CC=clang cmake -B ${{github.workspace}}/build -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.mode}} -DYLT_ENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Configure
run: |
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DYLT_ENABLE_SSL=${{matrix.ssl}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
run: |
CXX=clang++ CC=clang
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DYLT_ENABLE_SSL=${{matrix.ssl}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17\
-DBUILD_CORO_HTTP=OFF -DBUILD_CORO_IO=OFF -DBUILD_CORO_RPC=OFF -DBUILD_EASYLOG=OFF -DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF
- name: Build
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} \
-DBUILD_WITH_LIBCXX=${{matrix.libcxx}} \
-DENABLE_IO_URING=${{matrix.io_uring}} \
-DYLT_ENABLE_IO_URING=${{matrix.io_uring}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang-17 -DCMAKE_CXX_COMPILER=clang++-17\
-DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_PACK=OFF -DBUILD_STRUCT_PB=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
CXX=g++ CC=gcc
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DYLT_ENABLE_SSL=${{matrix.ssl}} \
-DUSE_CCACHE=${{env.ccache}}

- name: Build
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
run: |
CXX=g++ CC=gcc
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DYLT_ENABLE_SSL=${{matrix.ssl}} \
-DUSE_CCACHE=${{env.ccache}} \
-DBUILD_CORO_HTTP=OFF -DBUILD_CORO_IO=OFF -DBUILD_CORO_RPC=OFF -DBUILD_EASYLOG=OFF -DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF

Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
CXX=g++ CC=gcc
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} \
-DENABLE_IO_URING=${{matrix.io_uring}} \
-DYLT_ENABLE_IO_URING=${{matrix.io_uring}} \
-DUSE_CCACHE=${{env.ccache}} \
-DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_PACK=OFF -DBUILD_STRUCT_PB=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
key: ${{ github.job }}-${{ matrix.mode}}-ssl( ${{ matrix.ssl}} )-arch-${{ matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}\build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON
run: cmake -B ${{github.workspace}}\build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DYLT_ENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON
- name: Build
run: cmake --build ${{github.workspace}}\build
- name: Test
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
with:
key: ${{ github.job }}-${{ matrix.mode}}-arch-${{ matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}\build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON -DENABLE_CPP_20=OFF
run: cmake -B ${{github.workspace}}\build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DYLT_ENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON -DENABLE_CPP_20=OFF
- name: Build
run: cmake --build ${{github.workspace}}\build
- name: Test
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ You can see the test/example/benchmark executable file in `./build/output/`.
```shell
# You can use those option to skip build unit-test & benchmark & example:
cmake .. -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF -DBUILD_UNIT_TESTS=OFF
cmake --build .
```

3. install
Expand Down Expand Up @@ -400,18 +399,36 @@ See [async_simple](https://github.com/alibaba/async_simple)
# Details
## CMAKE OPTION
## CMAKE OPTION
## config option
These option maybe useful for your project. You can enable it in your project if you import ylt by cmake fetchContent or find_package.
|option|default value|description|
|----------|------------|
|YLT_ENABLE_SSL|OFF|enable optional ssl support for rpc/http|
|YLT_ENABLE_PMR|OFF|enable pmr optimize|
|YLT_ENABLE_IO_URING|OFF|enable io_uring in linux|
|YLT_ENABLE_FILE_IO_URING|OFF|enable file io_uring as backend in linux|
|YLT_ENABLE_STRUCT_PACK_UNPORTABLE_TYPE|OFF|enable unportable type(like wstring, int128_t) for struct_pack|
|YLT_ENABLE_STRUCT_PACK_OPTIMIZE|OFF|optimize struct_pack by radical template unwinding(will cost more compile time)|
## thirdparty installation option
These CMake options is used for yalantinglibs developing/installing itself. They are not effected for your project, because ylt is a head-only.
In default, yalantinglibs will install thirdparty librarys in `ylt/thirdparty`. You need add it to include path when compile.
### INSTALL OPTION
If you don't want to install the thirdparty librarys, you can turn off cmake option `-DINSTALL_THIRDPARTY=OFF`.
If you want to install the thirdparty independently (direct install it in system include path so that you don't need add `ylt/thirdparty` to include path), you can use turn on cmake option `-DINSTALL_INDEPENDENT_THIRDPARTY=ON`.
|option|default value|
|----------|------------|
|INSTALL_THIRDPARTY|ON|
|INSTALL_INDEPENDENT_THIRDPARTY|OFF|
### ylt develop option
## develop option
These CMake options is used for yalantinglibs developing/installing itself. They are not effected for your project, because ylt is a head-only.
|option|default value|
|----------|------------|
Expand All @@ -423,25 +440,8 @@ These CMake options is used for yalantinglibs developing/installing itself. They
|GENERATE_BENCHMARK_DATA|ON|
|CORO_RPC_USE_OTHER_RPC|ON|
### ylt config option
These option maybe useful for your project. If you want to enable it in your project, see the cmake code [here](https://github.com/alibaba/yalantinglibs/tree/main/cmake/config.cmake)
|option|default value|
|----------|------------|
|ENABLE_SSL|OFF|
|ENABLE_PMR|OFF|
|ENABLE_IO_URING|OFF|
|ENABLE_FILE_IO_URING|OFF|
|ENABLE_STRUCT_PACK_UNPORTABLE_TYPE|OFF|
|ENABLE_STRUCT_PACK_OPTIMIZE|OFF|
## Thirdparty Dependency
In default, yalantinglibs will install thirdparty librarys in `ylt/thirdparty`. You need add it to include path when compile.
If you don't want to install the thirdparty librarys, you can turn off cmake option `-DINSTALL_THIRDPARTY=OFF`.
If you want to install the thirdparty independently (direct install it in system include path so that you don't need add `ylt/thirdparty` to include path), you can use turn on cmake option `-DINSTALL_INDEPENDENT_THIRDPARTY=ON`.
## Thirdparty Dependency List
Here are the thirdparty libraries we used(Although async_simple is a part of ylt, it open source first, so we import it as a independence thirdparty library).
Expand Down
3 changes: 2 additions & 1 deletion cmake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
message(STATUS "-------------COMPILE SETTING-------------")
message(STATUS "-------------YLT COMPILE SETTING------------")

# CPP Standard
foreach(i ${CMAKE_CXX_COMPILE_FEATURES})
Expand Down Expand Up @@ -79,3 +79,4 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/EHa>")
endif()

message(STATUS "--------------------------------------------")
51 changes: 24 additions & 27 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
message(STATUS "-------------PROJECT SETTING-------------")
option(ENABLE_SSL "Enable ssl support" OFF)
message(STATUS "ENABLE_SSL: ${ENABLE_SSL}")
if (ENABLE_SSL)
message(STATUS "-------------YLT CONFIG SETTING-------------")
option(YLT_ENABLE_SSL "Enable ssl support" OFF)
message(STATUS "ENABLE_SSL: ${YLT_ENABLE_SSL}")
if (YLT_ENABLE_SSL)
find_package(OpenSSL REQUIRED)
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
add_compile_definitions(YLT_ENABLE_SSL)
add_compile_definitions("YLT_ENABLE_SSL")
link_libraries(OpenSSL::SSL OpenSSL::Crypto)
else ()
target_compile_definitions(yalantinglibs INTERFACE YLT_ENABLE_SSL)
target_compile_definitions(yalantinglibs INTERFACE "YLT_ENABLE_SSL")
target_link_libraries(yalantinglibs INTERFACE OpenSSL::SSL OpenSSL::Crypto)
endif ()
endif ()

option(ENABLE_PMR "Enable pmr support" OFF)
message(STATUS "ENABLE_PMR: ${ENABLE_PMR}")
if (ENABLE_PMR)
option(YLT_ENABLE_PMR "Enable pmr support" OFF)
message(STATUS "ENABLE_PMR: ${YLT_ENABLE_PMR}")
if (YLT_ENABLE_PMR)
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
add_compile_definitions(YLT_ENABLE_PMR IGUANA_ENABLE_PMR)
add_compile_definitions("YLT_ENABLE_PMR" IGUANA_ENABLE_PMR)
else ()
target_compile_definitions(yalantinglibs INTERFACE YLT_ENABLE_PMR IGUANA_ENABLE_PMR)
target_compile_definitions(yalantinglibs INTERFACE "YLT_ENABLE_PMR" IGUANA_ENABLE_PMR)
endif ()
endif ()

option(ENABLE_IO_URING "Enable io_uring" OFF)
message(STATUS "ENABLE_IO_URING: ${ENABLE_IO_URING}")
if (ENABLE_IO_URING)
option(YLT_ENABLE_IO_URING "Enable io_uring" OFF)
message(STATUS "ENABLE_IO_URING: ${YLT_ENABLE_IO_URING}")
if (YLT_ENABLE_IO_URING)
find_package(uring REQUIRED)
message(STATUS "Use IO_URING for all I/O in linux")
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
Expand All @@ -36,16 +36,16 @@ if (ENABLE_IO_URING)
endif ()
endif()

option(ENABLE_FILE_IO_URING "Enable file io_uring" OFF)
if (NOT ENABLE_IO_URING)
if(ENABLE_FILE_IO_URING)
option(YLT_ENABLE_FILE_IO_URING "Enable file io_uring" OFF)
if (NOT YLT_ENABLE_IO_URING)
if(YLT_ENABLE_FILE_IO_URING)
find_package(uring REQUIRED)
message(STATUS "Enable io_uring for file I/O in linux")
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
add_compile_definitions(ASIO_HAS_IO_URING ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
add_compile_definitions(ASIO_HAS_IO_URING ASIO_HAS_FILE "YLT_ENABLE_FILE_IO_URING")
link_libraries(uring)
else ()
target_compile_definitions(yalantinglibs INTERFACE ASIO_HAS_IO_URING ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
target_compile_definitions(yalantinglibs INTERFACE ASIO_HAS_IO_URING ASIO_HAS_FILE "YLT_ENABLE_FILE_IO_URING")
target_link_libraries(yalantinglibs INTERFACE uring)
endif ()
endif()
Expand All @@ -54,19 +54,16 @@ endif()
option(ENABLE_STRUCT_PACK_UNPORTABLE_TYPE "enable struct_pack unportable type(like wchar_t)" OFF)
message(STATUS "ENABLE_STRUCT_PACK_UNPORTABLE_TYPE: ${ENABLE_STRUCT_PACK_UNPORTABLE_TYPE}")
if(ENABLE_STRUCT_PACK_UNPORTABLE_TYPE)
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
add_compile_definitions(STRUCT_PACK_ENABLE_UNPORTABLE_TYPE)
else ()
target_compile_definitions(yalantinglibs INTERFACE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE)
endif ()
add_compile_definitions(STRUCT_PACK_ENABLE_UNPORTABLE_TYPE)
endif()

option(ENABLE_STRUCT_PACK_OPTIMIZE "enable struct_pack optimize(but cost more compile time)" OFF)
message(STATUS "ENABLE_STRUCT_PACK_OPTIMIZE: ${ENABLE_STRUCT_PACK_OPTIMIZE}")
option(YLT_ENABLE_STRUCT_PACK_OPTIMIZE "enable struct_pack optimize(but cost more compile time)" OFF)
message(STATUS "ENABLE_STRUCT_PACK_OPTIMIZE: ${YLT_ENABLE_STRUCT_PACK_OPTIMIZE}")
if(ENABLE_STRUCT_PACK_OPTIMIZE)
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
add_compile_definitions(ENABLE_STRUCT_PACK_OPTIMIZE)
else ()
target_compile_definitions(yalantinglibs INTERFACE ENABLE_STRUCT_PACK_OPTIMIZE)
endif ()
endif()
endif()
message(STATUS "--------------------------------------------")
3 changes: 2 additions & 1 deletion cmake/develop.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
message(STATUS "-------------DEVELOP SETTING-------------")
message(STATUS "-------------YLT DEVELOP SETTING------------")
# extra
option(BUILD_EXAMPLES "Build examples" ON)
message(STATUS "BUILD_EXAMPLES: ${BUILD_EXAMPLES}")
Expand Down Expand Up @@ -65,3 +65,4 @@ if(ENABLE_WARNING)
-Wfatal-errors)
endif()
endif()
message(STATUS "--------------------------------------------")
20 changes: 17 additions & 3 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
message(STATUS "-------------INSTALL SETTING-------------")
message(STATUS "-------------YLT INSTALL SETTING------------")
option(INSTALL_THIRDPARTY "Install thirdparty" ON)
message(STATUS "INSTALL_THIRDPARTY: " ${INSTALL_THIRDPARTY})
option(INSTALL_INDEPENDENT_THIRDPARTY "Install independent thirdparty" ON)
Expand All @@ -25,8 +25,21 @@ install(TARGETS yalantinglibs
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/yalantinglibsConfig.cmake"
"include(\$\{CMAKE_CURRENT_LIST_DIR\}/yalantinglibsConfigImpl.cmake)\n"
"include(\$\{CMAKE_CURRENT_LIST_DIR\}/config.cmake)\n"
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/yalantinglibsConfig.cmake"
DESTINATION ${ConfigPackageLocation})

install(FILES "${yaLanTingLibs_SOURCE_DIR}/cmake/config.cmake"
DESTINATION ${ConfigPackageLocation}
)

install(EXPORT yalantinglibsTargets
FILE yalantinglibsConfig.cmake
FILE yalantinglibsConfigImpl.cmake
NAMESPACE yalantinglibs::
DESTINATION ${ConfigPackageLocation}
)
Expand All @@ -43,4 +56,5 @@ if (INSTALL_THIRDPARTY)
$<INSTALL_INTERFACE:include/ylt/thirdparty>
)
endif()
endif()
endif()
message(STATUS "--------------------------------------------")
5 changes: 4 additions & 1 deletion cmake/subdir.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
message(STATUS "-------------YLT PROJECT SETTING------------")

file(GLOB children src/*)

foreach(child ${children})
Expand Down Expand Up @@ -40,4 +42,5 @@ foreach(child ${children})
endforeach()
if (BUILD_STRUCT_PB)
add_subdirectory(src/struct_pb)
endif()
endif()
message(STATUS "--------------------------------------------")
Loading
Loading