CMakeLists.txt 2.7 KB

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