Skip to content

Commit 4a4529d

Browse files
committed
assorted fixes to the build system
Remove the use of `CMARK_INLINE` (as is being considered upstream) as this workaround is no longer needed. It was to support VS2013 which has been obsoleted for some time now. Restructure the CMake modules to match expectations for CMake. Avoid defining `likely` and `unlikely` in global scope. While doing so, prefer the modern `__has_builtin` for the check (with fallbacks for pre-GCC 4.10, clang 3.4, and MSVC). This largely shouldn't matter in practice as modern branch predictors do well without the hint. Sink the declaration into source files as the macros are not namespaced. Remove the now unnecessary `config.h`. Clean up the builds to only support a single build type which is dependent on the standard `BUILD_SHARED_LIBS`. Simplify and normalise the install rules to use the `GNUInstallDirs` parameters.
1 parent 1dc6da9 commit 4a4529d

32 files changed

+218
-393
lines changed

CMakeLists.txt

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,43 @@ if(POLICY CMP0092)
77
cmake_policy(SET CMP0092 NEW)
88
endif()
99

10-
project(cmark-gfm)
11-
12-
set(PROJECT_VERSION_MAJOR 0)
13-
set(PROJECT_VERSION_MINOR 29)
14-
set(PROJECT_VERSION_PATCH 0)
15-
set(PROJECT_VERSION_GFM 13)
16-
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM})
17-
18-
include("FindAsan.cmake")
19-
include("CheckFileOffsetBits.cmake")
20-
include(CTest)
21-
include(GNUInstallDirs)
10+
project(cmark-gfm
11+
LANGUAGES C CXX)
12+
set(PROJECT_VERSION 0.29.0.gfm.13)
2213

2314
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
2415
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
2516
endif()
2617

27-
option(CMARK_STATIC "Build static libcmark-gfm library" ON)
28-
option(CMARK_SHARED "Build shared libcmark-gfm library" ON)
2918
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
3019
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
3120

32-
if(NOT MSVC)
33-
set(CMAKE_C_STANDARD 99)
34-
set(CMAKE_C_STANDARD_REQUIRED YES)
35-
set(CMAKE_C_EXTENSIONS NO)
36-
endif()
37-
38-
# -fvisibility=hidden
21+
set(CMAKE_C_STANDARD 99)
22+
set(CMAKE_C_STANDARD_REQUIRED YES)
23+
set(CMAKE_C_EXTENSIONS NO)
3924
set(CMAKE_C_VISIBILITY_PRESET hidden)
25+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
4026
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
4127

4228
if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
4329
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
4430
include(InstallRequiredSystemLibraries)
4531
endif()
4632

33+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
34+
35+
include(CheckFileOffsetBits)
36+
include(CTest)
37+
include(FindAsan)
38+
include(GenerateExportHeader)
39+
include(GNUInstallDirs)
40+
41+
check_file_offset_bits()
4742

4843
# Compiler flags
4944
if(MSVC)
5045
add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
5146
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
52-
# Compile as C++ under MSVC older than 12.0
53-
add_compile_options($<$<COMPILE_LANGUAGE:C>:/TP>)
5447
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_CRT_SECURE_NO_WARNINGS>)
5548
# BEGIN cmark-gfm
5649
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4204>)
@@ -80,11 +73,7 @@ if(CMARK_LIB_FUZZER)
8073
endif()
8174

8275
if(CMARK_FUZZ_QUADRATIC)
83-
set(FUZZER_FLAGS "-fsanitize=fuzzer-no-link,address -g")
84-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_FLAGS}")
85-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_FLAGS}")
86-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_FLAGS}")
87-
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FUZZER_FLAGS}")
76+
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fsanitize=fuzzer-no-link,address>)
8877
endif()
8978

9079
add_subdirectory(src)
@@ -96,9 +85,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
9685
endif()
9786
if(BUILD_TESTING)
9887
add_subdirectory(test testdir)
99-
if(CMARK_STATIC OR CMARK_SHARED)
100-
add_subdirectory(api_test)
101-
endif()
88+
add_subdirectory(api_test)
10289
endif()
10390
if(CMARK_FUZZ_QUADRATIC)
10491
add_subdirectory(fuzz)

api_test/CMakeLists.txt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
add_executable(api_test
22
cplusplus.cpp
33
harness.c
4-
harness.h
5-
main.c
6-
)
7-
include_directories(
8-
${PROJECT_SOURCE_DIR}/src
9-
${PROJECT_BINARY_DIR}/src
10-
${PROJECT_BINARY_DIR}/extensions
11-
)
12-
if(CMARK_SHARED)
13-
target_link_libraries(api_test libcmark-gfm-extensions libcmark-gfm)
14-
else()
15-
target_link_libraries(api_test libcmark-gfm-extensions_static libcmark-gfm_static)
16-
endif()
4+
main.c)
5+
target_link_libraries(api_test PRIVATE
6+
libcmark-gfm
7+
libcmark-gfm-extensions)
178

