Skip to content

Commit

Permalink
build: add a CMake based build
Browse files Browse the repository at this point in the history
This is meant to support building swift-markdown for re-use in the
toolchain build.  It does not follow best practices (opting for a single
file approach rather than a CMakeLists.txt per directory) and currently
needs some refinement for integrating an existing CMark build, but
provides the skeleton for further experimentation.
  • Loading branch information
compnerd committed Dec 19, 2023
1 parent c211079 commit 20e360b
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#[[
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

cmake_minimum_required(VERSION 3.19.0)

if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

project(SwiftMarkdown
LANGUAGES C Swift)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

include(FetchContent)

set(_SM_VENDOR_DEPENDENCIES)

set(BUILD_EXAMPLES NO)
set(BUILD_TESTING NO)

find_package(ArgumentParser CONFIG)
if(NOT ArgumentParser_FOUND)
FetchContent_Declare(ArgumentParser
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
GIT_TAG 1.2.3)
list(APPEND _SM_VENDOR_DEPENDENCIES ArgumentParser)
endif()

find_package(cmark-gfm CONFIG)
if(NOT cmark-gfm_FOUND)
FetchContent_Declare(cmark-gfm
GIT_REPOSITORY https://github.com/apple/swift-cmark
GIT_TAG gfm)
list(APPEND _SM_VENDOR_DEPENDENCIES cmark-gfm)
endif()

if(_SM_VENDOR_DEPENDENCIES)
FetchContent_MakeAvailable(${_SM_VENDOR_DEPENDENCIES})
endif()

add_subdirectory(Sources)

13 changes: 13 additions & 0 deletions Sources/CAtomic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[[
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(CAtomic STATIC
CAtomic.c)
target_include_directories(CAtomic PUBLIC
include)
4 changes: 4 additions & 0 deletions Sources/CAtomic/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CAtomic {
header "CAtomic.h"
export *
}
11 changes: 11 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[[
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_subdirectory(CAtomic)
add_subdirectory(Markdown)
80 changes: 80 additions & 0 deletions Sources/Markdown/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#[[
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(Markdown
Base/ChildIndexPath.swift
Base/DirectiveArgument.swift
Base/Document.swift
Base/LiteralMarkup.swift
Base/Markup.swift
Base/MarkupChildren.swift
Base/MarkupData.swift
Base/PlainTextConvertibleMarkup.swift
Base/RawMarkup.swift
"Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenParameter.swift"
"Block Nodes/Block Container Blocks/Doxygen Commands/DoxygenReturns.swift"
"Block Nodes/Block Container Blocks/BlockDirective.swift"
"Block Nodes/Block Container Blocks/BlockQuote.swift"
"Block Nodes/Block Container Blocks/CustomBlock.swift"
"Block Nodes/Block Container Blocks/ListItem.swift"
"Block Nodes/Block Container Blocks/OrderedList.swift"
"Block Nodes/Block Container Blocks/UnorderedList.swift"
"Block Nodes/Inline Container Blocks/Paragraph.swift"
"Block Nodes/Leaf Blocks/CodeBlock.swift"
"Block Nodes/Leaf Blocks/Heading.swift"
"Block Nodes/Leaf Blocks/HTMLBlock.swift"
"Block Nodes/Leaf Blocks/ThematicBreak.swift"
"Block Nodes/Tables/Table.swift"
"Block Nodes/Tables/TableBody.swift"
"Block Nodes/Tables/TableCell.swift"
"Block Nodes/Tables/TableCellContainer.swift"
"Block Nodes/Tables/TableHead.swift"
"Block Nodes/Tables/TableRow.swift"
Infrastructure/Replacement.swift
Infrastructure/SourceLocation.swift
"Inline Nodes/Inline Containers/Emphasis.swift"
"Inline Nodes/Inline Containers/Image.swift"
"Inline Nodes/Inline Containers/InlineAttributes.swift"
"Inline Nodes/Inline Containers/Link.swift"
"Inline Nodes/Inline Containers/Strikethrough.swift"
"Inline Nodes/Inline Containers/Strong.swift"
"Inline Nodes/Inline Leaves/CustomInline.swift"
"Inline Nodes/Inline Leaves/InlineCode.swift"
"Inline Nodes/Inline Leaves/InlineHTML.swift"
"Inline Nodes/Inline Leaves/LineBreak.swift"
"Inline Nodes/Inline Leaves/SoftBreak.swift"
"Inline Nodes/Inline Leaves/SymbolLink.swift"
"Inline Nodes/Inline Leaves/Text.swift"
"Interpretive Nodes/Aside.swift"
Parser/BlockDirectiveParser.swift
Parser/CommonMarkConverter.swift
Parser/LazySplitLines.swift
Parser/ParseOptions.swift
Parser/RangeAdjuster.swift
Parser/RangerTracker.swift
Rewriter/MarkupRewriter.swift
"Structural Restrictions/BasicBlockContainer.swift"
"Structural Restrictions/BasicInlineContainer.swift"
"Structural Restrictions/BlockContainer.swift"
"Structural Restrictions/BlockMarkup.swift"
"Structural Restrictions/InlineContainer.swift"
"Structural Restrictions/InlineMarkup.swift"
"Structural Restrictions/ListItemContainer.swift"
Utility/AtomicCounter.swift
Utility/CharacterExtensions.swift
Utility/CollectionExtensions.swift
Utility/StringExtensions.swift
Visitor/MarkupVisitor.swift
Walker/MarkupWalker.swift
Walker/Walkers/MarkupFormatter.swift
Walker/Walkers/MarkupTreeDumper.swift)
target_link_libraries(Markdown PRIVATE
ArgumentParser
libcmark-gfm
CAtomic)

0 comments on commit 20e360b

Please sign in to comment.