aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: aef1b1438ba288a9e6c4f8631f66a4e4814f2f9d (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_unescape.h
  16. 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.c
  30. html_unescape.gperf
  31. houdini_href_e.c
  32. houdini_html_e.c
  33. 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(. ${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
  48. --no-generation-date
  49. -o ${DOS_CURRENT_SOURCE_DIR}\\scanners.c
  50. ${DOS_CURRENT_SOURCE_DIR}\\scanners.re )
  51. else(MSVC)
  52. add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  53. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
  54. COMMAND ${RE2C} --case-insensitive -b -i
  55. --no-generation-date
  56. -o ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  57. ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re )
  58. endif(MSVC)
  59. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
  60. ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
  61. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
  62. DESTINATION lib/pkgconfig)
  63. include (GenerateExportHeader)
  64. add_executable(${PROGRAM} ${PROGRAM_SOURCES})
  65. add_compiler_export_flags()
  66. # Disable the PUBLIC declarations when compiling the executable:
  67. set_target_properties(${PROGRAM} PROPERTIES
  68. COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
  69. # Check integrity of node structure when compiled as debug:
  70. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCMARK_DEBUG_NODES")
  71. if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
  72. set(CMAKE_C_VISIBILITY_PRESET hidden)
  73. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  74. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  75. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  76. endif ()
  77. add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
  78. set_target_properties(${LIBRARY}
  79. PROPERTIES OUTPUT_NAME "cmark")
  80. set_property(TARGET ${LIBRARY}
  81. APPEND PROPERTY MACOSX_RPATH true)
  82. generate_export_header(${LIBRARY}
  83. BASE_NAME ${PROJECT_NAME})
  84. if (MSVC)
  85. set_property(TARGET ${PROGRAM}
  86. APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
  87. endif(MSVC)
  88. install(TARGETS ${PROGRAM} ${LIBRARY}
  89. RUNTIME DESTINATION bin
  90. LIBRARY DESTINATION lib
  91. )
  92. install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
  93. DESTINATION include
  94. )
  95. # Feature tests
  96. include(CheckIncludeFile)
  97. include(CheckCSourceCompiles)
  98. CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
  99. CHECK_C_SOURCE_COMPILES(
  100. "int main() { __builtin_expect(0,0); return 0; }"
  101. HAVE___BUILTIN_EXPECT)
  102. CHECK_C_SOURCE_COMPILES("
  103. int f(void) __attribute__ (());
  104. int main() { return 0; }
  105. " HAVE___ATTRIBUTE__)
  106. CONFIGURE_FILE(
  107. ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  108. ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  109. # Always compile with warnings
  110. if(MSVC)
  111. # Force to always compile with W4
  112. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  113. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  114. else()
  115. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  116. endif()
  117. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS")
  118. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  119. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
  120. endif()
  121. # Compile as C++ under MSVC
  122. if(MSVC)
  123. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
  124. endif()
  125. if($ENV{TIMER})
  126. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
  127. endif($ENV{TIMER})