forked from commonmark/cmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
118 lines (103 loc) · 3.73 KB
/
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
cmake_minimum_required(VERSION 3.7)
if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()
project(cmark
LANGUAGES C CXX
VERSION 0.31.0)
if(CMAKE_BUILD_TYPE MATCHES "asan|ubsan")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
include(FindAsan)
endif()
# Include module for functions
# - 'write_basic_package_version_file'
# - 'configure_package_config_file'
include(CMakePackageConfigHelpers)
include(CTest)
include(GenerateExportHeader)
include(GNUInstallDirs)
if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
include(InstallRequiredSystemLibraries)
endif()
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
endif()
# Backwards Compatibility
# TODO: remove this once there has been a period to enable people to migrate
set(_CMARK_BUILD_SHARED_LIBS_DEFAULT NO)
if(DEFINED CMARK_SHARED)
message(AUTHOR_WARNING [=[
'CMARK_SHARED' has been replaced with the standard 'BUILD_SHARED_LIBS' to control the library type.
]=])
set(_CMARK_BUILD_SHARED_LIBS_DEFAULT ${CMARK_SHARED})
endif()
if(DEFINED CMARK_STATIC)
message(AUTHOR_WARNING [=[
'CMARK_STATIC' has been replaced with the standard 'BUILD_SHARED_LIBS' to control the library type.
]=])
if(NOT CMARK_STATIC)
set(_CMARK_BUILD_SHARED_LIBS_DEFAULT YES)
else()
set(_CMARK_BUILD_SHARED_LIBS_DEFAULT NO)
endif()
endif()
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
option(BUILD_SHARED_LIBS "Build the CMark library as shared"
${_CMARK_BUILD_SHARED_LIBS_DEFAULT})
if(NOT MSVC)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS NO)
endif()
# -fvisibility=hidden
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Check integrity of node structure when compiled as debug
add_compile_options($<$<CONFIG:Debug>:-DCMARK_DEBUG_NODES>)
# In order to maintain compatibility with older platforms which may not have a
# recent version of CMake (i.e. are running CMake <3.3), we cannot simply use
# the `add_compile_options` with a generator expression. This uses the
# `target_compile_options` with `PRIVATE` to add the flags only to the targets
# so that CMark may be used in projects with non-C languages.
function(cmark_add_compile_options target)
if(MSVC)
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(${target} PRIVATE
-Wall -Wextra -pedantic
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>)
endif()
if(CMAKE_BUILD_TYPE MATCHES profile)
target_compile_options(${target} PRIVATE -pg)
endif()
if(CMAKE_BUILD_TYPE MATCHES ubsan)
target_compile_options(${target} PRIVATE -fsanitize=undefined)
endif()
if(CMARK_LIB_FUZZER)
if(target MATCHES fuzz)
target_compile_options(${target} PRIVATE -fsanitize=fuzzer)
target_link_options(${target} PRIVATE -fsanitize=fuzzer)
else()
target_compile_options(${target} PRIVATE -fsanitize=fuzzer-no-link)
target_link_options(${target} PRIVATE -fsanitize=fuzzer-no-link)
endif()
endif()
endfunction()
add_subdirectory(src)
# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
# to Windows, but defines `MINGW`.
if(BUILD_TESTING)
add_subdirectory(api_test)
endif()
if(CMARK_LIB_FUZZER)
add_subdirectory(fuzz)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
endif(NOT CMAKE_BUILD_TYPE)