aboutsummaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 9bae3b579bfe4a1d0c1b77ad200b8a0154222dae (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. if (MSVC)
  41. set(RE2C ${CMAKE_CURRENT_SOURCE_DIR}/re2c)
  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. set(RE2C re2c)
  48. add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
  49. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
  50. COMMAND ${RE2C} --case-insensitive -b -i ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re >${CMAKE_CURRENT_SOURCE_DIR}/scanners.c)
  51. endif(MSVC)
  52. include (GenerateExportHeader)
  53. add_executable(${PROGRAM} ${PROGRAM_SOURCES})
  54. add_compiler_export_flags()
  55. # Disable the PUBLIC declarations when compiling the executable:
  56. set_target_properties(${PROGRAM} PROPERTIES
  57. COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
  58. if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
  59. set(CMAKE_C_VISIBILITY_PRESET hidden)
  60. set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  61. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  62. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  63. endif ()
  64. add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
  65. set_target_properties(${LIBRARY}
  66. PROPERTIES OUTPUT_NAME "cmark")
  67. set_property(TARGET ${LIBRARY}
  68. APPEND PROPERTY MACOSX_RPATH true)
  69. generate_export_header(${LIBRARY}
  70. BASE_NAME ${PROJECT_NAME})
  71. if (MSVC)
  72. set_property(TARGET ${PROGRAM}
  73. APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO)
  74. endif(MSVC)
  75. install(TARGETS ${PROGRAM} ${LIBRARY}
  76. RUNTIME DESTINATION bin
  77. LIBRARY DESTINATION lib
  78. )
  79. install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
  80. DESTINATION include
  81. )
  82. include (CheckIncludeFile)
  83. CHECK_INCLUDE_FILE (stdbool.h HAVE_STDBOOL_H)
  84. # Always compile with warnings
  85. if(MSVC)
  86. # Force to always compile with W4
  87. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  88. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  89. else()
  90. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  91. endif()
  92. elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  93. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -pedantic")
  94. endif()
  95. if(CMAKE_COMPILER_IS_MINGW)
  96. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fgnu89-inline")
  97. endif(CMAKE_COMPILER_IS_MINGW)
  98. if($ENV{TIMER})
  99. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1")
  100. endif($ENV{TIMER})