From bdef2bdd62598afc31e17b24349b47d3813eed57 Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Wed, 14 Aug 2019 11:32:00 -0500 Subject: [PATCH 1/4] UnitTest++ now correctly supports CMake's find_package config mode [CMakeLists.txt] - Bumped cmake minimum requirement to go to 3.0 as this appears to be earliest version that transitive usage requirements are supported. - Added version to project so that is evident when looking at CMakeLists.txt - Removed include_directories as that command affects more than just UnitTest++ in favor of target_include_directories. - The target_include_directories uses the generator expressions to do the same thing for the BUILD_INTERFACE condition but only affects UnitTest++. The INSTALL_INTERFACE ensures that when UnitTest++ is installed client applications calling find_package for UnitTest++ only have to add the UnitTest++ target to the target_link_libraries and will get the correct include path for UnitTest++ added to their include paths. - Added DEBUG_POSTFIX to both library and unit test to distinguish them from each other as they are installed into the same directory and would otherwise overwrite one another. - Added Versioning using write_basic_package_version_file to the install so that a client can call find_package(UnitTest++ 2.1 REQUIRED) and it will be able to confirm the version. If the version is updated you could theoretically ahve a version 2.2, 2.3 ,etc... and the find_package mechanism will find the correct one. the SameMajorVersion option in that call indicates that 2.3 is compatible with 2.1 or in other words if find_package(UnitTest++ 2.1 REQUIRED) is called and 2.3 is installed that satisfies the condition but if only 3.0 was installed it will fail because of 'SameMajorVersion'. - Also added installation for the Version file. --- CMakeLists.txt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a683ea1..03a4f62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8.1) -project(UnitTest++) +cmake_minimum_required(VERSION 3.0) +project(UnitTest++ VERSION 2.1) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" @@ -74,7 +74,7 @@ endif() file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h) source_group( "" FILES ${TEST_SRCS}) add_executable(TestUnitTest++ ${TEST_SRCS}) -include_directories(.) + if(${UTPP_USE_PLUS_SIGN}) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) @@ -100,13 +100,30 @@ else() set (UTPP_INSTALL_DESTINATION "include/UnitTestPP") endif() +target_include_directories( UnitTest++ + PUBLIC + $ + $ + ) +set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d") +set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d") + set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME}) set(targets_export_name_ "${PROJECT_NAME}Targets") +include(CMakePackageConfigHelpers) +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_}) -install(FILES cmake/UnitTest++Config.cmake DESTINATION "${config_install_dir_}") +install(FILES + cmake/UnitTest++Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake + DESTINATION "${config_install_dir_}") install(EXPORT "${targets_export_name_}" DESTINATION "${config_install_dir_}") set(prefix ${CMAKE_INSTALL_PREFIX}) From 2423fcac7668aa9c331a2dcf024c3ca06742942d Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Thu, 15 Aug 2019 08:26:41 -0500 Subject: [PATCH 2/4] CrasingTestsAreReportedAsFailures no longer core dumps on Clang Release Found that Crashing tests at some point in Clang history were actually caught but testing on Clang 6.0 and Clang 7.0 this is not the case. So added Clang to the list of compilers that don't run this tests. Noted that several other Pull Requests were failing for the same reason. --- tests/TestTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestTest.cpp b/tests/TestTest.cpp index 5a4e1ca..0db0650 100644 --- a/tests/TestTest.cpp +++ b/tests/TestTest.cpp @@ -72,7 +72,7 @@ namespace { CHECK_EQUAL(1, results.GetFailureCount()); } -#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) +#if !defined(UNITTEST_MINGW) && !defined(UNITTEST_WIN32) && !defined(__clang__) // Skip this test in debug because some debuggers don't like it. #if defined(NDEBUG) TEST(CrashingTestsAreReportedAsFailures) From c26966668191029f50d3e9f7318e176e5bbd74fc Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Thu, 17 Oct 2019 08:23:46 -0500 Subject: [PATCH 3/4] Version made explicitly 3 parts - Updated to appveyor.yml and configure.ac to 2.1.0 to match CMake project version. --- CMakeLists.txt | 2 +- appveyor.yml | 2 +- configure.ac | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03a4f62..7a3fb55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(UnitTest++ VERSION 2.1) +project(UnitTest++ VERSION 2.1.0) option(UTPP_USE_PLUS_SIGN "Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths" diff --git a/appveyor.yml b/appveyor.yml index bebe4f5..3a4637d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.0.0.{build} +version: 2.1.0.{build} os: - Windows Server 2012 R2 diff --git a/configure.ac b/configure.ac index 56300a6..372f576 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AM_CONDITIONAL([WINDOWS], LT_INIT() -AC_SUBST([LIBUNITTEST_SO_VERSION], [2:0:0]) +AC_SUBST([LIBUNITTEST_SO_VERSION], [2:1:0]) # Checks for programs. AC_PROG_CXX From f871471d9020788eb0c05582f6430cca36397424 Mon Sep 17 00:00:00 2001 From: Dan Huantes Date: Tue, 7 Apr 2020 18:07:24 -0500 Subject: [PATCH 4/4] Added Namespace to Exported Target [CMakeLists.txt] - It is standard practice to have a namespace for an imported target. Added UnitTest++:: as the namespace argument so that find_package(UnitTest++) will result in UnitTest++::UnitTest++ target that will be used in target_link_libraries. - Updated target_link_libraries for TestUnitTest++ as an example --- CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a3fb55..b4c75c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_}) # create the lib add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_}) +add_library(UnitTest++::UnitTest++ ALIAS UnitTest++) + if(${UTPP_USE_PLUS_SIGN}) set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++) @@ -80,7 +82,10 @@ if(${UTPP_USE_PLUS_SIGN}) set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++) endif() -target_link_libraries(TestUnitTest++ UnitTest++) +target_link_libraries(TestUnitTest++ + PUBLIC + UnitTest++::UnitTest++ + ) # run unit tests as post build step add_custom_command(TARGET TestUnitTest++ @@ -124,7 +129,7 @@ install(FILES cmake/UnitTest++Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake DESTINATION "${config_install_dir_}") -install(EXPORT "${targets_export_name_}" 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)