Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
122 lines (106 loc) · 4.58 KB
/
Copy pathCMakeLists.txt
File metadata and controls
122 lines (106 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmake_minimum_required(VERSION 3.14)
# ESP-IDF build system does not support CMake's project() command,
# so we need to check if we're building as part of an ESP-IDF
# project or standalone.
if(IDF_TARGET)
idf_component_register(
SRC_DIRS "src"
INCLUDE_DIRS "src"
)
endif()
if(NOT IDF_TARGET)
project(EnrMrkd
VERSION "0.6.0"
HOMEPAGE_URL "https://github.com/software-mansion-labs/md4c"
LANGUAGES C
)
# Some embedded platforms need the following files to exist even before
# CMake's configure time. Hence we have them directly in the repo, but lets
# at least check, they're up to date.
#
# If not, after a review of the generated one in the build dir need to be
# committed as replacement of the respective pre-generated one. Unless we
# do some really significant change like directory restructuring or introduce
# some lib dependencies, it should be just about keeping the version in sync
# between these files.
configure_file(idf_component.yml.in idf_component.yml.expected @ONLY)
configure_file(library.json.in library.json.expected @ONLY)
configure_file(library.properties.in library.properties.expected @ONLY)
function(CheckPregeneratedFile rel_path)
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files --ignore-eol
${CMAKE_CURRENT_SOURCE_DIR}/${rel_path}
${CMAKE_CURRENT_BINARY_DIR}/${rel_path}.expected
RESULT_VARIABLE compare_result
)
if(NOT compare_result EQUAL 0)
message(FATAL_ERROR "The pre-generated ${rel_path} file is not up to date.")
endif()
endfunction()
CheckPregeneratedFile(idf_component.yml)
CheckPregeneratedFile(library.json)
CheckPregeneratedFile(library.properties)
# Some heuristics for what targets (and how) we actually build:
set(BUILD_SHARED_LIBS_default ON)
set(BUILD_HTML_LIBRARY_default ON)
set(BUILDMD2HTML_EXECUTABLE_default ON)
if(WIN32)
# On Windows, given there is no standard lib install dir etc., we
# rather by default build static lib.
set(BUILD_SHARED_LIBS_default OFF)
endif()
if(NOT PROJECT_IS_TOP_LEVEL)
# When we're embedded into a bigger project, most likely the outer
# project only needs the libs.
set(BUILDMD2HTML_EXECUTABLE_default OFF)
endif()
# Allow the user to override the defaults:
option(
BUILD_SHARED_LIBS
"Build using shared libraries"
${BUILD_SHARED_LIBS_default}
)
option(
BUILD_HTML_LIBRARY
"Whether to compile the libmd-html library"
${BUILD_HTML_LIBRARY_default}
)
option(
BUILD_MD2HTML_EXECUTABLE
"Whether to compile the md2html command line tool (requires libmd-html)"
${BUILDMD2HTML_EXECUTABLE_default}
)
if(BUILD_MD2HTML_EXECUTABLE AND NOT BUILD_HTML_LIBRARY)
message(FATAL_ERROR "BUILD_MD2HTML_EXECUTABLE requires BUILD_HTML_LIBRARY=ON")
endif()
set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo MinSizeRel)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
endif()
if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
add_compile_options(-Wall -Wextra -Wshadow)
# We enforce -Wdeclaration-after-statement because Qt project needs to
# build MD4C with Integrity compiler which chokes whenever a declaration
# is not at the beginning of a block.
add_compile_options(-Wdeclaration-after-statement)
elseif(MSVC)
# Disable warnings about the so-called unsecured functions:
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_options(/W3)
# Specify proper C runtime library:
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_RELWITHDEBINFO "{$CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE "/M[DT]d?" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /MT")
endif()
include(GNUInstallDirs)
add_subdirectory(src)
add_subdirectory(md2html)
endif()