Skip to content

Commit

Permalink
Split CMakeLists.txt (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius authored Dec 27, 2024
1 parent cc800ec commit a1679fa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: build/*.xml
files: build/tests/*.xml
check_name: Unit Test Results (Linux)

windows-build:
Expand Down
75 changes: 3 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,8 @@ include(${CMAKE_BINARY_DIR}/local.cmake)
endif ()

project(netlib)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CMOCKA REQUIRED cmocka)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
pkg_check_modules(URING REQUIRED liburing)
endif ()
pkg_check_modules(OPENSSL openssl)
enable_testing()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SOURCES
coroio/socket.cpp
coroio/sockutils.cpp
coroio/poll.cpp
coroio/select.cpp
coroio/epoll.cpp
coroio/uring.cpp
coroio/kqueue.cpp
coroio/resolver.cpp
coroio/ssl.cpp
coroio/iocp.cpp
coroio/win32_pipe.cpp
)

if (WIN32)
list(APPEND SOURCES
coroio/wepoll.c
)
set_source_files_properties(coroio/wepoll.c PROPERTIES COMPILE_FLAGS "-w")
endif ()

add_library(coroio ${SOURCES})

target_include_directories(coroio PUBLIC ${URING_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS})
target_link_directories(coroio PUBLIC ${URING_LIBRARY_DIRS} ${OPENSSL_LIBRARY_DIRS})
target_link_libraries(coroio PUBLIC ${URING_LIBRARIES} ${OPENSSL_LIBRARIES})
if (WIN32)
target_link_libraries(coroio PUBLIC ws2_32)
endif()

if(MSVC)
target_compile_options(coroio PRIVATE /W4 /WX)
else()
target_compile_options(coroio PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()

macro(target name source)
add_executable(${name} ${source})
target_link_libraries(${name} coroio)
endmacro()

macro(ut name source)
add_executable(ut_${name} ${source})
target_include_directories(ut_${name} PRIVATE ${CMOCKA_INCLUDE_DIRS})
target_link_directories(ut_${name} PRIVATE ${CMOCKA_LIBRARY_DIRS})
target_link_libraries(ut_${name} PRIVATE coroio ${CMOCKA_LIBRARIES})

add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ut_${name})
set_tests_properties(${name} PROPERTIES ENVIRONMENT "CMOCKA_MESSAGE_OUTPUT=xml;CMOCKA_XML_FILE=${name}.xml")
endmacro()

target(timers examples/timers.cpp)
target(echotest examples/echotest.cpp)
target(echoserver examples/echoserver.cpp)
target(echoclient examples/echoclient.cpp)
target(sslechoclient examples/sslechoclient.cpp)
target(sslechoserver examples/sslechoserver.cpp)
target(resolver examples/resolver.cpp)
target(bench examples/bench.cpp)

ut(tests tests/tests.cpp)
add_subdirectory(coroio)
add_subdirectory(examples)
add_subdirectory(tests)
45 changes: 45 additions & 0 deletions coroio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
find_package(PkgConfig REQUIRED)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
pkg_check_modules(URING REQUIRED liburing)
endif ()
pkg_check_modules(OPENSSL openssl)

set(SOURCES
socket.cpp
sockutils.cpp
poll.cpp
select.cpp
epoll.cpp
uring.cpp
kqueue.cpp
resolver.cpp
ssl.cpp
iocp.cpp
win32_pipe.cpp
)

if (WIN32)
list(APPEND SOURCES
wepoll.c
)
set_source_files_properties(wepoll.c PROPERTIES COMPILE_FLAGS "-w")
endif ()

add_library(coroio ${SOURCES})

target_include_directories(coroio PUBLIC ${URING_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/..)

target_link_directories(coroio PUBLIC ${URING_LIBRARY_DIRS} ${OPENSSL_LIBRARY_DIRS})
target_link_libraries(coroio PUBLIC ${URING_LIBRARIES} ${OPENSSL_LIBRARIES})
if (WIN32)
target_link_libraries(coroio PUBLIC ws2_32)
endif()

if(MSVC)
target_compile_options(coroio PRIVATE /W4 /WX)
else()
target_compile_options(coroio PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()

target_compile_features(coroio PUBLIC cxx_std_20)
13 changes: 13 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
macro(target name source)
add_executable(${name} ${source})
target_link_libraries(${name} coroio)
endmacro()

target(timers timers.cpp)
target(echotest echotest.cpp)
target(echoserver echoserver.cpp)
target(echoclient echoclient.cpp)
target(sslechoclient sslechoclient.cpp)
target(sslechoserver sslechoserver.cpp)
target(resolver resolver.cpp)
target(bench bench.cpp)
16 changes: 16 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
find_package(PkgConfig REQUIRED)
pkg_check_modules(CMOCKA cmocka)

macro(ut name source)
add_executable(ut_${name} ${source})
target_include_directories(ut_${name} PRIVATE ${CMOCKA_INCLUDE_DIRS})
target_link_directories(ut_${name} PRIVATE ${CMOCKA_LIBRARY_DIRS})
target_link_libraries(ut_${name} PRIVATE coroio ${CMOCKA_LIBRARIES})

add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ut_${name})
set_tests_properties(${name} PROPERTIES ENVIRONMENT "CMOCKA_MESSAGE_OUTPUT=xml;CMOCKA_XML_FILE=${name}.xml")
endmacro()

if (CMOCKA_FOUND)
ut(tests tests.cpp)
endif ()

0 comments on commit a1679fa

Please sign in to comment.