?login_element?

Subversion Repositories NedoOS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. cmake_minimum_required(VERSION 2.8.1)
  2. project(UnitTest++)
  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.  
  68. if(${UTPP_USE_PLUS_SIGN})
  69.         set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
  70. endif()
  71.  
  72.  
  73. # build the test runner
  74. file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
  75. source_group( "" FILES ${TEST_SRCS})
  76. add_executable(TestUnitTest++ ${TEST_SRCS})
  77. include_directories(.)
  78.  
  79. if(${UTPP_USE_PLUS_SIGN})
  80.         set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
  81. endif()
  82.  
  83. target_link_libraries(TestUnitTest++ UnitTest++)
  84.  
  85. # run unit tests as post build step
  86. add_custom_command(TARGET TestUnitTest++
  87.     POST_BUILD COMMAND TestUnitTest++
  88.     COMMENT "Running unit tests")
  89.  
  90. if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
  91.     set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1)
  92. endif()
  93.  
  94. # add install targets
  95. # need a custom install path?
  96. # define CMAKE_INSTALL_PREFIX to change root folder
  97. if(${UTPP_USE_PLUS_SIGN})
  98.         set (UTPP_INSTALL_DESTINATION "include/UnitTest++")
  99. else()
  100.         set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
  101. endif()
  102.  
  103. set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
  104. set(targets_export_name_ "${PROJECT_NAME}Targets")
  105.  
  106. install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
  107. install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
  108. install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
  109. install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}")
  110. install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}")
  111.  
  112. set(prefix      ${CMAKE_INSTALL_PREFIX})
  113. set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
  114. set(libdir      ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
  115. set(includedir  ${CMAKE_INSTALL_PREFIX}/include/UnitTest++)
  116. configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY)
  117. if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
  118.     set(pkgconfdir  ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig)
  119. else()
  120.     set(pkgconfdir  ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig)
  121. endif()
  122. install(FILES       "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc"
  123.         DESTINATION "${pkgconfdir}")
  124.