cmark

My personal build of CMark ✏️

CMakeLists.txt (5482B)

  1 if(${CMAKE_VERSION} VERSION_GREATER "3.3")
  2     cmake_policy(SET CMP0063 NEW)
  3 endif()
  4 
  5 set(LIBRARY "cmark")
  6 set(STATICLIBRARY "cmark_static")
  7 set(HEADERS
  8   cmark.h
  9   parser.h
 10   buffer.h
 11   node.h
 12   iterator.h
 13   chunk.h
 14   references.h
 15   utf8.h
 16   scanners.h
 17   inlines.h
 18   houdini.h
 19   cmark_ctype.h
 20   render.h
 21   )
 22 set(LIBRARY_SOURCES
 23   cmark.c
 24   node.c
 25   iterator.c
 26   blocks.c
 27   inlines.c
 28   scanners.c
 29   scanners.re
 30   utf8.c
 31   buffer.c
 32   references.c
 33   render.c
 34   man.c
 35   xml.c
 36   html.c
 37   commonmark.c
 38   latex.c
 39   houdini_href_e.c
 40   houdini_html_e.c
 41   houdini_html_u.c
 42   cmark_ctype.c
 43   ${HEADERS}
 44   )
 45 
 46 set(PROGRAM "cmark_exe")
 47 set(PROGRAM_SOURCES main.c)
 48 
 49 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in
 50   ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h)
 51 
 52 include(GNUInstallDirs)
 53 include (GenerateExportHeader)
 54 
 55 add_executable(${PROGRAM} ${PROGRAM_SOURCES})
 56 set_target_properties(${PROGRAM} PROPERTIES
 57   OUTPUT_NAME "cmark")
 58 
 59 if (CMARK_STATIC)
 60   target_link_libraries(${PROGRAM} ${STATICLIBRARY})
 61   # Disable the PUBLIC declarations when compiling the executable:
 62   set_target_properties(${PROGRAM} PROPERTIES
 63     COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
 64 elseif (CMARK_SHARED)
 65   target_link_libraries(${PROGRAM} ${LIBRARY})
 66 endif()
 67 
 68 # -fvisibility=hidden
 69 set(CMAKE_C_VISIBILITY_PRESET hidden)
 70 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
 71 
 72 if (CMARK_SHARED)
 73   add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
 74   set_target_properties(${LIBRARY} PROPERTIES
 75     MACOSX_RPATH TRUE
 76     OUTPUT_NAME "cmark"
 77     # Avoid name clash between PROGRAM and LIBRARY pdb files.
 78     PDB_NAME cmark_dll
 79     # Include minor version and patch level in soname for now.
 80     SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
 81     VERSION ${PROJECT_VERSION})
 82   target_include_directories(${LIBRARY} INTERFACE
 83     $<INSTALL_INTERFACE:include>
 84     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
 85     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
 86   add_library(cmark::cmark ALIAS ${LIBRARY})
 87 
 88   generate_export_header(${LIBRARY}
 89     BASE_NAME ${PROJECT_NAME})
 90 
 91   list(APPEND CMARK_INSTALL ${LIBRARY})
 92 endif()
 93 
 94 if (CMARK_STATIC)
 95   add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
 96   set_target_properties(${STATICLIBRARY} PROPERTIES
 97     COMPILE_FLAGS -DCMARK_STATIC_DEFINE
 98     OUTPUT_NAME "cmark$<$<BOOL:${MSVC}>:_static>"
 99     POSITION_INDEPENDENT_CODE ON
100     VERSION ${PROJECT_VERSION})
101   target_include_directories(${STATICLIBRARY} INTERFACE
102     $<INSTALL_INTERFACE:include>
103     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
104     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
105   add_library(cmark::cmark_static ALIAS ${STATICLIBRARY})
106 
107   if (NOT CMARK_SHARED)
108     generate_export_header(${STATICLIBRARY}
109       BASE_NAME ${PROJECT_NAME})
110   endif()
111 
112   list(APPEND CMARK_INSTALL ${STATICLIBRARY})
113 endif()
114 
115 if (MSVC)
116   set_property(TARGET ${PROGRAM}
117     APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
118 endif(MSVC)
119 
120 if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
121   set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
122   include(InstallRequiredSystemLibraries)
123 endif()
124 
125 install(TARGETS ${PROGRAM} ${CMARK_INSTALL}
126   EXPORT cmark-targets
127   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
128   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
129   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
130   )
131 
132 if(CMARK_SHARED OR CMARK_STATIC)
133   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
134     ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
135   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
136     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
137 
138   install(FILES
139     cmark.h
140     ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
141     ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h
142     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
143     )
144 
145   # Include module for fuctions
146   # - 'write_basic_package_version_file'
147   # - 'configure_package_config_file'
148   include(CMakePackageConfigHelpers)
149   # generate cmark-config.cmake and cmark-config-version.cmake files
150   configure_package_config_file(
151     "cmarkConfig.cmake.in"
152     "${CMAKE_CURRENT_BINARY_DIR}/generated/cmark-config.cmake"
153     INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmark")
154   write_basic_package_version_file(
155     "${CMAKE_CURRENT_BINARY_DIR}/generated/cmark-config-version.cmake"
156     VERSION ${PROJECT_VERSION}
157     COMPATIBILITY SameMajorVersion)
158   # install config and version file
159   install(
160     FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/cmark-config.cmake"
161           "${CMAKE_CURRENT_BINARY_DIR}/generated/cmark-config-version.cmake"
162     DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmark"
163   )
164   # install targets file
165   install(
166     EXPORT "cmark-targets"
167     NAMESPACE "cmark::"
168     DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmark"
169   )
170 
171 endif()
172 
173 # Feature tests
174 include(CheckIncludeFile)
175 include(CheckCSourceCompiles)
176 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
177 CHECK_C_SOURCE_COMPILES(
178   "int main() { __builtin_expect(0,0); return 0; }"
179   HAVE___BUILTIN_EXPECT)
180 CHECK_C_SOURCE_COMPILES("
181   int f(void) __attribute__ (());
182   int main() { return 0; }
183 " HAVE___ATTRIBUTE__)
184 
185 CONFIGURE_FILE(
186   ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
187   ${CMAKE_CURRENT_BINARY_DIR}/config.h)
188 
189 if(CMARK_LIB_FUZZER)
190   add_executable(cmark-fuzz ../test/cmark-fuzz.c ${LIBRARY_SOURCES})
191   target_link_libraries(cmark-fuzz "${CMAKE_LIB_FUZZER_PATH}")
192 
193   # cmark is written in C but the libFuzzer runtime is written in C++ which
194   # needs to link against the C++ runtime.
195   set_target_properties(cmark-fuzz PROPERTIES
196     LINKER_LANGUAGE CXX)
197 endif()