forked from martin-olivier/dylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
69 lines (55 loc) · 2.03 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required(VERSION 3.14)
project(dylib CXX)
if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(dylib INTERFACE)
target_include_directories(dylib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(UNIX)
target_link_libraries(dylib INTERFACE dl)
endif()
option(DYLIB_BUILD_TESTS "When set to ON, build unit tests" OFF)
option(DYLIB_WARNING_AS_ERRORS "Treat warnings as errors" OFF)
if(DYLIB_BUILD_TESTS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
find_package(googletest QUIET)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Weffc++)
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
add_compile_options(-Wall -Wextra)
elseif(MSVC)
add_compile_options(/W4)
endif()
if(DYLIB_WARNING_AS_ERRORS)
if(MSVC)
add_compile_options(/WX)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
add_compile_options(-Werror)
endif()
endif()
add_library(dynamic_lib SHARED tests/lib.cpp)
if(WIN32 AND MINGW)
set_target_properties(dynamic_lib PROPERTIES PREFIX "")
endif()
enable_testing()
if(UNIX AND NOT APPLE)
add_compile_options(-fprofile-arcs -ftest-coverage)
endif()
add_executable(unit_tests tests/tests.cpp)
add_dependencies(unit_tests dynamic_lib)
target_link_libraries(unit_tests PRIVATE gtest_main dylib)
if(UNIX AND NOT APPLE)
target_link_libraries(unit_tests PRIVATE gcov)
endif()
include(GoogleTest)
gtest_discover_tests(unit_tests PROPERTIES DISCOVERY_TIMEOUT 600 WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()