|
1 | 1 | cmake_minimum_required(VERSION 3.12)
|
| 2 | + |
| 3 | +if(POLICY CMP0063) |
| 4 | + cmake_policy(SET CMP0063 NEW) |
| 5 | +endif() |
| 6 | + |
| 7 | +if(POLICY CMP0092) |
| 8 | + cmake_policy(SET CMP0092 NEW) |
| 9 | +endif() |
| 10 | + |
2 | 11 | project(cmark-gfm)
|
| 12 | +# NOTE: we cannot simply version the project due to the use of an invalid |
| 13 | +# version (the infixed `.gfm.`). |
| 14 | +set(PROJECT_VERSION 0.29.0.gfm.13) |
3 | 15 |
|
4 |
| -set(PROJECT_VERSION_MAJOR 0) |
5 |
| -set(PROJECT_VERSION_MINOR 29) |
6 |
| -set(PROJECT_VERSION_PATCH 0) |
7 |
| -set(PROJECT_VERSION_GFM 13) |
8 |
| -set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM}) |
| 16 | +set(CMAKE_C_STANDARD 99) |
| 17 | +set(CMAKE_C_STANDARD_REQUIRED YES) |
| 18 | +set(CMAKE_C_EXTENSIONS NO) |
| 19 | + |
| 20 | +set(CMAKE_C_VISIBILITY_PRESET hidden) |
| 21 | +set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) |
9 | 22 |
|
10 |
| -include("FindAsan.cmake") |
11 |
| -include("CheckFileOffsetBits.cmake") |
| 23 | +set(CMAKE_INCLUDE_CURRENT_DIR YES) |
| 24 | + |
| 25 | +option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF) |
| 26 | +option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF) |
| 27 | +option(CMARK_THREADING "Add locks around static accesses" OFF) |
12 | 28 |
|
13 | 29 | if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
14 | 30 | message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
|
15 | 31 | endif()
|
| 32 | +if(NOT CMAKE_BUILD_TYPE) |
| 33 | + set(CMAKE_BUILD_TYPE "Release" CACHE STRING |
| 34 | + "Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE) |
| 35 | +endif(NOT CMAKE_BUILD_TYPE) |
16 | 36 |
|
17 |
| -option(CMARK_TESTS "Build cmark-gfm tests and enable testing" ON) |
18 |
| -option(CMARK_STATIC "Build static libcmark-gfm library" ON) |
19 |
| -option(CMARK_SHARED "Build shared libcmark-gfm library" ON) |
20 |
| -option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF) |
21 |
| -option(CMARK_THREADING "Add locks around static accesses" OFF) |
| 37 | +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) |
| 38 | + |
| 39 | +include(CheckFileOffsetBits) |
| 40 | +include(CTest) |
| 41 | +include(FindAsan) |
| 42 | +if(CMARK_THREADING) |
| 43 | + set(THREADS_PREFER_PTHREAD_FLAG YES) |
| 44 | + include(FindThreads) |
| 45 | + add_compile_definitions(CMARK_THREADING) |
| 46 | +endif() |
| 47 | +include(GNUInstallDirs) |
| 48 | + |
| 49 | +if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) |
| 50 | + set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) |
| 51 | + include(InstallRequiredSystemLibraries) |
| 52 | +endif() |
22 | 53 |
|
23 |
| -# set a required C standard so we can load stdbool.h |
24 | 54 | if(MSVC)
|
25 |
| - set(CMAKE_C_STANDARD 11) |
26 |
| -else() |
27 |
| - set(CMAKE_C_STANDARD 99) |
| 55 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>) |
| 56 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/WX>) |
| 57 | + # FIXME(compnerd) why do we diverge from upstream? |
| 58 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd5105>) |
| 59 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>) |
| 60 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4221>) |
| 61 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4204>) |
| 62 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4100>) |
| 63 | + add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_CRT_SECURE_NO_WARNINGS>) |
| 64 | +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang) |
| 65 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>) |
| 66 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>) |
| 67 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-unused-parameter>) |
| 68 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>) |
28 | 69 | endif()
|
29 |
| -set(CMAKE_C_STANDARD_REQUIRED YES) |
30 | 70 |
|
31 |
| -# Use CMake's generated headers instead of the Swift package prebuilt ones |
32 |
| -add_compile_definitions(CMARK_USE_CMAKE_HEADERS) |
| 71 | +if(CMAKE_BUILD_TYPE STREQUAL "Ubsan") |
| 72 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>) |
| 73 | +endif() |
33 | 74 |
|
34 |
| -option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF) |
| 75 | +# Check integrity of node structure when compiled as debug |
| 76 | +add_compile_definitions($<$<CONFIG:Debug>:CMARK_DEBUG_NODES>) |
| 77 | +# FIXME(compnerd) why do we not use `!defined(NDEBUG)`? |
| 78 | +add_compile_definitions($<$<CONFIG:Debug>:DEBUG>) |
| 79 | + |
| 80 | +add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>) |
| 81 | + |
| 82 | +if(CMARK_LIB_FUZZER) |
| 83 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>) |
| 84 | +endif() |
35 | 85 |
|
36 | 86 | if(CMARK_FUZZ_QUADRATIC)
|
37 |
| - set(FUZZER_FLAGS "-fsanitize=fuzzer-no-link,address -g") |
38 |
| - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_FLAGS}") |
39 |
| - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_FLAGS}") |
40 |
| - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_FLAGS}") |
41 |
| - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FUZZER_FLAGS}") |
| 87 | + # FIXME(compnerd) why do we enable debug information? |
| 88 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>) |
| 89 | + # FIXME(compnerd) why do we use fuzzer-no-link with a custom variable for the |
| 90 | + # runtime rather than `-fsanitize=fuzzer,address`? |
| 91 | + add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=fuzzer-no-link,address>) |
| 92 | + add_link_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=address>) |
42 | 93 | endif()
|
43 | 94 |
|
| 95 | +check_file_offset_bits() |
| 96 | + |
44 | 97 | add_subdirectory(src)
|
45 | 98 | add_subdirectory(extensions)
|
46 |
| -if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC)) |
47 |
| - add_subdirectory(api_test) |
| 99 | +# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME |
| 100 | +# to Windows, but defines `MINGW`. |
| 101 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) |
| 102 | + add_subdirectory(man) |
48 | 103 | endif()
|
49 |
| -add_subdirectory(man) |
50 |
| -if(CMARK_TESTS) |
51 |
| - enable_testing() |
| 104 | +if(BUILD_TESTING) |
52 | 105 | add_subdirectory(test testdir)
|
| 106 | + add_subdirectory(api_test) |
53 | 107 | endif()
|
54 | 108 | if(CMARK_FUZZ_QUADRATIC)
|
55 | 109 | add_subdirectory(fuzz)
|
56 | 110 | endif()
|
57 | 111 |
|
58 |
| -if(NOT CMAKE_BUILD_TYPE) |
59 |
| - set(CMAKE_BUILD_TYPE "Release" CACHE STRING |
60 |
| - "Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE) |
61 |
| -endif(NOT CMAKE_BUILD_TYPE) |
| 112 | +export(TARGETS libcmark-gfm libcmark-gfm-extensions |
| 113 | + FILE cmark-gfmConfig.cmake) |
| 114 | + |
0 commit comments