0003-CMakeLists.txt-respect-BUILD_TESTING-OFF.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From 7f0f1e7e34f997eef697856804dd478b54bb365e Mon Sep 17 00:00:00 2001
  2. From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  3. Date: Tue, 22 Dec 2020 10:45:21 +0100
  4. Subject: [PATCH] CMakeLists.txt: respect BUILD_TESTING=OFF
  5. Allow the user to disable unit tests through BUILD_TESTING=OFF:
  6. https://cmake.org/cmake/help/latest/command/enable_testing.html
  7. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  8. [Upstream status: https://github.com/apitrace/apitrace/pull/698]
  9. ---
  10. CMakeLists.txt | 6 +++++-
  11. gui/CMakeLists.txt | 6 ++++--
  12. lib/guids/CMakeLists.txt | 6 ++++--
  13. lib/os/CMakeLists.txt | 6 ++++--
  14. lib/trace/CMakeLists.txt | 6 ++++--
  15. 5 files changed, 21 insertions(+), 9 deletions(-)
  16. diff --git a/CMakeLists.txt b/CMakeLists.txt
  17. index 4a07f069..ee401887 100644
  18. --- a/CMakeLists.txt
  19. +++ b/CMakeLists.txt
  20. @@ -41,6 +41,8 @@ option (ENABLE_FRAME_POINTER "Disable frame pointer omission" ON)
  21. option (ENABLE_ASAN "Enable Address Sanitizer" OFF)
  22. +option (BUILD_TESTING "Enable unit tests" ON)
  23. +
  24. option (ENABLE_TESTS "Enable additional tests" OFF)
  25. if (ANDROID)
  26. @@ -433,7 +435,9 @@ endmacro ()
  27. # which subdirectory they are declared
  28. set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  29. -enable_testing ()
  30. +if (BUILD_TESTING)
  31. + enable_testing ()
  32. +endif ()
  33. if (CMAKE_CROSSCOMPILING)
  34. add_custom_target (check)
  35. elseif (DEFINED CMAKE_BUILD_TYPE)
  36. diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
  37. index 5baf3552..ad6ee501 100644
  38. --- a/gui/CMakeLists.txt
  39. +++ b/gui/CMakeLists.txt
  40. @@ -13,8 +13,10 @@ add_library (qubjson STATIC
  41. qubjson.cpp
  42. )
  43. -add_gtest (qubjson_test qubjson_test.cpp)
  44. -target_link_libraries (qubjson_test qubjson)
  45. +if (BUILD_TESTING)
  46. + add_gtest (qubjson_test qubjson_test.cpp)
  47. + target_link_libraries (qubjson_test qubjson)
  48. +endif ()
  49. set(qapitrace_SRCS
  50. apisurface.cpp
  51. diff --git a/lib/guids/CMakeLists.txt b/lib/guids/CMakeLists.txt
  52. index ce0f86da..ea28a18f 100644
  53. --- a/lib/guids/CMakeLists.txt
  54. +++ b/lib/guids/CMakeLists.txt
  55. @@ -5,5 +5,7 @@ add_library (guids STATIC
  56. guids.hpp
  57. )
  58. -add_gtest (guids_test guids_test.cpp)
  59. -target_link_libraries (guids_test guids)
  60. +if (BUILD_TESTING)
  61. + add_gtest (guids_test guids_test.cpp)
  62. + target_link_libraries (guids_test guids)
  63. +endif ()
  64. diff --git a/lib/os/CMakeLists.txt b/lib/os/CMakeLists.txt
  65. index 222411e0..b7134b57 100644
  66. --- a/lib/os/CMakeLists.txt
  67. +++ b/lib/os/CMakeLists.txt
  68. @@ -36,5 +36,7 @@ if (APPLE)
  69. )
  70. endif ()
  71. -add_gtest (os_thread_test os_thread_test.cpp)
  72. -target_link_libraries (os_thread_test os)
  73. +if (BUILD_TESTING)
  74. + add_gtest (os_thread_test os_thread_test.cpp)
  75. + target_link_libraries (os_thread_test os)
  76. +endif ()
  77. diff --git a/lib/trace/CMakeLists.txt b/lib/trace/CMakeLists.txt
  78. index c68bd00f..d95df978 100644
  79. --- a/lib/trace/CMakeLists.txt
  80. +++ b/lib/trace/CMakeLists.txt
  81. @@ -34,5 +34,7 @@ target_link_libraries (common
  82. brotli_dec brotli_common
  83. )
  84. -add_gtest (trace_parser_flags_test trace_parser_flags_test.cpp)
  85. -target_link_libraries (trace_parser_flags_test common)
  86. +if (BUILD_TESTING)
  87. + add_gtest (trace_parser_flags_test trace_parser_flags_test.cpp)
  88. + target_link_libraries (trace_parser_flags_test common)
  89. +endif ()
  90. --
  91. 2.29.2