cmake: use UVW_ to avoid polluting parent projects

This commit is contained in:
Michele Caini 2024-10-18 15:09:24 +02:00
parent 4d54eb946f
commit fb2f8d9eff
12 changed files with 109 additions and 103 deletions

View File

@ -10,12 +10,12 @@ jobs:
strategy: strategy:
matrix: matrix:
mode: [-DBUILD_UVW_SHARED_LIB=ON, -DBUILD_UVW_LIBS=ON, -DBUILD_UVW_LIBS=OFF] mode: [-DUVW_BUILD_SHARED_LIB=ON, -DUVW_BUILD_LIBS=ON, -DUVW_BUILD_LIBS=OFF]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Compile tests - name: Compile tests
working-directory: build working-directory: build
run: | run: |
cmake ${{ matrix.mode }} -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF .. cmake ${{ matrix.mode }} -DUVW_BUILD_TESTING=ON -Dlibuv_buildtests=OFF ..
make -j2 make -j2

View File

@ -16,7 +16,7 @@ jobs:
- { pkg: clang, exe: 'clang++', version: 9 } - { pkg: clang, exe: 'clang++', version: 9 }
- { pkg: clang, exe: 'clang++', version: 10 } - { pkg: clang, exe: 'clang++', version: 10 }
- { pkg: clang, exe: 'clang++', version: 11 } - { pkg: clang, exe: 'clang++', version: 11 }
mode: [-DBUILD_UVW_SHARED_LIB=ON, -DBUILD_UVW_LIBS=ON, -DBUILD_UVW_LIBS=OFF] mode: [-DUVW_BUILD_SHARED_LIB=ON, -DUVW_BUILD_LIBS=ON, -DUVW_BUILD_LIBS=OFF]
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04

View File

@ -15,7 +15,7 @@ jobs:
- { pkg: clang, exe: 'clang++', version: 12 } - { pkg: clang, exe: 'clang++', version: 12 }
- { pkg: clang, exe: 'clang++', version: 13 } - { pkg: clang, exe: 'clang++', version: 13 }
- { pkg: clang, exe: 'clang++', version: 14 } - { pkg: clang, exe: 'clang++', version: 14 }
mode: [-DBUILD_UVW_SHARED_LIB=ON, -DBUILD_UVW_LIBS=ON, -DBUILD_UVW_LIBS=OFF] mode: [-DUVW_BUILD_SHARED_LIB=ON, -DUVW_BUILD_LIBS=ON, -DUVW_BUILD_LIBS=OFF]
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -11,12 +11,12 @@ jobs:
strategy: strategy:
matrix: matrix:
generator: [Visual Studio 17 2022] generator: [Visual Studio 17 2022]
mode: [-DBUILD_UVW_SHARED_LIB=ON, -DBUILD_UVW_LIBS=ON, -DBUILD_UVW_LIBS=OFF] mode: [-DUVW_BUILD_SHARED_LIB=ON, -DUVW_BUILD_LIBS=ON, -DUVW_BUILD_LIBS=OFF]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Compile tests - name: Compile tests
working-directory: build working-directory: build
run: | run: |
cmake -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE ${{ matrix.mode }} -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -DCMAKE_CXX_FLAGS=/W1 -G"${{ matrix.generator }}" .. cmake -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE ${{ matrix.mode }} -DUVW_BUILD_TESTING=ON -Dlibuv_buildtests=OFF -DCMAKE_CXX_FLAGS=/W1 -G"${{ matrix.generator }}" ..
cmake --build . -j 2 cmake --build . -j 2

View File

@ -16,7 +16,7 @@ jobs:
CXXFLAGS: "-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline" CXXFLAGS: "-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
CXX: g++ CXX: g++
run: | run: |
cmake -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF .. cmake -DUVW_BUILD_TESTING=ON -Dlibuv_buildtests=OFF ..
make -j4 make -j4
- name: Run tests - name: Run tests
working-directory: build working-directory: build

View File

