CMakeLists.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (c) 2016-2022 Martin Moene.
  2. #
  3. # https://github.com/martinmoene/expected-lite
  4. #
  5. # Distributed under the Boost Software License, Version 1.0.
  6. # (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. if( NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION )
  8. cmake_minimum_required( VERSION 3.8 FATAL_ERROR )
  9. endif()
  10. project( example LANGUAGES CXX )
  11. set( unit_name "expected" )
  12. set( PACKAGE ${unit_name}-lite )
  13. message( STATUS "Subproject '${PROJECT_NAME}', various examples")
  14. # Target default options and definitions:
  15. set( OPTIONS "" )
  16. #set( DEFINITIONS "" )
  17. # Sources (.cpp), normal and no-exception, and their base names:
  18. set( SOURCES_CPP11
  19. 02-required.cpp
  20. )
  21. set( SOURCES_CPP14
  22. 01-basic.cpp
  23. )
  24. # note: here variable must be quoted to create semicolon separated list:
  25. string( REPLACE ".cpp" "" BASENAMES_CPP11 "${SOURCES_CPP11}" )
  26. string( REPLACE ".cpp" "" BASENAMES_CPP14 "${SOURCES_CPP14}" )
  27. set( TARGETS_CPP11 ${BASENAMES_CPP11} )
  28. set( TARGETS_CPP14 ${BASENAMES_CPP14} )
  29. set( TARGETS_ALL ${TARGETS_CPP11} ${TARGETS_CPP14} )
  30. # add targets:
  31. foreach( name ${TARGETS_ALL} )
  32. add_executable( ${name} ${name}.cpp )
  33. target_link_libraries( ${name} PRIVATE ${PACKAGE} )
  34. endforeach()
  35. # set compiler options:
  36. if( ${CMAKE_GENERATOR} MATCHES Visual )
  37. foreach( name ${TARGETS_ALL} )
  38. target_compile_options( ${name} PUBLIC -W3 -EHsc -wd4814 -Zc:implicitNoexcept- )
  39. endforeach()
  40. else()
  41. foreach( name ${TARGETS_ALL} )
  42. target_compile_options( ${name} PUBLIC -Wall )
  43. endforeach()
  44. foreach( name ${TARGETS_CPP11} )
  45. target_compile_options( ${name} PUBLIC -std=c++11 )
  46. endforeach()
  47. foreach( name ${TARGETS_CPP14} )
  48. target_compile_options( ${name} PUBLIC -std=c++14 )
  49. endforeach()
  50. endif()
  51. # configure unit tests via CTest:
  52. enable_testing()
  53. foreach( name ${TARGETS_ALL} )
  54. add_test ( NAME ${name} COMMAND ${name} )
  55. set_property( TEST ${name} PROPERTY LABELS example )
  56. endforeach()
  57. # end of file