CMakeLists.txt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # SExp - A S-Expression Parser for C++
  2. # Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. cmake_minimum_required(VERSION 3.0)
  17. project(sexp)
  18. include(mk/cmake/TinyCMMC.cmake)
  19. include(GNUInstallDirs)
  20. include(MaximumWarnings)
  21. include(ClangTidy)
  22. set(CMAKE_CXX_STANDARD 20)
  23. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  24. set(CMAKE_CXX_EXTENSIONS OFF)
  25. file(GLOB SEXP_SOURCES src/*.cpp)
  26. file(GLOB SEXP_HEADER_SOURCES include/sexp/*.hpp)
  27. add_library(sexp STATIC ${SEXP_SOURCES})
  28. set_target_properties(sexp PROPERTIES PUBLIC_HEADER "${SEXP_HEADER_SOURCES}")
  29. target_compile_options(sexp PRIVATE ${WARNINGS_CXX_FLAGS})
  30. target_include_directories(sexp SYSTEM PUBLIC
  31. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  32. $<INSTALL_INTERFACE:include>)
  33. configure_file(
  34. "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/sexp.pc.in"
  35. "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/sexp.pc"
  36. @ONLY)
  37. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/sexp.pc"
  38. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  39. if(BUILD_TESTS)
  40. find_package(GTest REQUIRED)
  41. # build sexp tests
  42. file(GLOB TEST_SEXP_SOURCES tests/*.cpp)
  43. add_executable(test_sexp ${TEST_SEXP_SOURCES})
  44. target_compile_options(test_sexp PRIVATE ${WARNINGS_CXX_FLAGS})
  45. target_include_directories(test_sexp PUBLIC src/)
  46. target_link_libraries(test_sexp
  47. GTest::GTest
  48. GTest::Main
  49. sexp)
  50. # add 'make test' target, use 'make test ARGS="-V"' or 'ctest -V' for verbose
  51. enable_testing()
  52. add_test(NAME test_sexp
  53. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  54. COMMAND test_sexp)
  55. endif()
  56. if(BUILD_BENCHMARKS)
  57. find_package(benchmark REQUIRED)
  58. find_package(Threads REQUIRED)
  59. # build benchmarks
  60. file(GLOB BENCHMARKSOURCES benchmarks/*.cpp)
  61. foreach(SOURCE ${BENCHMARKSOURCES})
  62. get_filename_component(SOURCE_BASENAME ${SOURCE} NAME_WE)
  63. add_executable(${SOURCE_BASENAME} ${SOURCE})
  64. target_link_libraries(${SOURCE_BASENAME}
  65. sexp
  66. benchmark::benchmark
  67. Threads::Threads
  68. )
  69. set_target_properties(${SOURCE_BASENAME} PROPERTIES
  70. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/benchmarks/")
  71. target_compile_options(${SOURCE_BASENAME} PRIVATE -std=c++1y ${WARNINGS_CXX_FLAGS})
  72. endforeach()
  73. endif()
  74. include(ExportAndInstallLibrary)
  75. # EOF #