Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ on: [push, pull_request]
jobs:

linter:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v1
- name: Install clang-tidy
run: |
Expand All @@ -23,7 +20,6 @@ jobs:
CXX: clang++

linux:

runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -45,6 +41,7 @@ jobs:
- uses: actions/checkout@v1
- name: Install valgrind
run: |
sudo apt update
sudo apt install -y valgrind
- name: Build and test
run: |
Expand All @@ -53,7 +50,6 @@ jobs:
make leakcheck

macos:

runs-on: macOS-latest
strategy:
fail-fast: false
Expand Down
70 changes: 21 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0065 NEW)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")

project(cmark VERSION 0.29.0)

include("FindAsan.cmake")
include(TargetProperties)
include(FindAsan)
include(GNUInstallDirs)

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")
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
endif()

option(CMARK_TESTS "Build cmark tests and enable testing" ON)
option(CMARK_STATIC "Build static libcmark library" ON)
option(CMARK_SHARED "Build shared libcmark library" ON)
option(CMARK_EXE "Build cmark executable" ON)
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)

set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};Release;Profile;Asan;Ubsan" CACHE STRING "" FORCE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif(NOT CMAKE_BUILD_TYPE)

if(NOT MSVC)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)
Expand All @@ -21,56 +33,16 @@ endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

# The Linux modules distributed with CMake add "-rdynamic" to the build flags
# which is incompatible with static linking under certain configurations.
# Unsetting CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ensures this does not happen.
if(CMARK_STATIC AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
endif()

# Compiler flags
if(MSVC)
# Force to always compile with W4
add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
# Compile as C++ under MSVC older than 12.0
if(MSVC_VERSION LESS 1800)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/TP>)
endif()
add_compile_options($<$<COMPILE_LANGUAGE:C>:/D_CRT_SECURE_NO_WARNINGS>)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>)
endif()

# Check integrity of node structure when compiled as debug
add_compile_options($<$<CONFIG:Debug>:-DCMARK_DEBUG_NODES>)

add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>)

if(CMAKE_BUILD_TYPE STREQUAL Ubsan)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>)
endif()
if(CMARK_LIB_FUZZER)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
endif()

add_subdirectory(src)
if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
add_subdirectory(api_test)
endif()
# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
# to Windows, but defines `MINGW`.
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)

if(NOT WIN32 AND NOT MINGW)
add_subdirectory(man)
endif()

if(CMARK_TESTS)
enable_testing()
if(CMARK_SHARED OR CMARK_STATIC)
add_subdirectory(api_test)
endif()
add_subdirectory(test testdir)
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)
7 changes: 2 additions & 5 deletions api_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ add_executable(api_test
harness.h
main.c
)
if(CMARK_SHARED)
target_link_libraries(api_test cmark)
else()
target_link_libraries(api_test cmark_static)
endif()

target_link_libraries(api_test cmark::cmark)
File renamed without changes.
28 changes: 28 additions & 0 deletions cmake/TargetProperties.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Defines common cmark properties.
function(cmark_target_properties tgt)
# Compiler flags
if(MSVC)
target_compile_options(${tgt} PRIVATE
$<$<COMPILE_LANGUAGE:C>:/W4> # Compile with W4
$<$<COMPILE_LANGUAGE:C>:/wd4706>
$<$<COMPILE_LANGUAGE:C>:/D_CRT_SECURE_NO_WARNINGS>
$<$<COMPILE_LANGUAGE:C>:/D_CRT_SECURE_NO_WARNINGS>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<VERSION_LESS:MSVC_VERSION,1800>>:/TP>
)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
target_compile_options(${tgt} PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wall>
$<$<COMPILE_LANGUAGE:C>:-Wextra>
$<$<COMPILE_LANGUAGE:C>:-pedantic>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:PROFILE>>:-pg>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<STREQUAL:${CMAKE_BUILD_TYPE},Ubsan>>:-fsanitize=undefined>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${CMARK_LIB_FUZZER}>>:-fsanitize-coverage=trace-pc-guard>
)
endif()

# Compiler definitions
target_compile_definitions(${tgt} PRIVATE
$<$<CONFIG:Debug>:CMARK_DEBUG_NODES> # Check integrity of node structure
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:CMARK_STATIC_DEFINE> # Disable PUBLIC declarations
)
endfunction()
Loading