CMakeLists.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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(GNUInstallDirs)
  19. set(CMAKE_CXX_STANDARD 20)
  20. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  21. set(CMAKE_CXX_EXTENSIONS OFF)
  22. file(GLOB SEXP_SOURCES src/*.cpp)
  23. file(GLOB SEXP_HEADER_SOURCES include/sexp/*.hpp)
  24. add_library(sexp STATIC ${SEXP_SOURCES})
  25. set_target_properties(sexp PROPERTIES PUBLIC_HEADER "${SEXP_HEADER_SOURCES}")
  26. target_compile_options(sexp PRIVATE ${WARNINGS_CXX_FLAGS})
  27. target_include_directories(sexp SYSTEM PUBLIC
  28. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  29. $<INSTALL_INTERFACE:include>)
  30. configure_file(
  31. "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/sexp.pc.in"
  32. "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/sexp.pc"
  33. @ONLY)
  34. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/sexp.pc"
  35. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  36. if(BUILD_TESTS)
  37. find_package(GTest REQUIRED)
  38. # build sexp tests
  39. file(GLOB TEST_SEXP_SOURCES tests/*.cpp)
  40. add_executable(test_sexp ${TEST_SEXP_SOURCES})
  41. target_compile_options(test_sexp PRIVATE ${WARNINGS_CXX_FLAGS})
  42. target_include_directories(test_sexp PUBLIC src/)
  43. target_link_libraries(test_sexp
  44. GTest::GTest
  45. GTest::Main
  46. sexp)
  47. # add 'make test' target, use 'make test ARGS="-V"' or 'ctest -V' for verbose
  48. enable_testing()
  49. add_test(NAME test_sexp
  50. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  51. COMMAND test_sexp)
  52. endif()
  53. if(BUILD_BENCHMARKS)
  54. find_package(benchmark REQUIRED)
  55. find_package(Threads REQUIRED)
  56. # build benchmarks
  57. file(GLOB BENCHMARKSOURCES benchmarks/*.cpp)
  58. foreach(SOURCE ${BENCHMARKSOURCES})
  59. get_filename_component(SOURCE_BASENAME ${SOURCE} NAME_WE)
  60. add_executable(${SOURCE_BASENAME} ${SOURCE})
  61. target_link_libraries(${SOURCE_BASENAME}
  62. sexp
  63. benchmark::benchmark
  64. Threads::Threads
  65. )
  66. set_target_properties(${SOURCE_BASENAME} PROPERTIES
  67. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/benchmarks/")
  68. target_compile_options(${SOURCE_BASENAME} PRIVATE -std=c++1y ${WARNINGS_CXX_FLAGS})
  69. endforeach()
  70. endif()
  71. # EOF #