Skip to content

Commit 2dfd154

Browse files
committed
Initial drop of cppdap
0 parents  commit 2dfd154

51 files changed

Lines changed: 9924 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
BasedOnStyle: Chromium

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
.vs/
3+
.vscode/settings.json
4+
CMakeSettings.json

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "third_party/json"]
2+
path = third_party/json
3+
url = https://github.com/nlohmann/json.git
4+
[submodule "third_party/googletest"]
5+
path = third_party/googletest
6+
url = https://github.com/google/googletest.git

.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/third_party/json/include",
8+
"${workspaceFolder}/third_party/googletest/googlemock/include"
9+
],
10+
"defines": [],
11+
"compilerPath": "/usr/bin/gcc",
12+
"cStandard": "c11",
13+
"cppStandard": "c++17",
14+
"intelliSenseMode": "clang-x64"
15+
}
16+
],
17+
"version": 4
18+
}

.vscode/launch.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "cppdap: hello_debugger",
9+
"type": "hello_debugger",
10+
"request": "launch"
11+
},
12+
{
13+
"type": "lldb",
14+
"request": "launch",
15+
"name": "unittests (lldb)",
16+
"program": "${workspaceFolder}/build/dap-unittests",
17+
"cwd": "${workspaceRoot}",
18+
},
19+
{
20+
"name": "unittests (gdb)",
21+
"type": "cppdbg",
22+
"request": "launch",
23+
"program": "${workspaceFolder}/build/dap-unittests",
24+
"args": [],
25+
"stopAtEntry": false,
26+
"cwd": "${workspaceFolder}",
27+
"environment": [],
28+
"externalConsole": false,
29+
"MIMode": "gdb",
30+
"setupCommands": [
31+
{
32+
"description": "Enable pretty-printing for gdb",
33+
"text": "-enable-pretty-printing",
34+
"ignoreFailures": true
35+
}
36+
]
37+
}
38+
]
39+
}

.vscode/tasks.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "make",
8+
"group": {
9+
"kind": "build",
10+
"isDefault": true
11+
},
12+
"type": "shell",
13+
"command": "sh",
14+
"osx": {
15+
"args": [
16+
"-c",
17+
"cmake --build . && echo Done"
18+
]
19+
},
20+
"linux": {
21+
"args": [
22+
"-c",
23+
"cmake --build . && echo Done"
24+
]
25+
},
26+
"windows": {
27+
"args": [
28+
"-c",
29+
"cmake --build . && echo Done"
30+
]
31+
},
32+
"options": {
33+
"cwd": "${workspaceRoot}/build",
34+
},
35+
"presentation": {
36+
"echo": false,
37+
"reveal": "always",
38+
"focus": false,
39+
"panel": "shared",
40+
"showReuseMessage": false,
41+
"clear": true,
42+
},
43+
"problemMatcher": {
44+
"owner": "cpp",
45+
"fileLocation": "absolute",
46+
"pattern": {
47+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
48+
"file": 1,
49+
"line": 2,
50+
"column": 3,
51+
"severity": 4,
52+
"message": 5
53+
}
54+
}
55+
},
56+
{
57+
"label": "cmake",
58+
"type": "shell",
59+
"command": "sh",
60+
"args": [
61+
"-c",
62+
"mkdir build; cd build; cmake .. -GNinja -DCMAKE_BUILD_TYPE=${input:buildType} -DCPPDAP_BUILD_TESTS=1 -DCPPDAP_BUILD_EXAMPLES=1 -DCPPDAP_INSTALL_VSCODE_EXAMPLES=1 -DCPPDAP_WARNINGS_AS_ERRORS=1",
63+
],
64+
"options": {
65+
"cwd": "${workspaceRoot}"
66+
},
67+
"problemMatcher": [],
68+
},
69+
],
70+
"inputs": [
71+
{
72+
"id": "buildType",
73+
"type": "pickString",
74+
"options": [
75+
"Debug",
76+
"Release",
77+
"MinSizeRel",
78+
"RelWithDebInfo",
79+
],
80+
"default": "Debug",
81+
"description": "The type of build",
82+
},
83+
]
84+
}

