aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 0562c1c2007faa2aea3e883d1e820bc9862c382b (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
cmake_minimum_required(VERSION "4.2.0")

project("ttwhy"
  VERSION "1.0.0"
  LANGUAGES CXX
)

include("CTest")

### System Tools

find_program(CLANG_TIDY_PATH NAMES
  "clang-tidy"
  "clang-tidy-22"
  "clang-tidy-23"
  "clang-tidy-24"
)

### System Dependencies

find_package("Threads")

### External Dependencies

include("FetchContent")

FetchContent_Declare("asio"
  GIT_REPOSITORY "https://github.com/chriskohlhoff/asio"
  GIT_TAG "asio-1-38-2"
)

FetchContent_Declare("sml"
  GIT_REPOSITORY "https://github.com/boost-ext/sml"
  GIT_TAG "v1.2.0"
)

if (BUILD_TESTING)
  FetchContent_Declare("Catch2"
    GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
    GIT_TAG "v3.16.0"
    EXCLUDE_FROM_ALL
    FIND_PACKAGE_ARGS
  )
endif()


FetchContent_MakeAvailable(
  "asio"
  "Catch2"
  "sml"
)

### asio

add_library("asio" INTERFACE)
add_library("ext::asio" ALIAS "asio")

target_include_directories("asio" SYSTEM INTERFACE
  "${asio_SOURCE_DIR}/asio/include"
)

target_link_libraries("asio" INTERFACE
  "Threads::Threads"
)

### Core Library

add_library("ttwhy-core")
add_library("ttwhy::lib" ALIAS "ttwhy-core")

target_sources("ttwhy-core" PUBLIC
  FILE_SET CXX_MODULES
  FILES

  "ttwhy/lib.cppm"

  "ttwhy/core/mod.cppm"
  "ttwhy/core/concepts.cppm"

  "ttwhy/terminal/mod.cppm"
  "ttwhy/terminal/echo.cppm"
  "ttwhy/terminal/events.cppm"
  "ttwhy/terminal/policies.cppm"
  "ttwhy/terminal/readers.cppm"
  "ttwhy/terminal/scanner.cppm"
  "ttwhy/terminal/scoped_attributes.cppm"
  "ttwhy/terminal/signal_handling.cppm"
)


target_compile_features("ttwhy-core" PUBLIC
  "cxx_std_23"
)

target_link_libraries("ttwhy-core" PUBLIC
  "ext::asio"
  "sml::sml"
)

target_compile_options("ttwhy-core" PUBLIC
  "$<$<CXX_COMPILER_ID:Clang,GNU>:-Wall>"
  "$<$<CXX_COMPILER_ID:Clang,GNU>:-Wextra>"
  "$<$<CXX_COMPILER_ID:Clang,GNU>:-Werror>"
  "$<$<CXX_COMPILER_ID:Clang,GNU>:-pedantic-errors>"
)

if(CLANG_TIDY_PATH)
  set_target_properties("ttwhy-core" PROPERTIES
    CXX_CLANG_TIDY "${CLANG_TIDY_PATH}"
  )
else()
  message(AUTHOR_WARNING
    "clang-tidy not found; skipping linting for 'ttwhy::core'"
  )
endif()

### Applications

add_executable("ttwhy-echo")
add_executable("ttwhy::echo" ALIAS "ttwhy-echo")

target_sources("ttwhy-echo" PRIVATE
  "apps/echo.cpp"
)

target_link_libraries("ttwhy-echo" PRIVATE
  "ttwhy::lib"
)

if(CLANG_TIDY_PATH)
  set_target_properties("ttwhy-echo" PROPERTIES
    CXX_CLANG_TIDY "${CLANG_TIDY_PATH}"
  )
else()
  message(AUTHOR_WARNING
    "clang-tidy not found; skipping linting for 'ttwhy::echo'"
  )
endif()

### Tests

if(BUILD_TESTING)
  find_package("Catch2")

  include("Catch")

  add_executable("ttwhy-tests")
  add_executable("ttwhy::tests" ALIAS "ttwhy-tests")

  target_sources("ttwhy-tests" PRIVATE
    "ttwhy/terminal/echo.tests.cpp"
    "ttwhy/terminal/scanner.tests.cpp"
  )

  target_link_libraries("ttwhy-tests" PRIVATE
    "ttwhy::lib"
    "Catch2::Catch2WithMain"
  )

  catch_discover_tests("ttwhy-tests")
endif()