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