CMakeLists.txt

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
cmake_minimum_required(VERSION 2.8)
17+
18+
set (CMAKE_CXX_STANDARD 11)
19+
20+
project(cppdap C CXX)
21+
22+
###########################################################
23+
# Options
24+
###########################################################
25+
option(CPPDAP_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
26+
option(CPPDAP_BUILD_EXAMPLES "Build example applications" OFF)
27+
option(CPPDAP_BUILD_TESTS "Build tests" OFF)
28+
option(CPPDAP_ASAN "Build dap with address sanitizer" OFF)
29+
option(CPPDAP_MSAN "Build dap with memory sanitizer" OFF)
30+
option(CPPDAP_TSAN "Build dap with thread sanitizer" OFF)
31+
option(CPPDAP_INSTALL_VSCODE_EXAMPLES "Build and install dap examples into vscode extensions directory" OFF)
32+
option(CPPDAP_INSTALL "Create dap install target" OFF)
33+
34+
###########################################################
35+
# Directories
36+
###########################################################
37+
set(CPPDAP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
38+
set(CPPDAP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
39+
set(CPPDAP_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
40+
set(JSON_DIR ${CPPDAP_THIRD_PARTY_DIR}/json)
41+
set(GOOGLETEST_DIR ${CPPDAP_THIRD_PARTY_DIR}/googletest)
42+
43+
###########################################################
44+
# Submodules
45+
###########################################################
46+
if(CPPDAP_BUILD_TESTS)
47+
if(NOT EXISTS ${CPPDAP_THIRD_PARTY_DIR}/googletest/.git)
48+
message(WARNING "third_party/googletest submodule missing.")
49+
message(WARNING "Run: `git submodule update --init` to build tests.")
50+
set(CPPDAP_BUILD_TESTS OFF)
51+
endif()
52+
endif(CPPDAP_BUILD_TESTS)
53+
54+
###########################################################
55+
# File lists
56+
###########################################################
57+
set(CPPDAP_LIST
58+
${CPPDAP_SRC_DIR}/content_stream.cpp
59+
${CPPDAP_SRC_DIR}/io.cpp
60+
${CPPDAP_SRC_DIR}/json_serializer.cpp
61+
${CPPDAP_SRC_DIR}/network.cpp
62+
${CPPDAP_SRC_DIR}/protocol_events.cpp
63+
${CPPDAP_SRC_DIR}/protocol_requests.cpp
64+
${CPPDAP_SRC_DIR}/protocol_response.cpp
65+
${CPPDAP_SRC_DIR}/protocol_types.cpp
66+
${CPPDAP_SRC_DIR}/session.cpp
67+
${CPPDAP_SRC_DIR}/socket.cpp
68+
${CPPDAP_SRC_DIR}/typeof.cpp
69+
)
70+
71+
###########################################################
72+
# OS libraries
73+
###########################################################
74+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
75+
set(CPPDAP_OS_LIBS WS2_32)
76+
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
77+
set(CPPDAP_OS_LIBS pthread)
78+
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
79+
set(CPPDAP_OS_LIBS)
80+
endif()
81+
82+
###########################################################
83+
# Functions
84+
###########################################################
85+
function(cppdap_set_target_options target)
86+
# Enable all warnings
87+
if(MSVC)
88+
target_compile_options(${target} PRIVATE "-W4")
89+
else()
90+
target_compile_options(${target} PRIVATE "-Wall")
91+
endif()
92+
93+
# Disable specific, pedantic warnings
94+
if(MSVC)
95+
target_compile_options(${target} PRIVATE "-D_CRT_SECURE_NO_WARNINGS")
96+
endif()
97+
98+
# Treat all warnings as errors
99+
if(CPPDAP_WARNINGS_AS_ERRORS)
100+
if(MSVC)
101+
target_compile_options(${target} PRIVATE "/WX")
102+
else()
103+
target_compile_options(${target} PRIVATE "-Werror")
104+
endif()
105+
endif(CPPDAP_WARNINGS_AS_ERRORS)
106+
107+
if(CPPDAP_ASAN)
108+
target_compile_options(${target} PUBLIC "-fsanitize=address")
109+
target_link_libraries(${target} "-fsanitize=address")
110+
elseif(CPPDAP_MSAN)
111+
target_compile_options(${target} PUBLIC "-fsanitize=memory")
112+
target_link_libraries(${target} "-fsanitize=memory")
113+
elseif(CPPDAP_TSAN)
114+
target_compile_options(${target} PUBLIC "-fsanitize=thread")
115+
target_link_libraries(${target} "-fsanitize=thread")
116+
endif()
117+
118+
# Error on undefined symbols
119+
# if(NOT MSVC)
120+
# target_compile_options(${target} PRIVATE "-Wl,--no-undefined")
121+
# endif()
122+
123+
target_include_directories(${target} PRIVATE ${CPPDAP_INCLUDE_DIR})
124+
endfunction(cppdap_set_target_options)
125+
126+
###########################################################
127+
# Targets
128+
###########################################################
129+
130+
# dap
131+
add_library(cppdap STATIC ${CPPDAP_LIST})
132+
set_target_properties(cppdap PROPERTIES
133+
POSITION_INDEPENDENT_CODE 1
134+
)
135+
136+
target_include_directories(cppdap PRIVATE "${JSON_DIR}/include/")
137+
138+
cppdap_set_target_options(cppdap)
139+
140+
target_link_libraries(cppdap "${CPPDAP_OS_LIBS}")
141+
142+
# install
143+
if(CPPDAP_INSTALL)
144+
include(GNUInstallDirs)
145+
146+
install(DIRECTORY ${CPPDAP_INCLUDE_DIR}/cppdap
147+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
148+
USE_SOURCE_PERMISSIONS
149+
)
150+
151+
install(TARGETS cppdap
152+
EXPORT cppdap-targets
153+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
154+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
155+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
156+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
157+
)
158+
159+
install(EXPORT cppdap-targets
160+
FILE cppdap-config.cmake
161+
NAMESPACE cppdap::
162+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cppdap
163+
)
164+
endif(CPPDAP_INSTALL)
165+
166+
# tests
167+
if(CPPDAP_BUILD_TESTS)
168+
set(DAP_TEST_LIST
169+
${CPPDAP_SRC_DIR}/any_test.cpp
170+
${CPPDAP_SRC_DIR}/chan_test.cpp
171+
${CPPDAP_SRC_DIR}/content_stream_test.cpp
172+
${CPPDAP_SRC_DIR}/dap_test.cpp
173+
${CPPDAP_SRC_DIR}/json_serializer_test.cpp
174+
${CPPDAP_SRC_DIR}/network_test.cpp
175+
${CPPDAP_SRC_DIR}/optional_test.cpp
176+
${CPPDAP_SRC_DIR}/session_test.cpp
177+
${CPPDAP_SRC_DIR}/variant_test.cpp
178+
${GOOGLETEST_DIR}/googletest/src/gtest-all.cc
179+
)
180+
181+
set(DAP_TEST_INCLUDE_DIR
182+
${GOOGLETEST_DIR}/googlemock/include/
183+
${GOOGLETEST_DIR}/googletest/
184+
${GOOGLETEST_DIR}/googletest/include/
185+
${JSON_DIR}/include/
186+
)
187+
188+
add_executable(cppdap-unittests ${DAP_TEST_LIST})
189+
190+
set_target_properties(cppdap-unittests PROPERTIES
191+
INCLUDE_DIRECTORIES "${DAP_TEST_INCLUDE_DIR}"
192+
FOLDER "Tests"
193+
)
194+
195+
if(MSVC)
196+
# googletest emits warning C4244: 'initializing': conversion from 'double' to 'testing::internal::BiggestInt', possible loss of data
197+
target_compile_options(cppdap-unittests PRIVATE "/wd4244")
198+
endif()
199+
200+
cppdap_set_target_options(cppdap-unittests)
201+
202+
target_link_libraries(cppdap-unittests cppdap "${CPPDAP_OS_LIBS}")
203+
endif(CPPDAP_BUILD_TESTS)
204+
205+
# examples
206+
if(CPPDAP_BUILD_EXAMPLES)
207+
function(build_example target)
208+
add_executable(${target} "${CMAKE_CURRENT_SOURCE_DIR}/examples/${target}.cpp")
209+
set_target_properties(${target} PROPERTIES
210+
FOLDER "Examples"
211+
)
212+
cppdap_set_target_options(${target})
213+
target_link_libraries(${target} cppdap "${CPPDAP_OS_LIBS}")
214+
215+
if(CPPDAP_INSTALL_VSCODE_EXAMPLES)
216+
set(extroot "$ENV{HOME}/.vscode/extensions")
217+
if(EXISTS ${extroot})
218+
set(extdir "${extroot}/google.cppdap-example-${target}-1.0.0")
219+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/examples/vscode/package.json ${extdir}/package.json)
220+
add_custom_command(TARGET ${target}
221+
POST_BUILD
222+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> ${extdir})
223+
else()
224+
message(WARNING "Could not install vscode example extension as '${extroot}' does not exist")
225+
endif()
226+
endif(CPPDAP_INSTALL_VSCODE_EXAMPLES)
227+
endfunction(build_example)
228+
229+
build_example(hello_debugger)
230+
231+
endif(CPPDAP_BUILD_EXAMPLES)

0 commit comments

Comments
 (0)