-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
142 lines (119 loc) · 4.35 KB
/
CMakeLists.txt
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
cmake_minimum_required(VERSION 3.8)
project(html2md VERSION 1.6.3 LANGUAGES CXX)
set(PROJECT_HOMEPAGE_URL "https://tim-gromeyer.github.io/html2md/")
set(html2md_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(PROJECT_DESCRIPTION "Transform your HTML into clean, easy-to-read markdown with html2md")
set(html2md_DESCRIPTION "${PROJECT_DESCRIPTION}")
# If build type not specified we use release
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not specified. Release is used.")
set(CMAKE_BUILD_TYPE "Release")
endif()
# Improve performance
if(CMAKE_BUILD_TYPE STREQUAL "Release")
string(REPLACE "-O2" "-O3" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
# Check if it was included via `add_subdirectory`
get_directory_property(subproject PARENT_DIRECTORY)
# Create HTML for webassembly
if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
# Some options
if (subproject)
option(BUILD_EXE "Build a executable to convert html to markdown." OFF)
else()
option(BUILD_EXE "Build a executable to convert html to markdown." ON)
endif()
option(BUILD_DOC "Build documentation" OFF)
option(BUILD_TEST "Build tests" OFF)
option(PYTHON_BINDINGS "Build python bindings" OFF)
set(SOURCES
src/html2md.cpp
src/table.cpp
)
set(HEADERS
include/html2md.h
include/table.h
)
if(PYTHON_BINDINGS)
add_subdirectory(python/pybind11)
pybind11_add_module(pyhtml2md python/bindings.cpp ${SOURCES} ${HEADER})
target_compile_features(pyhtml2md PUBLIC
cxx_auto_type # auto keyword
cxx_constexpr # constexpr support
cxx_range_for # for (auto test : tests)
cxx_std_11 # Require at least c++11
)
target_compile_definitions(pyhtml2md PRIVATE PYTHON_BINDINGS)
target_include_directories(pyhtml2md PRIVATE include)
if (SKBUILD)
install(TARGETS pyhtml2md DESTINATION "${SKBUILD_PLATLIB_DIR}")
endif()
return()
endif()
add_library(html2md ${SOURCES})
set_target_properties(html2md PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${HEADERS}"
)
target_include_directories(html2md PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_compile_features(html2md PUBLIC cxx_std_11) # Require at least c++11
if ((subproject AND BUILD_SHARED_LIBS) OR BUILD_EXE)
add_library(html2md-static STATIC ${HEADERS} ${SOURCES})
target_include_directories(html2md-static PUBLIC include)
target_compile_features(html2md-static PUBLIC cxx_std_11) # Require at least c++11
endif()
if(BUILD_EXE)
add_executable(html2md-exe cli/main.cpp)
target_link_libraries(html2md-exe html2md-static)
set_target_properties(html2md-exe PROPERTIES OUTPUT_NAME "html2md")
target_compile_definitions(html2md-exe PUBLIC VERSION="${PROJECT_VERSION}")
target_compile_features(html2md-exe PUBLIC cxx_std_11) # Require at least c++11
endif()
if(BUILD_TEST)
add_subdirectory(tests)
endif()
if(BUILD_DOC)
include(cmake/Doc.cmake)
endif()
# Don't install as a subproject
if(subproject)
return()
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS html2md
EXPORT html2mdTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/html2md
)
install(EXPORT html2mdTargets
FILE html2mdTargets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/html2md"
)
configure_file(html2md.pc.in html2md.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/html2md.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md
)
if (BUILD_EXE)
install(TARGETS html2md-exe DESTINATION bin)
endif()
include(cmake/Packaging.cmake)