189
add_test(NAME api_test COMMAND api_test)
1910
if(WIN32)

extensions/CMakeLists.txt

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,30 @@
1-
set(LIBRARY "libcmark-gfm-extensions")
2-
set(STATICLIBRARY "libcmark-gfm-extensions_static")
3-
set(LIBRARY_SOURCES
4-
core-extensions.c
5-
table.c
6-
strikethrough.c
7-
autolink.c
8-
tagfilter.c
9-
ext_scanners.c
10-
ext_scanners.re
11-
ext_scanners.h
12-
tasklist.c
13-
)
14-
15-
include_directories(
16-
${PROJECT_SOURCE_DIR}/src
17-
${PROJECT_BINARY_DIR}/src
18-
)
19-
20-
include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
21-
22-
if (CMARK_SHARED)
23-
add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
24-
25-
set_target_properties(${LIBRARY} PROPERTIES
26-
OUTPUT_NAME "cmark-gfm-extensions"
27-
DEFINE_SYMBOL "cmark-gfm"
28-
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.gfm.${PROJECT_VERSION_GFM}
29-
VERSION ${PROJECT_VERSION})
30-
31-
set_property(TARGET ${LIBRARY}
32-
APPEND PROPERTY MACOSX_RPATH true)
33-
34-
# Avoid name clash between PROGRAM and LIBRARY pdb files.
35-
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark-gfm-extensions_dll)
36-
37-
list(APPEND CMARK_INSTALL ${LIBRARY})
38-
target_link_libraries(${LIBRARY} libcmark-gfm)
39-
40-
endif()
41-
42-
if (CMARK_STATIC)
43-
add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
44-
target_compile_definitions(${STATICLIBRARY} PUBLIC
45-
CMARK_GFM_STATIC_DEFINE
46-
CMARK_GFM_EXTENSIONS_STATIC_DEFINE)
47-
set_target_properties(${STATICLIBRARY} PROPERTIES
48-
DEFINE_SYMBOL "cmark-gfm"
49-
POSITION_INDEPENDENT_CODE ON)
50-
51-
if (MSVC)
52-
set_target_properties(${STATICLIBRARY} PROPERTIES
53-
OUTPUT_NAME "cmark-gfm-extensions_static"
54-
VERSION ${PROJECT_VERSION})
55-
else()
56-
set_target_properties(${STATICLIBRARY} PROPERTIES
57-
OUTPUT_NAME "cmark-gfm-extensions"
58-
VERSION ${PROJECT_VERSION})
59-
endif(MSVC)
60-
61-
list(APPEND CMARK_INSTALL ${STATICLIBRARY})
62-
endif()
63-
64-
install(TARGETS ${CMARK_INSTALL}
1+
add_library(libcmark-gfm-extensions
2+
autolink.c
3+
core-extensions.c
4+
ext_scanners.c
5+
ext_scanners.h
6+
ext_scanners.re
7+
strikethrough.c
8+
table.c
9+
tagfilter.c
10+
tasklist.c)
11+
set_target_properties(libcmark-gfm-extensions PROPERTIES
12+
DEFINE_SYMBOL cmark-gfm
13+
MACOSX_RPATH TRUE
14+
OUTPUT_NAME cmark-gfm-extensions
15+
PDB_NAME libcmark-gfm-extensions
16+
SOVERSION ${PROJECT_VERSION}
17+
VERSION ${PROJECT_VERSION})
18+
target_link_libraries(libcmark-gfm-extensions PRIVATE
19+
libcmark-gfm)
20+
21+
22+
install(TARGETS libcmark-gfm-extensions
6523
EXPORT cmark-gfm-extensions
6624
RUNTIME DESTINATION bin
67-
LIBRARY DESTINATION lib${LIB_SUFFIX}
68-
ARCHIVE DESTINATION lib${LIB_SUFFIX}
69-
)
70-
71-
if (CMARK_SHARED OR CMARK_STATIC)
72-
install(FILES
73-
cmark-gfm-core-extensions.h
74-
DESTINATION include
75-
)
76-
77-
install(EXPORT cmark-gfm-extensions DESTINATION lib${LIB_SUFFIX}/cmake-gfm-extensions)
78-
endif()
79-
80-
# Feature tests
81-
include(CheckCSourceCompiles)
82-
83-
CHECK_C_SOURCE_COMPILES(
84-
"int main() { __builtin_expect(0,0); return 0; }"
85-
HAVE___BUILTIN_EXPECT)
25+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
26+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
27+
install(FILES cmark-gfm-core-extensions.h
28+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
29+
install(EXPORT cmark-gfm-extensions
30+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake-gfm-extensions)

0 commit comments

Comments
 (0)