cmark

My personal build of CMark ✏️

CMakeLists.txt (2682B)

 1 cmake_minimum_required(VERSION 3.0)
 2 project(cmark VERSION 0.29.0)
 3 
 4 include("FindAsan.cmake")
 5 include(GNUInstallDirs)
 6 
 7 if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
 8     message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
 9 endif()
10 
11 option(CMARK_TESTS "Build cmark tests and enable testing" ON)
12 option(CMARK_STATIC "Build static libcmark library" ON)
13 option(CMARK_SHARED "Build shared libcmark library" ON)
14 option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
15 
16 if(NOT MSVC)
17   set(CMAKE_C_STANDARD 99)
18   set(CMAKE_C_STANDARD_REQUIRED YES)
19   set(CMAKE_C_EXTENSIONS NO)
20 endif()
21 
22 set(CMAKE_INCLUDE_CURRENT_DIR ON)
23 
24 # The Linux modules distributed with CMake add "-rdynamic" to the build flags
25 # which is incompatible with static linking under certain configurations.
26 # Unsetting CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ensures this does not happen.
27 if(CMARK_STATIC AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
28   SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
29 endif()
30 
31 # Compiler flags
32 if(MSVC)
33   # Force to always compile with W4
34   add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
35   add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
36   # Compile as C++ under MSVC older than 12.0
37   if(MSVC_VERSION LESS 1800)
38     add_compile_options($<$<COMPILE_LANGUAGE:C>:/TP>)
39   endif()
40   add_compile_options($<$<COMPILE_LANGUAGE:C>:/D_CRT_SECURE_NO_WARNINGS>)
41 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
42   add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>)
43   add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>)
44   add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>)
45 endif()
46 
47 # Check integrity of node structure when compiled as debug
48 add_compile_options($<$<CONFIG:Debug>:-DCMARK_DEBUG_NODES>)
49 
50 add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>)
51 
52 if(CMAKE_BUILD_TYPE STREQUAL Ubsan)
53   add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>)
54 endif()
55 if(CMARK_LIB_FUZZER)
56   add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
57 endif()
58 
59 add_subdirectory(src)
60 if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
61   add_subdirectory(api_test)
62 endif()
63 # TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
64 # to Windows, but defines `MINGW`.
65 if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
66   add_subdirectory(man)
67 endif()
68 if(CMARK_TESTS)
69   enable_testing()
70   add_subdirectory(test testdir)
71 endif()
72 
73 if(NOT CMAKE_BUILD_TYPE)
74   set(CMAKE_BUILD_TYPE "Release" CACHE STRING
75   "Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
76 endif(NOT CMAKE_BUILD_TYPE)