diff --git a/CMakeLists.txt b/CMakeLists.txt index c23c5d3b..726a8b54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/config.cmake b/cmake/config.cmake index 0897702b..3f9e6917 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -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() \ No newline at end of file