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