-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
135 lines (119 loc) · 3.2 KB
/
CMakeLists.txt
File metadata and controls
135 lines (119 loc) · 3.2 KB
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
cmake_minimum_required(VERSION 4.0)
project(oly VERSION 0.2.0 LANGUAGES C CXX)
# compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_EXPORT_COMPILE_COMMANDS) # symlink in /build
add_custom_target(link_compile_commands ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_SOURCE_DIR}/build/compile_commands.json
)
endif()
################
# dependencies #
################
include(FetchContent)
FetchContent_Declare(
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG master
)
FetchContent_MakeAvailable(yaml-cpp)
# treesitter
FetchContent_Declare(
tree-sitter
GIT_REPOSITORY https://github.com/tree-sitter/tree-sitter.git
GIT_TAG master
)
# Grammars
FetchContent_Declare(
ts-latex
GIT_REPOSITORY https://github.com/latex-lsp/tree-sitter-latex.git
GIT_TAG master
)
FetchContent_Declare(
ts-typst
GIT_REPOSITORY https://github.com/uben0/tree-sitter-typst
GIT_TAG master
)
FetchContent_MakeAvailable(tree-sitter ts-latex ts-typst)
message(STATUS "Generating Tree-sitter LaTeX parser...")
add_custom_command(
OUTPUT
${ts-latex_SOURCE_DIR}/src/parser.c
${ts-latex_SOURCE_DIR}/src/scanner.c
COMMAND tree-sitter generate
WORKING_DIRECTORY ${ts-latex_SOURCE_DIR}
DEPENDS
${ts-latex_SOURCE_DIR}/grammar.js
COMMENT "Generating Tree-sitter LaTeX parser"
)
add_custom_target(ts_latex_gen
DEPENDS
${ts-latex_SOURCE_DIR}/src/parser.c
${ts-latex_SOURCE_DIR}/src/scanner.c
)
# disable warnings for these files
set(TS_NOISY_SOURCES
${ts-latex_SOURCE_DIR}/src/parser.c
${ts-latex_SOURCE_DIR}/src/scanner.c
${ts-typst_SOURCE_DIR}/src/parser.c
${ts-typst_SOURCE_DIR}/src/scanner.c
)
if(MSVC)
set_source_files_properties(${TS_NOISY_SOURCES} PROPERTIES COMPILE_FLAGS "/w")
else()
set_source_files_properties(${TS_NOISY_SOURCES} PROPERTIES COMPILE_FLAGS "-w")
endif()
# get latest commit hash
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
##############
# executable #
##############
set(SOURCES
src/main.cpp
src/log.cpp
src/config.cpp
src/contest.cpp
src/utils.cpp
src/cmds/add.cpp
src/cmds/alias.cpp
src/cmds/command.cpp
src/cmds/default.cpp
src/cmds/edit.cpp
src/cmds/generate.cpp
src/cmds/get_cmd.cpp
src/cmds/list.cpp
src/cmds/remove.cpp
src/cmds/rename.cpp
src/cmds/search.cpp
src/cmds/show.cpp
)
add_executable(oly ${SOURCES})
add_dependencies(oly ts_latex_gen)
target_compile_definitions(oly PRIVATE
OLY_NAME="${PROJECT_NAME}"
OLY_VERSION="${PROJECT_VERSION}"
OLY_BUILD_TYPE="$<CONFIG>"
OLY_COMMIT_HASH="${GIT_COMMIT_HASH}"
)
target_compile_features(oly PRIVATE cxx_std_26)
target_compile_options(oly PRIVATE -Wall -Wextra -Wpedantic)
target_sources(oly PRIVATE
${ts-latex_SOURCE_DIR}/src/parser.c
${ts-latex_SOURCE_DIR}/src/scanner.c
${ts-typst_SOURCE_DIR}/src/parser.c
${ts-typst_SOURCE_DIR}/src/scanner.c
)
target_include_directories(oly PRIVATE
${PROJECT_SOURCE_DIR}/include
${tree-sitter_SOURCE_DIR}/lib/include
${ts-latex_SOURCE_DIR}/src
${ts-typst_SOURCE_DIR}/src
)
target_link_libraries(oly PRIVATE tree-sitter yaml-cpp)