@ -21,7 +21,7 @@ jobs:
env: env:
CXX: ${{ matrix.compiler }} CXX: ${{ matrix.compiler }}
run: | run: |
cmake ${{ matrix.mode }} -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -DUSE_${{ matrix.sanitizer }}=ON .. cmake ${{ matrix.mode }} -DUVW_BUILD_TESTING=ON -DUVW_USE_${{ matrix.sanitizer }}=ON -Dlibuv_buildtests=OFF ..
make -j2 make -j2
- name: Run tests - name: Run tests
working-directory: build working-directory: build

View File

@ -48,7 +48,7 @@ jobs:
working-directory: build working-directory: build
run: | run: |
export PATH=$PATH:${GITHUB_WORKSPACE}/build/include-what-you-use/build/bin export PATH=$PATH:${GITHUB_WORKSPACE}/build/include-what-you-use/build/bin
cmake -DBUILD_TESTING=ON \ cmake -DUVW_BUILD_TESTING=ON \
-Dlibuv_buildtests=OFF \ -Dlibuv_buildtests=OFF \
-DCMAKE_C_COMPILER=clang-$LLVM \ -DCMAKE_C_COMPILER=clang-$LLVM \
-DCMAKE_CXX_COMPILER=clang++-$LLVM \ -DCMAKE_CXX_COMPILER=clang++-$LLVM \
@ -69,7 +69,7 @@ jobs:
env: env:
CXX: clang++ CXX: clang++
run: | run: |
cmake -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -DUSE_CLANG_TIDY=ON .. cmake -DUVW_BUILD_TESTING=ON -DUVW_USE_CLANG_TIDY=ON -Dlibuv_buildtests=OFF ..
make -j4 make -j4
- name: Run tests - name: Run tests
working-directory: build working-directory: build

View File

