@@ -73,10 +73,15 @@ include(FeatureSummary)
7373# Optional build settings for libopenshot
7474option (USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON )
7575option (DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF )
76+
7677option (ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF )
77- option (ENABLE_TESTS "Build unit tests (requires UnitTest++)" ON )
78+
79+ option (ENABLE_TESTS "Build unit tests (requires Catch2)" ON )
80+ option (ENABLE_PARALLEL_CTEST "Run CTest using multiple processors" ON )
7881option (ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF )
82+
7983option (ENABLE_DOCS "Build API documentation (requires Doxygen)" ON )
84+
8085option (APPIMAGE_BUILD "Build to install in an AppImage (Linux only)" OFF )
8186option (ENABLE_MAGICK "Use ImageMagick, if available" ON )
8287option (ENABLE_OPENCV "Build with OpenCV algorithms (requires Boost, Protobuf 3)" ON )
@@ -87,7 +92,7 @@ if (DISABLE_TESTS)
8792endif ()
8893
8994if (DEFINED ENABLE_TESTS)
90- set (ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires UnitTest++ )" FORCE)
95+ set (ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires Catch2 )" FORCE)
9196endif ()
9297
9398#### Work around a GCC < 9 bug with handling of _Pragma() in macros
@@ -109,7 +114,7 @@ ENDIF(WIN32)
109114############## Code Coverage #########################
110115if (ENABLE_COVERAGE AND NOT ENABLE_TESTS)
111116 message (WARNING "ENABLE_COVERAGE requires unit tests, forcing ENABLE_TESTS" )
112- set (ENABLE_TESTS ON CACHE BOOL "Don't build unit tests" FORCE)
117+ set (ENABLE_TESTS ON CACHE BOOL "Build unit tests (requires Catch2 or UnitTest++) " FORCE)
113118endif ()
114119
115120if (ENABLE_COVERAGE)
@@ -166,55 +171,87 @@ if (ENABLE_DOCS)
166171 OPTIONAL ) # No error if the docs aren't found
167172 endif ()
168173endif ()
169- add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'make doc'" )
170174
171175############# PROCESS tests/ DIRECTORY ##############
172176if (ENABLE_TESTS)
173177 set (TESTS_ENABLED TRUE ) # May be overridden by tests/CMakeLists.txt
178+ find_package (Catch2 REQUIRED)
179+ if (ENABLE_PARALLEL_CTEST)
180+ # Figure out the amount of parallelism for CTest
181+ include (ProcessorCount)
182+ ProcessorCount(CPU_COUNT)
183+ if (NOT CPU_COUNT EQUAL 0)
184+ message (STATUS "Setting up unit tests to use ${CPU_COUNT} processors" )
185+ set (CTEST_OPTIONS "-j${CPU_COUNT} " )
186+ endif ()
187+ endif ()
188+ include (CTest)
189+ include (Catch)
174190 add_subdirectory (tests)
175191endif ()
176192add_feature_info("Unit tests" TESTS_ENABLED "Compile unit tests for library functions" )
177193
178194############## COVERAGE REPORTING #################
179- if (ENABLE_COVERAGE)
195+ if (ENABLE_COVERAGE AND DEFINED UNIT_TEST_TARGETS )
180196 setup_target_for_coverage_lcov(
181197 NAME coverage
182198 LCOV_ARGS "--no-external"
183- EXECUTABLE openshot-test
184- DEPENDENCIES openshot openshot-test
199+ EXECUTABLE ctest
200+ EXECUTABLE_ARGS ${CTEST_OPTIONS}
201+ DEPENDENCIES openshot ${UNIT_TEST_TARGETS}
185202 EXCLUDE
186203 "bindings/*"
187204 "examples/*"
188205 "${CMAKE_CURRENT_BINARY_DIR} /bindings/*"
189206 "${CMAKE_CURRENT_BINARY_DIR} /src/*_autogen/*"
190207 )
191- if (NOT TARGET os_test)
192- add_custom_target (os_test)
193- add_dependencies (os_test coverage)
194- endif ()
195208endif ()
196209
197- # Also hook up 'test' as an alias for the 'os_test' target, if possible
198- # This requires CMake 3.11+, where the CMP0037 policy
199- # configured to 'NEW' mode will not reserve target names
200- # unless the corresponding feature is actually used
201- if (POLICY CMP0037)
202- cmake_policy (SET CMP0037 NEW)
210+ if (TESTS_ENABLED AND NOT TARGET coverage)
211+ add_custom_target (coverage
212+ COMMAND ctest ${CTEST_OPTIONS}
213+ DEPENDS openshot ${UNIT_TEST_TARGETS}
214+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
215+ COMMENT "Running unit tests (coverage disabled)"
216+ )
203217endif ()
204- if (TARGET os_test)
205- if (CMAKE_VERSION VERSION_GREATER 3.11)
206- message (STATUS "Cmake 3.11+ detected, enabling 'test' target" )
207- add_custom_target (test )
208- add_dependencies (test os_test)
209- set (TEST_TARGET_NAME "test" )
210- else ()
211- set (TEST_TARGET_NAME "os_test" )
218+
219+ if (TARGET test AND NOT TARGET os_test)
220+ add_custom_target (os_test)
221+ add_dependencies (os_test coverage)
222+ endif ()
223+
224+ if (TARGET os_test AND NOT TARGET test AND CMAKE_VERSION VERSION_GREATER 3.11)
225+ # Also hook up 'test' as an alias for the 'os_test' target, if possible
226+ # This requires CMake 3.11+, where the CMP0037 policy
227+ # configured to 'NEW' mode will not reserve target names
228+ # unless the corresponding feature is actually used
229+ if (POLICY CMP0037)
230+ cmake_policy (SET CMP0037 NEW)
212231 endif ()
213- add_feature_info("Testrunner" ENABLE_TESTS "Run unit tests with 'make ${TEST_TARGET_NAME} '" )
232+ message (STATUS "Cmake 3.11+ detected, enabling 'test' target" )
233+ add_custom_target (test )
234+ add_dependencies (test os_test)
214235endif ()
215236
237+ ###
238+ ### Add feature-summary details on non-default built targets
239+ ###
240+ set (optional_targets test os_test coverage doc )
241+ set (target_test_description "Build and execute unit tests" )
242+ set (target_os_test_description "Build and execute unit tests (legacy target)" )
243+ set (target_coverage_description "Run unit tests and (if enabled) collect coverage data" )
244+ set (target_doc_description "Build formatted API documentation (HTML+SVG)" )
245+ foreach (_tname IN LISTS optional_targets)
246+ if (TARGET ${_tname} )
247+ add_feature_info("Non-default target '${_tname} '" TRUE ${target_${_tname} _description})
248+ else ()
249+ message (DEBUG "No target ${_tname} " )
250+ endif ()
251+ endforeach ()
252+
216253########### PRINT FEATURE SUMMARY ##############
217254feature_summary(WHAT ALL
218255 INCLUDE_QUIET_PACKAGES
219256 FATAL_ON_MISSING_REQUIRED_PACKAGES
220- DESCRIPTION "Displaying feature summary \n\n Build configuration:" )
257+ DESCRIPTION "Build configuration:" )
0 commit comments