export cmake option when developer use CMake FetchContent
For example, use the following cmake config ``` include(FetchContent) FetchContent_Declare( yalantinglibs GIT_REPOSITORY https://github.com/alibaba/yalantinglibs.git GIT_TAG xxx # use the least commit id GIT_SHALLOW 1 # optional ( --depth=1 ) ) FetchContent_MakeAvailable(yalantinglibs) add_executable(demo main.cpp) target_link_libraries(demo PRIVATE yalantinglibs) ``` you can use `cmake -DENABLE_STRUCT_PACK_UNPORTABLE_TYPE=ON ..`, the option `ENABLE_STRUCT_PACK_UNPORTABLE_TYPE=ON` will be used when building yalantinglibs
This commit is contained in:
parent
a920fce8b0
commit
c0e48cf1e3
|
@ -28,5 +28,8 @@ if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs") # if ylt is top-level project
|
|||
include(cmake/config.cmake)
|
||||
# add project's source such as unit test, example & benchmark
|
||||
include(cmake/subdir.cmake)
|
||||
else ()
|
||||
# add project config, such as enable_ssl.
|
||||
include(cmake/config.cmake)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -3,14 +3,23 @@ option(ENABLE_SSL "Enable ssl support" OFF)
|
|||
message(STATUS "ENABLE_SSL: ${ENABLE_SSL}")
|
||||
if (ENABLE_SSL)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
add_compile_definitions(YLT_ENABLE_SSL)
|
||||
link_libraries(OpenSSL::SSL OpenSSL::Crypto)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
|
||||
add_compile_definitions(YLT_ENABLE_SSL)
|
||||
link_libraries(OpenSSL::SSL OpenSSL::Crypto)
|
||||
else ()
|
||||
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)
|
||||
add_compile_definitions(YLT_ENABLE_PMR IGUANA_ENABLE_PMR)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
|
||||
add_compile_definitions(YLT_ENABLE_PMR IGUANA_ENABLE_PMR)
|
||||
else ()
|
||||
target_compile_definitions(yalantinglibs INTERFACE YLT_ENABLE_PMR IGUANA_ENABLE_PMR)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
option(ENABLE_IO_URING "Enable io_uring" OFF)
|
||||
|
@ -18,8 +27,13 @@ message(STATUS "ENABLE_IO_URING: ${ENABLE_IO_URING}")
|
|||
if (ENABLE_IO_URING)
|
||||
find_package(uring REQUIRED)
|
||||
message(STATUS "Use IO_URING for all I/O in linux")
|
||||
add_compile_definitions(ASIO_HAS_IO_URING ASIO_DISABLE_EPOLL ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
|
||||
link_libraries(uring)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
|
||||
add_compile_definitions(ASIO_HAS_IO_URING ASIO_DISABLE_EPOLL ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
|
||||
link_libraries(uring)
|
||||
else ()
|
||||
target_compile_definitions(yalantinglibs INTERFACE ASIO_HAS_IO_URING ASIO_DISABLE_EPOLL ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
|
||||
target_link_libraries(yalantinglibs INTERFACE uring)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
option(ENABLE_FILE_IO_URING "Enable file io_uring" OFF)
|
||||
|
@ -27,19 +41,32 @@ if (NOT ENABLE_IO_URING)
|
|||
if(ENABLE_FILE_IO_URING)
|
||||
find_package(uring REQUIRED)
|
||||
message(STATUS "Enable io_uring for file I/O in linux")
|
||||
add_compile_definitions(ASIO_HAS_IO_URING ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING)
|
||||
link_libraries(uring)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs")
|
||||
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_link_libraries(yalantinglibs INTERFACE uring)
|
||||
endif ()
|
||||
endif()
|
||||
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)
|
||||
add_compile_definitions(STRUCT_PACK_ENABLE_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 ()
|
||||
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}")
|
||||
if(ENABLE_STRUCT_PACK_OPTIMIZE)
|
||||
add_compile_definitions(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()
|
Loading…
Reference in New Issue