Skip to content

Commit c5d1389

Browse files
committed
build: reorganise the build files
Shuffle the behaviour checks to the beginning of the processing. Co-locate and hoist the options that the project supports, put custom behavioural changes in a single location.
1 parent 8aa6779 commit c5d1389

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

CMakeLists.txt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ project(cmark-gfm)
1313
# version (the infixed `.gfm.`).
1414
set(PROJECT_VERSION 0.29.0.gfm.13)
1515

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)
22+
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)
28+
29+
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
30+
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
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)
36+
1637
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
1738

1839
include(CheckFileOffsetBits)
@@ -58,24 +79,6 @@ add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
5879

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

61-
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
62-
message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
63-
endif()
64-
65-
option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
66-
option(CMARK_THREADING "Add locks around static accesses" OFF)
67-
68-
set(CMAKE_C_STANDARD 99)
69-
set(CMAKE_C_STANDARD_REQUIRED YES)
70-
set(CMAKE_C_EXTENSIONS NO)
71-
72-
set(CMAKE_C_VISIBILITY_PRESET hidden)
73-
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
74-
75-
set(CMAKE_INCLUDE_CURRENT_DIR YES)
76-
77-
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
78-
7982
if(CMARK_LIB_FUZZER)
8083
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
8184
endif()
@@ -89,6 +92,8 @@ if(CMARK_FUZZ_QUADRATIC)
8992
add_link_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=address>)
9093
endif()
9194

95+
check_file_offset_bits()
96+
9297
add_subdirectory(src)
9398
add_subdirectory(extensions)
9499
# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
@@ -107,7 +112,3 @@ endif()
107112
export(TARGETS libcmark-gfm libcmark-gfm-extensions
108113
FILE cmark-gfmConfig.cmake)
109114

110-
if(NOT CMAKE_BUILD_TYPE)
111-
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
112-
"Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
113-
endif(NOT CMAKE_BUILD_TYPE)

src/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark-gfm.pc.in
22
${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc @ONLY)
33

4-
check_file_offset_bits()
5-
6-
add_executable(cmark-gfm
7-
${PROJECT_SOURCE_DIR}/bin/main.c)
8-
target_link_libraries(cmark-gfm
9-
libcmark-gfm
10-
libcmark-gfm-extensions)
11-
124
add_library(libcmark-gfm
135
arena.c
146
blocks.c
@@ -53,6 +45,12 @@ set_target_properties(libcmark-gfm PROPERTIES
5345
SOVERSION ${PROJECT_VERSION}
5446
VERSION ${PROJECT_VERSION})
5547

48+
add_executable(cmark-gfm
49+
${PROJECT_SOURCE_DIR}/bin/main.c)
50+
target_link_libraries(cmark-gfm
51+
libcmark-gfm
52+
libcmark-gfm-extensions)
53+
5654

5755
install(TARGETS cmark-gfm libcmark-gfm
5856
EXPORT cmark-gfm

0 commit comments

Comments
 (0)