aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 033a9bef9f52da4e02b82e28985bf714e1380eed (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}/cmark_version.h.in
  48. ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h)
  49. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
  50. ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
  51. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
  52. DESTINATION lib/pkgconfig)
  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} -pg -DCMARK_DEBUG_NODES")
  61. set(CMAKE_LINKER_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -pg")
  62. if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
  63. set(CMAKE_C_VISIBILITY_PRESET hidden)
  64. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  65. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  66. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  67. endif ()
  68. add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
  69. # Include minor version in soname as long as major version is 0.
  70. set_target_properties(${LIBRARY} PROPERTIES
  71. OUTPUT_NAME "cmark"
  72. SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
  73. VERSION ${PROJECT_VERSION})
  74. set_property(TARGET ${LIBRARY}
  75. APPEND PROPERTY MACOSX_RPATH true)
  76. generate_export_header(${LIBRARY}
  77. BASE_NAME ${PROJECT_NAME})
  78. if (MSVC)
  79. set_property(TARGET ${PROGRAM}
  80. APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
  81. endif(MSVC)
  82. install(TARGETS ${PROGRAM} ${LIBRARY}
  83. RUNTIME DESTINATION bin
  84. LIBRARY DESTINATION lib
  85. )
  86. install(FILES
  87. cmark.h
  88. ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
  89. ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h
  90. DESTINATION include
  91. )
  92. # Feature tests
  93. include(CheckIncludeFile)
  94. include(CheckCSourceCompiles)
  95. include(CheckSymbolExists)
  96. CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
  97. CHECK_C_SOURCE_COMPILES(
  98. "int main() { __builtin_expect(0,0); return 0; }"
  99. HAVE___BUILTIN_EXPECT)
  100. CHECK_C_SOURCE_COMPILES("
  101. int f(void) __attribute__ (());
  102. int main() { return 0; }
  103. " HAVE___ATTRIBUTE__)
  104. CHECK_SYMBOL_EXISTS(va_copy stdarg.h HAVE_VA_COPY)
  105. CONFIGURE_FILE(
  106. ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  107. ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  108. # Always compile with warnings
  109. if(MSVC)
  110. # Force to always compile with W4
  111. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  112. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  113. else()
  114. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  115. endif()
  116. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127 /wd4244 /wd4267 /wd4706 /wd4800 /D_CRT_SECURE_NO_WARNINGS")
  117. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  118. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic -D_GNU_SOURCE")
  119. endif()
  120. # Compile as C++ under MSVC
  121. if(MSVC)
  122. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
  123. endif()
  124. if($ENV{TIMER})
  125. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
  126. endif($ENV{TIMER})