Echo Writes Code

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
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
include(CrucibleAddLibrary)
include(CrucibleAddTest)

# This is a special step for core only: we supply a header file containing preprocessor definitions for platform
# features we detected during configuration, so that we don't end up with a huge target_compile_definitions()
configure_file(
  "${CMAKE_CURRENT_SOURCE_DIR}/include/crucible/core/target_platform.hpp.in"
  "${CMAKE_CURRENT_BINARY_DIR}/include/crucible/core/target_platform.hpp"
  NEWLINE_STYLE UNIX)

crucible_add_library(crucible-core)

# Also a special step for core only: we add CMAKE_CURRENT_BINARY_DIR to our include search path in
# order to find generated files, such as target_platform.hpp
target_include_directories(crucible-core PUBLIC
  "${CMAKE_CURRENT_BINARY_DIR}/include"
  "${CMAKE_CURRENT_SOURCE_DIR}/include")

target_sources(crucible-core PRIVATE
  source/crucible/core/assert.cpp
  source/crucible/core/backtrace.cpp
  source/crucible/core/filesystem.cpp
  source/crucible/core/format.cpp
  source/crucible/core/none.cpp
  source/crucible/core/stack_frame.cpp
  source/crucible/core/string.cpp
  source/crucible/core/terminate_handler.cpp
  source/crucible/core/unsafe.cpp)

if(UNIX)
  target_compile_definitions(crucible-core PUBLIC
    CRUCIBLE_UNIX)

  target_sources(crucible-core PRIVATE
    source/crucible/core/unix/backtrace.cpp
    source/crucible/core/unix/demangle.cpp
    source/crucible/core/unix/filesystem.cpp
    source/crucible/core/unix/system_error.cpp)
endif()

if(WIN32)
  target_compile_definitions(crucible-core PUBLIC
    CRUCIBLE_WINDOWS

    # <Windows.h> defines macros called `min()` and `max()`... which shadow any functions named `min()` or `max()` :S
    NOMINMAX

    # One of these is for the Windows API, and the other is for the C standard library
    _UNICODE
    UNICODE

    # Hopefully speed up the build a bit
    WIN32_LEAN_AND_MEAN)

  target_link_libraries(crucible-core PUBLIC
    # Provides stack-walking and address-to-source-location conversion
    dbghelp)

  target_sources(crucible-core PRIVATE
    source/crucible/core/windows/backtrace.cpp
    source/crucible/core/windows/filesystem.cpp
    source/crucible/core/windows/system_error.cpp
    source/crucible/core/windows/transcoding.cpp)
endif()

crucible_add_test(test-crucible-core)

target_link_libraries(test-crucible-core PRIVATE
  crucible-core
  crucible-test)

target_sources(test-crucible-core PRIVATE
  tests/crucible/core/test_error.cpp
  tests/crucible/core/test_format.cpp
  tests/crucible/core/test_functional.cpp
  tests/crucible/core/test_memory.cpp
  tests/crucible/core/test_result.cpp
  tests/crucible/core/test_slice.cpp
  tests/crucible/core/test_string.cpp
  tests/crucible/core/test_vector.cpp
  tests/main.cpp)

if(UNIX)
  target_sources(test-crucible-core PRIVATE
    tests/crucible/core/unix/test_backtrace.cpp
    tests/crucible/core/unix/test_filesystem.cpp)
endif()

if(WIN32)
  target_sources(test-crucible-core PRIVATE
    tests/crucible/core/windows/test_backtrace.cpp
    tests/crucible/core/windows/test_filesystem.cpp
    tests/crucible/core/windows/test_transcoding.cpp)
endif()