CMakeLists.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. cmake_minimum_required(VERSION 3.5)
  2. project(horrible-harry
  3. VERSION 0.1
  4. LANGUAGES CXX C)
  5. ###########
  6. # Debug or Release
  7. ###########
  8. if (NOT CMAKE_BUILD_TYPE)
  9. ## set default to Debug
  10. set(CMAKE_BUILD_TYPE Debug) # override with -DCMAKE_BUILD_TYPE=Release
  11. message("==> CMAKE_BUILD_TYPE empty. Changing it to Debug.")
  12. else()
  13. message("==> CMAKE_BUILD_TYPE == ${CMAKE_BUILD_TYPE}.")
  14. endif()
  15. FIND_PACKAGE(Git)
  16. IF(GIT_FOUND)
  17. message("Ask git for version information")
  18. EXECUTE_PROCESS(
  19. COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --long --tags --dirty --always --match v[0-9]*
  20. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  21. OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
  22. RESULT_VARIABLE GIT_DESCRIBE_RESULT
  23. ERROR_VARIABLE GIT_DESCRIBE_ERROR
  24. OUTPUT_STRIP_TRAILING_WHITESPACE
  25. )
  26. message("Version: " ${GIT_DESCRIBE_VERSION})
  27. # message("Result: " ${GIT_DESCRIBE_RESULT})
  28. ENDIF(GIT_FOUND)
  29. ## https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
  30. ## During Debug, use debug version of libstdc++ (asserts on access to invalid iterators, etc!)
  31. ## set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
  32. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=shift-base -fsanitize=unreachable -fsanitize=null -fsanitize=return -fsanitize=bounds-strict -fsanitize=object-size")
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  34. ###########
  35. # Suppress certain warnings
  36. ###########
  37. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
  38. # rm CMakeCache.txt and cmake . if you change any of the C++ Standards.
  39. ##############
  40. # C++ Standard
  41. ##############
  42. set(CMAKE_CXX_STANDARD 14)
  43. ## set(CMAKE_CXX_STANDARD 17)
  44. set(CMAKE_CXX_EXTENSIONS ON)
  45. # Are you debugging a buffer issue? If so, turn this to OFF.
  46. # This creates HUGE log files. Not for production!
  47. set(DISABLE_BUFFER_DEBUG ON CACHE BOOL "Turn off buffer debugging" FORCE)
  48. # set(DISABLE_BUFFER_DEBUG OFF CACHE BOOL "Turn off buffer debugging" FORCE)
  49. # Always disable in Release build.
  50. if((CMAKE_BUILD_TYPE STREQUAL Release) OR (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo))
  51. message("Release build -- disable BUFFER DEBUG.")
  52. set(DISABLE_BUFFER_DEBUG ON CACHE BOOL "Turn off buffer debugging" FORCE)
  53. endif()
  54. # Display at configuration time what settings we're using.
  55. if(DISABLE_BUFFER_DEBUG)
  56. message("BUFFER DEBUG DISABLED (Good!)")
  57. else()
  58. message("WARNING: Big logs ahead! BUFFER DEBUG is ENABLED")
  59. endif()
  60. # Enable testing
  61. # set(BUILD_TESTING ON)
  62. # include(CTest)
  63. ### ADD gtest
  64. add_subdirectory(googletest)
  65. ### TESTS
  66. add_executable(test-lastseen test-lastseen.cpp lastseen.cpp)
  67. add_dependencies(test-lastseen gtest)
  68. target_link_libraries(test-lastseen gtest_main)
  69. enable_testing()
  70. add_test(NAME test-lastseen
  71. COMMAND test-lastseen)
  72. add_executable(test-utils test-utils.cpp utils.cpp)
  73. add_dependencies(test-utils gtest)
  74. target_link_libraries(test-utils gtest_main)
  75. if(DISABLE_BUFFER_DEBUG)
  76. target_compile_definitions(test-utils PUBLIC NO_BUFFER_DEBUG=1)
  77. endif()
  78. add_test(NAME test-utils
  79. COMMAND test-utils)
  80. add_executable(test-render test-render.cpp render.cpp terminal.cpp utils.cpp)
  81. add_dependencies(test-render gtest)
  82. target_link_libraries(test-render gtest_main)
  83. target_link_libraries(test-render zf_log)
  84. if(DISABLE_BUFFER_DEBUG)
  85. target_compile_definitions(test-render PUBLIC NO_BUFFER_DEBUG=1)
  86. endif()
  87. add_test(NAME test-render
  88. COMMAND test-render)
  89. add_executable(test-mangle test-mangle.cpp wordplay.cpp render.cpp terminal.cpp charman.cpp lastseen.cpp logs_utils.cpp images.h)
  90. add_dependencies(test-mangle gtest)
  91. target_link_libraries(test-mangle gtest_main)
  92. target_link_libraries(test-mangle zf_log)
  93. if(DISABLE_BUFFER_DEBUG)
  94. target_compile_definitions(test-mangle PUBLIC NO_BUFFER_DEBUG=1)
  95. endif()
  96. add_test(NAME test-mangle COMMAND test-mangle)
  97. add_executable(test-terminal test-terminal.cpp terminal.cpp utils.cpp)
  98. add_dependencies(test-terminal gtest)
  99. target_link_libraries(test-terminal gtest_main)
  100. target_link_libraries(test-terminal zf_log)
  101. if(DISABLE_BUFFER_DEBUG)
  102. target_compile_definitions(test-terminal PUBLIC NO_BUFFER_DEBUG=1)
  103. endif()
  104. add_test(NAME test-terminal COMMAND test-terminal)
  105. # include(FetchContent)
  106. #
  107. # FetchContent_Populate(
  108. # zf_log
  109. # GIT_REPOSITORY https://github.com/wonder-mice/zf_log.git
  110. # SOURCE_DIR zf_log
  111. # )
  112. # add_subdirectory(${zf_log_SOURCE_DIR}/src zf_log)
  113. # This works, if zf_log is pulled in.
  114. add_subdirectory(zf_log)
  115. # Example for how to define a test which uses gtest_gmock
  116. # add_executable(mytest tester.cpp)
  117. # target_link_libraries(mytest gmock_main)
  118. # Here's how to add all *.h and *.cpp files
  119. # to a project:
  120. #
  121. # file(GLOB SOURCES
  122. # header-folder/*.h
  123. # source-folder/*.cpp
  124. # )
  125. # add_executable(yourProj ${SOURCES})
  126. add_executable(ansi-to-src ansi-to-src.cpp utils.cpp)
  127. if(DISABLE_BUFFER_DEBUG)
  128. target_compile_definitions(ansi-to-src PUBLIC NO_BUFFER_DEBUG=1)
  129. endif()
  130. # Everything in the ansi directory is a dependency for images.h
  131. file(GLOB IMAGES
  132. ansi/*.ans
  133. )
  134. add_custom_command(
  135. OUTPUT images.h
  136. COMMAND ./build_images.sh ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}
  137. DEPENDS ansi-to-src ${IMAGES}
  138. COMMENT "Generating images.h"
  139. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  140. )
  141. add_executable(hharry hharry.cpp lastseen.cpp terminal.cpp render.cpp utils.cpp images.h wordplay.cpp charman.cpp logs_utils.cpp)
  142. target_link_libraries(hharry util)
  143. target_link_libraries(hharry zf_log)
  144. target_compile_definitions(hharry PUBLIC HHVERSION="${GIT_DESCRIBE_VERSION}")
  145. if((CMAKE_BUILD_TYPE STREQUAL Release) OR (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo))
  146. target_compile_definitions(hharry PUBLIC ZF_LOG_DEF_LEVEL=ZF_LOG_WARN)
  147. else()
  148. target_compile_definitions(hharry PUBLIC ZF_LOG_DEF_LEVEL=ZF_LOG_VERBOSE)
  149. endif()
  150. if(DISABLE_BUFFER_DEBUG)
  151. target_compile_definitions(hharry PUBLIC NO_BUFFER_DEBUG=1)
  152. endif()
  153. # If you want this: ninja try-re or make try-re
  154. add_executable(try-re EXCLUDE_FROM_ALL try-re.c)
  155. add_executable(ansi-color EXCLUDE_FROM_ALL ansi-color.c)
  156. add_executable(images images.cpp utils.cpp images.h)
  157. target_link_libraries(images zf_log)
  158. if(DISABLE_BUFFER_DEBUG)
  159. target_compile_definitions(images PUBLIC NO_BUFFER_DEBUG=1)
  160. endif()