aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 8eb198e8e879bf4f78ef16863cce1a7f673e07e1 (plain)
  1. cmake_minimum_required(VERSION 2.8)
  2. set(LIBRARY "libcmark")
  3. set(HEADERS
  4. cmark.h
  5. parser.h
  6. buffer.h
  7. node.h
  8. iterator.h
  9. chunk.h
  10. references.h
  11. debug.h
  12. bench.h
  13. utf8.h
  14. scanners.h
  15. inlines.h
  16. html_unescape.h
  17. houdini.h
  18. )
  19. set(LIBRARY_SOURCES
  20. cmark.c
  21. node.c
  22. iterator.c
  23. blocks.c
  24. inlines.c
  25. print.c
  26. scanners.c
  27. scanners.re
  28. utf8.c
  29. buffer.c
  30. references.c
  31. man.c
  32. html.c
  33. html_unescape.gperf
  34. houdini_href_e.c
  35. houdini_html_e.c
  36. houdini_html_u.c
  37. ${HEADERS}
  38. )
  39. set(PROGRAM "cmark")
  40. set(PROGRAM_SOURCES
  41. ${LIBRARY_SOURCES}
  42. main.c
  43. )
  44. include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
  45. set(RE2C re2c)
  46. if (MSVC)
  47. file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} DOS_CURRENT_SOURCE_DIR)
  48. add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  49. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
  50. COMMAND ${RE2C} --case-insensitive -b -i
  51. --no-generation-date
  52. -o ${DOS_CURRENT_SOURCE_DIR}\\scanners.c
  53. ${DOS_CURRENT_SOURCE_DIR}\\scanners.re )
  54. else(MSVC)
  55. add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  56. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
  57. COMMAND ${RE2C} --case-insensitive -b -i
  58. --no-generation-date
  59. -o ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  60. ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re )
  61. endif(MSVC)
  62. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
  63. ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
  64. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
  65. DESTINATION lib/pkgconfig)
  66. include (GenerateExportHeader)
  67. add_executable(${PROGRAM} ${PROGRAM_SOURCES})
  68. add_compiler_export_flags()
  69. # Disable the PUBLIC declarations when compiling the executable:
  70. set_target_properties(${PROGRAM} PROPERTIES
  71. COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
  72. # Check integrity of node structure when compiled as debug:
  73. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pg -DCMARK_DEBUG_NODES")
  74. set(CMAKE_LINKER_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -pg")
  75. if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
  76. set(CMAKE_C_VISIBILITY_PRESET hidden)
  77. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  78. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  79. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  80. endif ()
  81. add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
  82. set_target_properties(${LIBRARY}
  83. PROPERTIES OUTPUT_NAME "cmark")
  84. set_property(TARGET ${LIBRARY}
  85. APPEND PROPERTY MACOSX_RPATH true)
  86. generate_export_header(${LIBRARY}
  87. BASE_NAME ${PROJECT_NAME})
  88. if (MSVC)
  89. set_property(TARGET ${PROGRAM}
  90. APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
  91. endif(MSVC)
  92. install(TARGETS ${PROGRAM} ${LIBRARY}
  93. RUNTIME DESTINATION bin
  94. LIBRARY DESTINATION lib
  95. )
  96. install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
  97. DESTINATION include
  98. )
  99. # Feature tests
  100. include(CheckIncludeFile)
  101. include(CheckCSourceCompiles)
  102. CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
  103. CHECK_C_SOURCE_COMPILES(
  104. "int main() { __builtin_expect(0,0); return 0; }"
  105. HAVE___BUILTIN_EXPECT)
  106. CHECK_C_SOURCE_COMPILES("
  107. int f(void) __attribute__ (());
  108. int main() { return 0; }
  109. " HAVE___ATTRIBUTE__)
  110. CONFIGURE_FILE(
  111. ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  112. ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  113. # Always compile with warnings
  114. if(MSVC)
  115. # Force to always compile with W4
  116. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  117. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  118. else()
  119. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  120. endif()
  121. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS")
  122. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  123. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
  124. endif()
  125. # Compile as C++ under MSVC
  126. if(MSVC)
  127. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
  128. endif()
  129. if($ENV{TIMER})
  130. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
  131. endif($ENV{TIMER})