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