소스 검색

cppdap: Build as part of CMake or use external installation

Add `cm3p/` headers to use the selected copy of the library.

Co-authored-by: Glen Chung <[email protected]>
Brad King 2 년 전
부모
커밋
5ec69eb58c

+ 23 - 2
CMakeLists.txt

@@ -131,6 +131,23 @@ if(CMake_BUILD_LTO)
   endif()
 endif()
 
+# Check whether to build cppdap.
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+  if(NOT DEFINED CMake_ENABLE_CPPDAP)
+    # cppdap does not compile everywhere.
+    if(CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin|Linux|BSD|DragonFly|CYGWIN|MSYS"
+        AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.16)
+        AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "XLClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.1)
+        )
+      set(CMake_ENABLE_CPPDAP 1)
+    else()
+      set(CMake_ENABLE_CPPDAP 0)
+    endif()
+  endif()
+else()
+  set(CMake_ENABLE_CPPDAP 0)
+endif()
+
 #-----------------------------------------------------------------------
 # a macro to deal with system libraries, implemented as a macro
 # simply to improve readability of the main script
@@ -141,7 +158,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
 
   # Allow the user to enable/disable all system utility library options by
   # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
-  set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
+  set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD)
   foreach(util IN LISTS UTILITIES)
     if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
         AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
@@ -169,6 +186,9 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
 
   # Optionally use system utility libraries.
   option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
+  if(CMake_ENABLE_CPPDAP)
+    option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}")
+  endif()
   option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
   option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
@@ -182,7 +202,8 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2"
     "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON)
   option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
-  option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
+  CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp"
+    "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON)
   option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}")
   option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}")
 

+ 16 - 0
Source/Modules/CMakeBuildUtilities.cmake

@@ -376,3 +376,19 @@ if(BUILD_CursesDialog)
     message(FATAL_ERROR "CMAKE_USE_SYSTEM_FORM in ON but CURSES_FORM_LIBRARY is not set!")
   endif()
 endif()
+
+#---------------------------------------------------------------------
+# Build cppdap library.
+if(CMake_ENABLE_CPPDAP)
+  if(CMAKE_USE_SYSTEM_CPPDAP)
+    find_package(cppdap CONFIG)
+    if(NOT cppdap_FOUND)
+      message(FATAL_ERROR
+        "CMAKE_USE_SYSTEM_CPPDAP is ON but a cppdap is not found!")
+    endif()
+  else()
+    add_subdirectory(Utilities/cmcppdap)
+    add_library(cppdap::cppdap ALIAS cmcppdap)
+    CMAKE_SET_TARGET_FOLDER(cppdap "Utilities/3rdParty")
+  endif()
+endif()

+ 11 - 0
Utilities/cm3p/cppdap/dap.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/dap.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/dap.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/future.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/future.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/future.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/io.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/io.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/io.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/optional.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/optional.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/optional.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/protocol.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/protocol.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/protocol.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/session.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/session.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/session.h> // IWYU pragma: export
+#endif

+ 11 - 0
Utilities/cm3p/cppdap/types.h

@@ -0,0 +1,11 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+/* Use the cppdap library configured for CMake.  */
+#include "cmThirdParty.h"
+#ifdef CMAKE_USE_SYSTEM_CPPDAP
+#  include <dap/types.h> // IWYU pragma: export
+#else
+#  include <cmcppdap/include/dap/types.h> // IWYU pragma: export
+#endif

+ 1 - 0
Utilities/cmThirdParty.h.in

@@ -3,6 +3,7 @@
 #pragma once
 
 /* Whether CMake is using its own utility libraries.  */
+#cmakedefine CMAKE_USE_SYSTEM_CPPDAP
 #cmakedefine CMAKE_USE_SYSTEM_CURL
 #cmakedefine CMAKE_USE_SYSTEM_EXPAT
 #cmakedefine CMAKE_USE_SYSTEM_KWIML

+ 37 - 0
Utilities/cmcppdap/CMakeLists.txt

@@ -0,0 +1,37 @@
+# Disable warnings to avoid changing 3rd party code.
+if(CMAKE_CXX_COMPILER_ID MATCHES
+    "^(GNU|LCC|Clang|AppleClang|IBMClang|XLClang|XL|VisualAge|SunPro|HP|Intel|IntelLLVM|NVHPC)$")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
+elseif(CMAKE_CXX_COMPILER_ID STREQUAL "PathScale")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -woffall")
+endif()
+
+add_library(cmcppdap STATIC
+  src/content_stream.cpp
+  src/io.cpp
+  src/jsoncpp_json_serializer.cpp
+  src/network.cpp
+  src/null_json_serializer.cpp
+  src/protocol_events.cpp
+  src/protocol_requests.cpp
+  src/protocol_response.cpp
+  src/protocol_types.cpp
+  src/session.cpp
+  src/socket.cpp
+  src/typeinfo.cpp
+  src/typeof.cpp
+)
+
+target_compile_definitions(cmcppdap PRIVATE CPPDAP_JSON_JSONCPP=1)
+target_include_directories(cmcppdap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
+set_property(TARGET cmcppdap PROPERTY CXX_CLANG_TIDY "")
+set_property(TARGET cmcppdap PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
+
+target_link_libraries(cmcppdap PRIVATE JsonCpp::JsonCpp)
+if(WIN32)
+  target_link_libraries(cmcppdap PRIVATE ws2_32)
+elseif(NOT APPLE)
+  target_link_libraries(cmcppdap PRIVATE Threads::Threads)
+endif()
+
+install(FILES NOTICE DESTINATION ${CMAKE_DOC_DIR}/cmcppdap)

+ 5 - 0
Utilities/cmcppdap/NOTICE

@@ -0,0 +1,5 @@
+'cppdap' is a C++11 library implementation of the Debug Adapter Protocol.
+Version as of 2023-01-06
+Copyright Google LLC
+
+This product includes software developed at Google.

+ 1 - 1
Utilities/cmcppdap/src/jsoncpp_json_serializer.cpp

@@ -16,7 +16,7 @@
 
 #include "null_json_serializer.h"
 
-#include <json/json.h>
+#include <cm3p/json/json.h>
 #include <cstdlib>
 #include <memory>
 

+ 1 - 1
Utilities/cmcppdap/src/jsoncpp_json_serializer.h

@@ -19,7 +19,7 @@
 #include "dap/serialization.h"
 #include "dap/types.h"
 
-#include <json/forwards.h>
+#include <cm3p/json/forwards.h>
 
 namespace dap {
 namespace json {