@ -31,23 +31,23 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif() endif()
option(USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." ON) option(UVW_USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." ON)
option(USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF) option(UVW_USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF)
option(USE_UBSAN "Use address sanitizer by adding -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer flags" OFF) option(UVW_USE_UBSAN "Use address sanitizer by adding -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer flags" OFF)
option(USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF) option(UVW_USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
option(BUILD_UVW_LIBS "Prepare targets for static library rather than for a header-only library." OFF) option(UVW_BUILD_LIBS "Prepare targets for static library rather than for a header-only library." OFF)
option(BUILD_UVW_SHARED_LIB "Prepare targets for shared library rather than for a header-only library." OFF) option(UVW_BUILD_SHARED_LIB "Prepare targets for shared library rather than for a header-only library." OFF)
option(FIND_LIBUV "Try finding libuv library development files in the system" OFF) option(UVW_FIND_LIBUV "Try finding libuv library development files in the system" OFF)
if(BUILD_UVW_SHARED_LIB) if(UVW_BUILD_SHARED_LIB)
set(BUILD_UVW_LIBS BOOL:ON) set(UVW_BUILD_LIBS BOOL:ON)
endif() endif()
# #
# Compiler stuff # Compiler stuff
# #
if(NOT WIN32 AND USE_LIBCPP) if(NOT WIN32 AND UVW_USE_LIBCPP)
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CMakePushCheckState) include(CMakePushCheckState)
@ -58,34 +58,34 @@ if(NOT WIN32 AND USE_LIBCPP)
check_cxx_source_compiles(" check_cxx_source_compiles("
#include<type_traits> #include<type_traits>
int main() { return std::is_same_v<int, char>; } int main() { return std::is_same_v<int, char>; }
" HAS_LIBCPP) " UVW_HAS_LIBCPP)
if(NOT HAS_LIBCPP) if(NOT UVW_HAS_LIBCPP)
message(WARNING "The option USE_LIBCPP is set (by default) but libc++ is not available. The flag will not be added to the target.") message(WARNING "The option UVW_USE_LIBCPP is set (by default) but libc++ is not available. The flag will not be added to the target.")
endif() endif()
cmake_pop_check_state() cmake_pop_check_state()
endif() endif()
if(USE_CLANG_TIDY) if(UVW_USE_CLANG_TIDY)
find_program(CLANG_TIDY_EXECUTABLE "clang-tidy") find_program(UVW_CLANG_TIDY_EXECUTABLE "clang-tidy")
if(NOT CLANG_TIDY_EXECUTABLE) if(NOT UVW_CLANG_TIDY_EXECUTABLE)
message(VERBOSE "The option USE_CLANG_TIDY is set but clang-tidy executable is not available.") message(VERBOSE "The option UVW_USE_CLANG_TIDY is set but clang-tidy executable is not available.")
endif() endif()
endif() endif()
# Required minimal libuv version # Required minimal libuv version
set(LIBUV_VERSION 1.49.0) set(UVW_LIBUV_VERSION 1.49.0)
function(fetch_libuv) function(fetch_libuv)
if (FETCH_LIBUV) if (UVW_FETCH_LIBUV)
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
libuv libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG "v${LIBUV_VERSION}" GIT_TAG "v${UVW_LIBUV_VERSION}"
GIT_SHALLOW 1 GIT_SHALLOW 1
) )
@ -96,23 +96,24 @@ function(fetch_libuv)
add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL) add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
endif() endif()
if(BUILD_UVW_SHARED_LIB) if(UVW_BUILD_SHARED_LIB)
add_library(uv::uv-shared ALIAS uv) add_library(uv::uv-shared ALIAS uv)
set_target_properties(uv PROPERTIES POSITION_INDEPENDENT_CODE 1) set_target_properties(uv PROPERTIES POSITION_INDEPENDENT_CODE 1)
else() else()
add_library(uv::uv-static ALIAS uv_a) add_library(uv::uv-static ALIAS uv_a)
set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1) set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
endif() endif()
endif(FETCH_LIBUV) endif(UVW_FETCH_LIBUV)
endfunction() endfunction()
function(use_libuv) function(use_libuv)
set(FETCH_LIBUV_DEFAULT ON) set(UVW_FETCH_LIBUV_DEFAULT ON)
if (FIND_LIBUV)
if (UVW_FIND_LIBUV)
find_package(libuv ${LIBUV_VERSION} QUIET) find_package(libuv ${LIBUV_VERSION} QUIET)
if (libuv_FOUND) if (libuv_FOUND)
add_library(uv::uv-shared ALIAS uv) add_library(uv::uv-shared ALIAS uv)
set(FETCH_LIBUV_DEFAULT OFF) set(UVW_FETCH_LIBUV_DEFAULT OFF)
message(STATUS "libuv ${libuv_VERSION} found via cmake") message(STATUS "libuv ${libuv_VERSION} found via cmake")
else(libuv_FOUND) else(libuv_FOUND)
find_package(PkgConfig QUIET) find_package(PkgConfig QUIET)
@ -120,14 +121,15 @@ function(use_libuv)
pkg_check_modules(libuv IMPORTED_TARGET libuv>=${LIBUV_VERSION}) pkg_check_modules(libuv IMPORTED_TARGET libuv>=${LIBUV_VERSION})
if (libuv_FOUND) if (libuv_FOUND)
add_library(uv::uv-shared ALIAS PkgConfig::libuv) add_library(uv::uv-shared ALIAS PkgConfig::libuv)
set(FETCH_LIBUV_DEFAULT OFF) set(UVW_FETCH_LIBUV_DEFAULT OFF)
message(STATUS "libuv ${libuv_VERSION} found via pkg-config") message(STATUS "libuv ${libuv_VERSION} found via pkg-config")
endif(libuv_FOUND) endif(libuv_FOUND)
endif(PkgConfig_FOUND) endif(PkgConfig_FOUND)
endif(libuv_FOUND) endif(libuv_FOUND)
endif(FIND_LIBUV) endif(UVW_FIND_LIBUV)
option(UVW_FETCH_LIBUV "Fetch the libuv repo using CMake FetchContent facility" ${UVW_FETCH_LIBUV_DEFAULT})
option(FETCH_LIBUV "Fetch the libuv repo using CMake FetchContent facility" ${FETCH_LIBUV_DEFAULT})
fetch_libuv() fetch_libuv()
endfunction() endfunction()
@ -137,7 +139,7 @@ endfunction()
include(GNUInstallDirs) include(GNUInstallDirs)
if(BUILD_UVW_LIBS) if(UVW_BUILD_LIBS)
use_libuv() use_libuv()
add_subdirectory(src) add_subdirectory(src)
@ -155,25 +157,25 @@ else()
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
if(USE_ASAN) if(UVW_USE_ASAN)
target_compile_options(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>) target_compile_options(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>)
target_link_libraries(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=address>) target_link_libraries(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=address>)
endif() endif()
if(USE_UBSAN) if(UVW_USE_UBSAN)
target_compile_options(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer>) target_compile_options(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer>)
target_link_libraries(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined>) target_link_libraries(uvw INTERFACE $<$<CONFIG:Debug>:-fsanitize=undefined>)
endif() endif()
if(CLANG_TIDY_EXECUTABLE) if(UVW_CLANG_TIDY_EXECUTABLE)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};--config-file=${uvw_SOURCE_DIR}/.clang-tidy;--header-filter=${uvw_SOURCE_DIR}/src/uvw/.*") set(CMAKE_CXX_CLANG_TIDY "${UVW_CLANG_TIDY_EXECUTABLE};--config-file=${uvw_SOURCE_DIR}/.clang-tidy;--header-filter=${uvw_SOURCE_DIR}/src/uvw/.*")
endif() endif()
if(HAS_LIBCPP) if(UVW_HAS_LIBCPP)
target_compile_options(uvw BEFORE INTERFACE -stdlib=libc++) target_compile_options(uvw BEFORE INTERFACE -stdlib=libc++)
endif() endif()
file(GLOB HEADERS src/uvw/*.h src/uvw/*.hpp src/uvw/*.cpp) file(GLOB HEADERS src/uvw/*.h src/uvw/*.hpp)
endif() endif()
# #
@ -198,7 +200,7 @@ install(
# Install targets # Install targets
# #
if (BUILD_UVW_LIBS) if (UVW_BUILD_LIBS)
set_target_properties( set_target_properties(
uvw PROPERTIES uvw PROPERTIES
VERSION ${UVW_VERSION_MAJOR}.${UVW_VERSION_MINOR}.${UVW_VERSION_PATCH} VERSION ${UVW_VERSION_MAJOR}.${UVW_VERSION_MINOR}.${UVW_VERSION_PATCH}
@ -220,26 +222,26 @@ install(
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
if(FETCH_LIBUV AND BUILD_UVW_LIBS) if(UVW_FETCH_LIBUV AND UVW_BUILD_LIBS)
# libuv is only fetched when both above conditions are true # libuv is only fetched when both above conditions are true
install(DIRECTORY ${libuv_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uvw/uv/include) install(DIRECTORY ${libuv_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uvw/uv/include)
if (BUILD_UVW_SHARED_LIB) if (UVW_BUILD_SHARED_LIB)
install(TARGETS uv EXPORT uvwConfig LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/uvw) install(TARGETS uv EXPORT uvwConfig LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/uvw)
else() else()
install(TARGETS uv_a EXPORT uvwConfig ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uvw) install(TARGETS uv_a EXPORT uvwConfig ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/uvw)
endif() endif()
endif(FETCH_LIBUV AND BUILD_UVW_LIBS) endif(UVW_FETCH_LIBUV AND UVW_BUILD_LIBS)
export(EXPORT uvwConfig) export(EXPORT uvwConfig)
### Testing ### Testing
option(BUILD_TESTING "Enable testing with ctest." OFF) option(UVW_BUILD_TESTING "Enable testing with ctest." OFF)
if(BUILD_TESTING) if(UVW_BUILD_TESTING)
option(FIND_GTEST_PACKAGE "Enable finding gtest package." OFF) option(UVW_FIND_GTEST_PACKAGE "Enable finding gtest package." OFF)
if (NOT BUILD_UVW_LIBS) if (NOT UVW_BUILD_LIBS)
use_libuv() use_libuv()
endif() endif()
@ -251,9 +253,9 @@ endif()
# Documentation # Documentation
# #
option(BUILD_DOCS "Enable building with documentation." OFF) option(UVW_BUILD_DOCS "Enable building with documentation." OFF)
if(BUILD_DOCS) if(UVW_BUILD_DOCS)
find_package(Doxygen 1.10) find_package(Doxygen 1.10)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)

View File

@ -24,7 +24,7 @@
"description": "Common (non-OS specific) mode for development", "description": "Common (non-OS specific) mode for development",
"inherits": "cmake-pedantic", "inherits": "cmake-pedantic",
"cacheVariables": { "cacheVariables": {
"BUILD_TESTING": true, "UVW_BUILD_TESTING": true,
"libuv_buildtests": false "libuv_buildtests": false
} }
}, },

View File

@ -140,7 +140,7 @@ When used through `CMake`, the `uvw::uvw` target is exported for convenience.
### Static ### Static
To use `uvw` as a compiled library, set the `BUILD_UVW_LIBS` options in cmake To use `uvw` as a compiled library, set the `UVW_BUILD_LIBS` options in cmake
before including the project.<br/> before including the project.<br/>
This option triggers the generation of a targets named This option triggers the generation of a targets named
`uvw::uvw-static`. The matching version of `libuv` is also `uvw::uvw-static`. The matching version of `libuv` is also
@ -209,7 +209,7 @@ else.
To build the tests: To build the tests:
* `$ cd build` * `$ cd build`
* `$ cmake .. -DBUILD_TESTING=ON` * `$ cmake .. -DUVW_BUILD_TESTING=ON`
* `$ make` * `$ make`
* `$ ctest -j4 -R uvw` * `$ ctest -j4 -R uvw`

View File

@ -42,17 +42,17 @@ function(add_uvw_library LIB_NAME)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
if(USE_ASAN) if(UVW_USE_ASAN)
target_compile_options(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>) target_compile_options(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>)
target_link_libraries(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=address>) target_link_libraries(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=address>)
endif() endif()
if(USE_UBSAN) if(UVW_USE_UBSAN)
target_compile_options(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer>) target_compile_options(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer>)
target_link_libraries(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=undefined>) target_link_libraries(${LIB_NAME} PUBLIC $<$<CONFIG:Debug>:-fsanitize=undefined>)
endif() endif()
if(HAS_LIBCPP) if(UVW_HAS_LIBCPP)
target_compile_options(${LIB_NAME} BEFORE PUBLIC -stdlib=libc++) target_compile_options(${LIB_NAME} BEFORE PUBLIC -stdlib=libc++)
endif() endif()
endfunction() endfunction()
@ -61,7 +61,7 @@ endfunction()
# Build and install libraries # Build and install libraries
# #
if (BUILD_UVW_SHARED_LIB) if (UVW_BUILD_SHARED_LIB)
add_library(uvw SHARED) add_library(uvw SHARED)
add_library(uvw::uvw-shared ALIAS uvw) add_library(uvw::uvw-shared ALIAS uvw)
# If libuv is not fetched by ourselves, it's the caller's responsibility to make sure of the linkage. # If libuv is not fetched by ourselves, it's the caller's responsibility to make sure of the linkage.

View File

@ -7,7 +7,7 @@ include(FetchContent)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
if(FIND_GTEST_PACKAGE) if(UVW_FIND_GTEST_PACKAGE)
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
else() else()
FetchContent_Declare( FetchContent_Declare(
@ -19,18 +19,22 @@ else()
FetchContent_GetProperties(googletest) FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_Populate(googletest) FetchContent_MakeAvailable(googletest)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
add_library(GTest::Main ALIAS gtest_main) add_library(GTest::Main ALIAS gtest_main)
target_compile_features(gtest PUBLIC cxx_std_17) target_compile_features(gtest PUBLIC cxx_std_17)
set_target_properties(gtest PROPERTIES CXX_CLANG_TIDY "")
target_compile_features(gtest_main PUBLIC cxx_std_17) target_compile_features(gtest_main PUBLIC cxx_std_17)
set_target_properties(gtest_main PROPERTIES CXX_CLANG_TIDY "")
target_compile_features(gmock PUBLIC cxx_std_17) target_compile_features(gmock PUBLIC cxx_std_17)
set_target_properties(gmock PROPERTIES CXX_CLANG_TIDY "")
target_compile_features(gmock_main PUBLIC cxx_std_17) target_compile_features(gmock_main PUBLIC cxx_std_17)
set_target_properties(gmock_main PROPERTIES CXX_CLANG_TIDY "")
if(CMAKE_SYSTEM_NAME MATCHES OpenBSD) if(CMAKE_SYSTEM_NAME MATCHES OpenBSD)
target_compile_options(gtest PRIVATE -Wno-error) target_compile_options(gtest PRIVATE -Wno-error)
@ -41,7 +45,7 @@ if(WIN32)
set(WINSOCK2 ws2_32) set(WINSOCK2 ws2_32)
endif() endif()
function(ADD_UVW_TEST TEST_NAME TEST_SOURCE) function(UVW_ADD_TEST TEST_NAME TEST_SOURCE)
add_executable(${TEST_NAME} ${TEST_SOURCE}) add_executable(${TEST_NAME} ${TEST_SOURCE})
target_link_libraries( target_link_libraries(
@ -69,16 +73,16 @@ function(ADD_UVW_TEST TEST_NAME TEST_SOURCE)
add_test(NAME uvw_${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>) add_test(NAME uvw_${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>)
endfunction() endfunction()
function(ADD_UVW_DIR_TEST TEST_NAME TEST_SOURCE) function(UVW_ADD_DIR_TEST TEST_NAME TEST_SOURCE)
ADD_UVW_TEST(${TEST_NAME} ${TEST_SOURCE}) UVW_ADD_TEST(${TEST_NAME} ${TEST_SOURCE})
string(TOUPPER "${TEST_NAME}" TEST_NAME_UPPER) string(TOUPPER "${TEST_NAME}" TEST_NAME_UPPER)
set(TEST_DIR_VAR "TARGET_${TEST_NAME_UPPER}_DIR") set(TEST_DIR_VAR "TARGET_${TEST_NAME_UPPER}_DIR")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}_data) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}_data)
target_compile_definitions(${TEST_NAME} PRIVATE ${TEST_DIR_VAR}="${TEST_NAME}_data") target_compile_definitions(${TEST_NAME} PRIVATE ${TEST_DIR_VAR}="${TEST_NAME}_data")
endfunction() endfunction()
function(ADD_UVW_LIB_TEST TEST_NAME TEST_SOURCE) function(UVW_ADD_LIB_TEST TEST_NAME TEST_SOURCE)
ADD_UVW_TEST(${TEST_NAME} ${TEST_SOURCE}) UVW_ADD_TEST(${TEST_NAME} ${TEST_SOURCE})
target_link_libraries(${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(${TEST_NAME} PRIVATE ${CMAKE_DL_LIBS})
target_compile_definitions(${TEST_NAME} PRIVATE TARGET_LIB_SO="$<TARGET_FILE:fake>") target_compile_definitions(${TEST_NAME} PRIVATE TARGET_LIB_SO="$<TARGET_FILE:fake>")
endfunction() endfunction()
@ -87,39 +91,39 @@ add_library(fake SHARED fake.cpp)
# List of available targets # List of available targets
option(BUILD_DNS_TEST "Build DNS test." OFF) option(UVW_BUILD_DNS_TEST "Build DNS test." OFF)
ADD_UVW_TEST(main main.cpp) UVW_ADD_TEST(main main.cpp)
ADD_UVW_TEST(async uvw/async.cpp) UVW_ADD_TEST(async uvw/async.cpp)
ADD_UVW_TEST(check uvw/check.cpp) UVW_ADD_TEST(check uvw/check.cpp)
ADD_UVW_TEST(emitter uvw/emitter.cpp) UVW_ADD_TEST(emitter uvw/emitter.cpp)
ADD_UVW_DIR_TEST(file_req uvw/file_req.cpp) UVW_ADD_DIR_TEST(file_req uvw/file_req.cpp)
ADD_UVW_DIR_TEST(fs_event uvw/fs_event.cpp) UVW_ADD_DIR_TEST(fs_event uvw/fs_event.cpp)
ADD_UVW_DIR_TEST(fs_req uvw/fs_req.cpp) UVW_ADD_DIR_TEST(fs_req uvw/fs_req.cpp)
ADD_UVW_TEST(handle uvw/handle.cpp) UVW_ADD_TEST(handle uvw/handle.cpp)
ADD_UVW_TEST(idle uvw/idle.cpp) UVW_ADD_TEST(idle uvw/idle.cpp)
ADD_UVW_LIB_TEST(lib uvw/lib.cpp) UVW_ADD_LIB_TEST(lib uvw/lib.cpp)
ADD_UVW_TEST(loop uvw/loop.cpp) UVW_ADD_TEST(loop uvw/loop.cpp)
ADD_UVW_DIR_TEST(pipe uvw/pipe.cpp) UVW_ADD_DIR_TEST(pipe uvw/pipe.cpp)
ADD_UVW_TEST(prepare uvw/prepare.cpp) UVW_ADD_TEST(prepare uvw/prepare.cpp)
ADD_UVW_TEST(process uvw/process.cpp) UVW_ADD_TEST(process uvw/process.cpp)
ADD_UVW_TEST(request uvw/request.cpp) UVW_ADD_TEST(request uvw/request.cpp)
ADD_UVW_TEST(resource uvw/resource.cpp) UVW_ADD_TEST(resource uvw/resource.cpp)
ADD_UVW_TEST(signal uvw/signal.cpp) UVW_ADD_TEST(signal uvw/signal.cpp)
ADD_UVW_TEST(stream uvw/stream.cpp) UVW_ADD_TEST(stream uvw/stream.cpp)
ADD_UVW_TEST(tcp uvw/tcp.cpp) UVW_ADD_TEST(tcp uvw/tcp.cpp)
ADD_UVW_TEST(thread uvw/thread.cpp) UVW_ADD_TEST(thread uvw/thread.cpp)
ADD_UVW_TEST(timer uvw/timer.cpp) UVW_ADD_TEST(timer uvw/timer.cpp)
ADD_UVW_TEST(tty uvw/tty.cpp) UVW_ADD_TEST(tty uvw/tty.cpp)
ADD_UVW_TEST(udp uvw/udp.cpp) UVW_ADD_TEST(udp uvw/udp.cpp)
ADD_UVW_TEST(uv_type uvw/uv_type.cpp) UVW_ADD_TEST(uv_type uvw/uv_type.cpp)
ADD_UVW_TEST(util uvw/util.cpp) UVW_ADD_TEST(util uvw/util.cpp)
ADD_UVW_TEST(work uvw/work.cpp) UVW_ADD_TEST(work uvw/work.cpp)
if(NOT CMAKE_SYSTEM_NAME MATCHES OpenBSD) if(NOT CMAKE_SYSTEM_NAME MATCHES OpenBSD)
ADD_UVW_DIR_TEST(file_req_sendfile uvw/file_req_sendfile.cpp) UVW_ADD_DIR_TEST(file_req_sendfile uvw/file_req_sendfile.cpp)
endif() endif()
if(BUILD_DNS_TEST) if(UVW_BUILD_DNS_TEST)
ADD_UVW_TEST(dns uvw/dns.cpp) UVW_ADD_TEST(dns uvw/dns.cpp)
endif() endif()