"Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
ON)
option(UTPP_INCLUDE_TESTS_IN_BUILD
"Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build"
ON)
"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"
ON)
set(LIB_SUFFIX
"" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64")
# CHECK_CXX_COMPILER_FLAG could be used
# but MSVC version is preferred for feature requirements
# has the support we need
message(STATUS "The MSVC compiler version does not support UnitTest++ C++11 features.")
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX14
)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX11
)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++11")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
# up warning level for project
if (${UTPP_AMPLIFY_WARNINGS})
# instead of getting compiler specific, we're going to try making an assumption that an existing /W# means
# we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
if(CMAKE_CXX_FLAGS
MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} /WX")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
# get the main sources
file(GLOB headers_ RELATIVE
${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.h
)
file(GLOB sources_ RELATIVE
${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.cpp
)
# get platform specific sources
file(GLOB platformHeaders_ RELATIVE
${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/
${platformDir_}/*.h
)
file(GLOB platformSources_ RELATIVE
${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/
${platformDir_}/*.cpp
)
source_group(${platformDir_} FILES
${platformHeaders_} ${platformSources_})
# create the lib
add_library(UnitTest++
STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
if(${UTPP_USE_PLUS_SIGN})
# build the test runner
file(GLOB TEST_SRCS RELATIVE
${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h
)
if(${UTPP_USE_PLUS_SIGN})
PUBLIC
UnitTest++::UnitTest++
)
# run unit tests as post build step
POST_BUILD COMMAND TestUnitTest++
COMMENT "Running unit tests")
if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
# add install targets
# need a custom install path?
# define CMAKE_INSTALL_PREFIX to change root folder
if(${UTPP_USE_PLUS_SIGN})
set (UTPP_INSTALL_DESTINATION
"include/UnitTest++")
set (UTPP_INSTALL_DESTINATION
"include/UnitTestPP")
target_include_directories( UnitTest++
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
)
set(config_install_dir_ lib
${LIB_SUFFIX}/cmake/
${PROJECT_NAME})
set(targets_export_name_
"${PROJECT_NAME}Targets")
write_basic_package_version_file(
cmake/UnitTest++ConfigVersion.cmake
VERSION ${UnitTest++_VERSION}
COMPATIBILITY SameMajorVersion
)
install(TARGETS UnitTest++ EXPORT
"${targets_export_name_}" DESTINATION lib
${LIB_SUFFIX})
install(FILES
${headers_} DESTINATION
${UTPP_INSTALL_DESTINATION})
install(FILES
${platformHeaders_} DESTINATION
${UTPP_INSTALL_DESTINATION}/
${platformDir_})
cmake/UnitTest++Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
DESTINATION "${config_install_dir_}")
install(EXPORT
"${targets_export_name_}" NAMESPACE
"UnitTest++::" DESTINATION
"${config_install_dir_}")
set(prefix
${CMAKE_INSTALL_PREFIX})
set(exec_prefix
${CMAKE_INSTALL_PREFIX}/bin
)
set(libdir
${CMAKE_INSTALL_PREFIX}/lib
${LIB_SUFFIX})
set(includedir
${CMAKE_INSTALL_PREFIX}/include/UnitTest++
)
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(pkgconfdir
${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig
)
set(pkgconfdir
${CMAKE_INSTALL_PREFIX}/lib
${LIB_SUFFIX}/pkgconfig
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc"
DESTINATION "${pkgconfdir}")