aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: b4a0fe8331a0207c2a6f3e2af648a9cac026d84c (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. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
  48. ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
  49. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
  50. DESTINATION lib/pkgconfig)
  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. # Check integrity of node structure when compiled as debug:
  58. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pg -DCMARK_DEBUG_NODES")
  59. set(CMAKE_LINKER_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -pg")
  60. if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
  61. set(CMAKE_C_VISIBILITY_PRESET hidden)
  62. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  63. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  64. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  65. endif ()
  66. add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
  67. set_target_properties(${LIBRARY}
  68. PROPERTIES OUTPUT_NAME "cmark")
  69. set_property(TARGET ${LIBRARY}
  70. APPEND PROPERTY MACOSX_RPATH true)
  71. generate_export_header(${LIBRARY}
  72. BASE_NAME ${PROJECT_NAME})
  73. if (MSVC)
  74. set_property(TARGET ${PROGRAM}
  75. APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
  76. endif(MSVC)
  77. install(TARGETS ${PROGRAM} ${LIBRARY}
  78. RUNTIME DESTINATION bin
  79. LIBRARY DESTINATION lib
  80. )
  81. install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
  82. DESTINATION include
  83. )
  84. # Feature tests
  85. include(CheckIncludeFile)
  86. include(CheckCSourceCompiles)
  87. include(CheckSymbolExists)
  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. CHECK_SYMBOL_EXISTS(va_copy stdarg.h HAVE_VA_COPY)
  97. CONFIGURE_FILE(
  98. ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  99. ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  100. # Always compile with warnings
  101. if(MSVC)
  102. # Force to always compile with W4
  103. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  104. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  105. else()
  106. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  107. endif()
  108. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS")
  109. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  110. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
  111. endif()
  112. # Compile as C++ under MSVC
  113. if(MSVC)
  114. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
  115. endif()
  116. if($ENV{TIMER})
  117. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
  118. endif($ENV{TIMER})