?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download

  1. cmake_minimum_required(VERSION 3.0)
  2. project(UnitTest++ VERSION 2.1.0)
  3.  
  4. option(UTPP_USE_PLUS_SIGN
  5.     "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
  6.     ON)
  7. option(UTPP_INCLUDE_TESTS_IN_BUILD
  8.     "Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build"
  9.     ON)
  10. option(UTPP_AMPLIFY_WARNINGS
  11.     "Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler"
  12.     ON)
  13.  
  14. set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64")
  15.  
  16. if (MSVC)
  17.         # CHECK_CXX_COMPILER_FLAG could be used
  18.         # but MSVC version is preferred for feature requirements
  19.         if (MSVC14 OR MSVC12)
  20.                 # has the support we need
  21.         else()
  22.                 message(STATUS "The MSVC compiler version does not support UnitTest++ C++11 features.")
  23.         endif()
  24. else()
  25.     include(CheckCXXCompilerFlag)
  26.     CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
  27.     CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  28.     if(COMPILER_SUPPORTS_CXX14)
  29.         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  30.     elseif(COMPILER_SUPPORTS_CXX11)
  31.         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  32.     else()
  33.         message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
  34.     endif()
  35. endif()
  36.  
  37. # up warning level for project
  38. if (${UTPP_AMPLIFY_WARNINGS})
  39.     # instead of getting compiler specific, we're going to try making an assumption that an existing /W# means
  40.     # we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
  41.     if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  42.         string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
  43.     else()
  44.         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
  45.     endif()
  46. endif()
  47.  
  48. # get the main sources
  49. file(GLOB headers_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.h)
  50. file(GLOB sources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.cpp)
  51. source_group("" FILES ${headers_} ${sources_})
  52.  
  53. # get platform specific sources
  54. if (WIN32)
  55.     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  56.     set(platformDir_ Win32)
  57. else()
  58.     set(platformDir_ Posix)
  59. endif(WIN32)
  60.  
  61. file(GLOB platformHeaders_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.h)
  62. file(GLOB platformSources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.cpp)
  63. source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_})
  64.  
  65. # create the lib
  66. add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
  67. add_library(UnitTest++::UnitTest++ ALIAS UnitTest++)
  68.  
  69.  
  70. if(${UTPP_USE_PLUS_SIGN})
  71.         set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
  72. endif()
  73.  
  74.  
  75. # build the test runner
  76. file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
  77. source_group( "" FILES ${TEST_SRCS})
  78. add_executable(TestUnitTest++ ${TEST_SRCS})
  79.  
  80.  
  81. if(${UTPP_USE_PLUS_SIGN})
  82.         set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
  83. endif()
  84.  
  85. target_link_libraries(TestUnitTest++
  86.         PUBLIC
  87.                 UnitTest++::UnitTest++
  88.         )
  89.  
  90. # run unit tests as post build step
  91. add_custom_command(TARGET TestUnitTest++
  92.     POST_BUILD COMMAND TestUnitTest++
  93.     COMMENT "Running unit tests")
  94.  
  95. if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
  96.     set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1)
  97. endif()
  98.  
  99. # add install targets
  100. # need a custom install path?
  101. # define CMAKE_INSTALL_PREFIX to change root folder
  102. if(${UTPP_USE_PLUS_SIGN})
  103.         set (UTPP_INSTALL_DESTINATION "include/UnitTest++")
  104. else()
  105.         set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
  106. endif()
  107.  
  108. target_include_directories( UnitTest++
  109.         PUBLIC
  110.                 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
  111.                 $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
  112.         )
  113. set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
  114. set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
  115.  
  116. set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
  117. set(targets_export_name_ "${PROJECT_NAME}Targets")
  118. include(CMakePackageConfigHelpers)
  119. write_basic_package_version_file(
  120.         cmake/UnitTest++ConfigVersion.cmake
  121.         VERSION ${UnitTest++_VERSION}
  122.         COMPATIBILITY SameMajorVersion
  123.         )
  124.  
  125. install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
  126. install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
  127. install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
  128. install(FILES
  129.         cmake/UnitTest++Config.cmake
  130.         ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
  131.         DESTINATION "${config_install_dir_}")
  132. install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}")
  133.  
  134. set(prefix      ${CMAKE_INSTALL_PREFIX})
  135. set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
  136. set(libdir      ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
  137. set(includedir  ${CMAKE_INSTALL_PREFIX}/include/UnitTest++)
  138. configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY)
  139. if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
  140.     set(pkgconfdir  ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig)
  141. else()
  142.     set(pkgconfdir  ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig)
  143. endif()
  144. install(FILES       "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc"
  145.         DESTINATION "${pkgconfdir}")
  146.