aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/CMakeLists.txt
blob: 2b5ee12eea3c2e2aa54744e044751d9c77ba44b0 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
cmake_minimum_required(VERSION "3.27.0")

project("kstd"
  DESCRIPTION "A kernel STL implementation"
  VERSION "0.0.1"
  LANGUAGES CXX
)

include("CTest")

#[============================================================================[
# External Dependencies
#]============================================================================]

include("FetchContent")

if (BUILD_TESTING)
  FetchContent_Declare(
    "Catch2"
    URL "https://github.com/catchorg/Catch2/archive/refs/tags/v3.7.1.tar.gz"
    URL_HASH "SHA256=c991b247a1a0d7bb9c39aa35faf0fe9e19764213f28ffba3109388e62ee0269c"
    EXCLUDE_FROM_ALL
    FIND_PACKAGE_ARGS
  )

  FetchContent_MakeAvailable("Catch2")

  find_package("Catch2")
  include("Catch")
endif()

#[============================================================================[
# Library
#]============================================================================]

add_library("kstd" STATIC)
add_library("kstd::lib" ALIAS "kstd")

target_sources("kstd" PRIVATE
    "src/os/error.cpp"
    "src/mutex.cpp"
    "src/vformat.cpp"
)

file(GLOB_RECURSE KSTD_HEADERS
    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    CONFIGURE_DEPENDS
    "include/kstd/*"
)

target_sources("kstd" PUBLIC
    FILE_SET HEADERS
    BASE_DIRS "include"
    FILES
    ${KSTD_HEADERS}
)

target_include_directories("kstd" PUBLIC
    "include"
)

set_target_properties("kstd" PROPERTIES
    VERIFY_INTERFACE_HEADER_SETS YES
)

if(NOT BUILD_TESTING)
    target_sources("kstd" PRIVATE
        "src/libc/stdlib.cpp"
        "src/libc/string.cpp"
    )

    set(KSTD_LIBC_SYMBOLS
        "abort"
        "strlen"
        "memcmp"
        "memcpy"
    )

    list(TRANSFORM KSTD_LIBC_SYMBOLS PREPEND "-Wl,--undefined=")

    target_link_options("kstd" INTERFACE ${KSTD_LIBC_SYMBOLS})
endif()

#[============================================================================[
# Tests
#]============================================================================]

if(BUILD_TESTING)
    add_executable("kstd_tests")
    add_executable("kstd::tests" ALIAS "kstd_tests")

    target_sources("kstd_tests" PRIVATE
        "tests/src/flat_map.cpp"
        "tests/src/format.cpp"
        "tests/src/vector.cpp"
        "tests/src/observer_ptr.cpp"
        "tests/src/os_panic.cpp"
        "tests/src/string.cpp"
    )

    target_include_directories("kstd_tests" PRIVATE
        "tests/include"
    )

    target_link_libraries("kstd_tests" PRIVATE 
        "Catch2::Catch2WithMain"
        "kstd::lib"
    )

    set_target_properties("kstd_tests" PROPERTIES
        EXCLUDE_FROM_ALL NO
    )

    if(COMMAND "enable_coverage")
        enable_coverage("kstd")
        enable_coverage("kstd_tests")
    endif()

    catch_discover_tests("kstd::tests")
endif()