CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. cmake_minimum_required(VERSION 3.2)
  2. # zf_log target (required)
  3. set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  4. set(HEADERS door.h)
  5. set(SOURCES door.cpp ansicolor.cpp lines.cpp panel.cpp anyoption.cpp)
  6. # add_subdirectory(opendoors)
  7. ###########
  8. # Debug or Release
  9. ###########
  10. if (NOT CMAKE_BUILD_TYPE)
  11. ## set default to Debug
  12. set(CMAKE_BUILD_TYPE Debug) # override with -DCMAKE_BUILD_TYPE=Release
  13. message("==> CMAKE_BUILD_TYPE empty. Changing it to Debug.")
  14. else()
  15. message("==> CMAKE_BUILD_TYPE == ${CMAKE_BUILD_TYPE}.")
  16. endif()
  17. ## https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
  18. ## During Debug, use debug version of libstdc++ (asserts on access to invalid iterators, etc!)
  19. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  21. ##############
  22. # C++ Standard
  23. ##############
  24. set(CMAKE_CXX_STANDARD 14)
  25. # set(CMAKE_CXX_STANDARD 17)
  26. set(CMAKE_CXX_EXTENSIONS ON)
  27. ## set(CMAKE_C_STANDARD 99)
  28. ## set(CMAKE_C_STANDARD_REQUIRED ON)
  29. ## set(CMAKE_C_EXTENSIONS OFF)
  30. if(MSVC)
  31. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX")
  32. else()
  33. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic-errors")
  34. endif()
  35. add_library(door++ ${HEADERS} ${SOURCES})
  36. if(TESTS)
  37. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
  38. message("***")
  39. message("*** ERROR/MISSING *** please run: git clone https://github.com/google/googletest.git")
  40. message("***")
  41. endif()
  42. add_subdirectory(googletest)
  43. option(gtest_build_samples "Build gtest's sample programs." OFF)
  44. option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
  45. ### TESTS
  46. add_executable(test-door test-door.cpp)
  47. add_dependencies(test-door gtest)
  48. target_link_libraries(test-door gtest_main door++)
  49. enable_testing()
  50. add_test(NAME test-door
  51. COMMAND test-door)
  52. endif()
  53. # target_link_libraries(door++ pthread)
  54. target_include_directories(door++ PUBLIC $<BUILD_INTERFACE:${HEADERS_DIR}>)
  55. add_executable(door-example examples/door-example.cpp)
  56. target_link_libraries(door-example door++ pthread)
  57. ## if(ZF_LOG_LIBRARY_PREFIX)
  58. ## target_compile_definitions(door++ PRIVATE "ZF_LOG_LIBRARY_PREFIX=${ZF_LOG_LIBRARY_PREFIX}")
  59. ## endif()