Skip to content

Commit 96b4ac4

Browse files
committed
Clean up ENABLE/DISABLE_TESTS logic and handling
1 parent 85ca6c5 commit 96b4ac4

File tree

2 files changed

+65
-50
lines changed

2 files changed

+65
-50
lines changed

CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON)
7979

8080
# Legacy commandline override
8181
if (DISABLE_TESTS)
82-
set(ENABLE_TESTS OFF CACHE BOOL "Build unit tests (requires UnitTest++)" FORCE)
82+
if(ENABLE_COVERAGE)
83+
message(WARNING "ENABLE_COVERAGE requires tests, overriding DISABLE_TESTS")
84+
set(ENABLE_TESTS ON)
85+
else()
86+
set(ENABLE_TESTS OFF)
87+
endif()
88+
endif()
89+
90+
if(DEFINED ENABLE_TESTS)
91+
set(ENABLE_TESTS ${ENABLE_TESTS} CACHE BOOL "Build unit tests (requires UnitTest++)" FORCE)
8392
endif()
8493

8594
########## Configure Version.h header ##############
@@ -120,7 +129,7 @@ if (ENABLE_COVERAGE)
120129
message(STATUS "Coverage enabled, setting build type to Debug")
121130
endif()
122131
include(CodeCoverage)
123-
APPEND_COVERAGE_COMPILER_FLAGS()
132+
append_coverage_compiler_flags()
124133
endif()
125134
add_feature_info("Coverage" ENABLE_COVERAGE "analyze test coverage and generate report")
126135

@@ -152,9 +161,10 @@ add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'mak
152161

153162
############# PROCESS tests/ DIRECTORY ##############
154163
if(ENABLE_TESTS)
164+
set(TESTS_ENABLED TRUE) # May be overridden by tests/CMakeLists.txt
155165
add_subdirectory(tests)
156166
endif()
157-
add_feature_info("Unit tests" ENABLE_TESTS "Compile unit tests for library functions")
167+
add_feature_info("Unit tests" TESTS_ENABLED "Compile unit tests for library functions")
158168

159169
############## COVERAGE REPORTING #################
160170
if (ENABLE_COVERAGE)

tests/CMakeLists.txt

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,107 +24,112 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27-
SET(TEST_MEDIA_PATH "${PROJECT_SOURCE_DIR}/src/examples/")
27+
# Test media path, used by unit tests for input data
28+
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/src/examples/" TEST_MEDIA_PATH)
29+
add_definitions( -DTEST_MEDIA_PATH="${TEST_MEDIA_PATH}" )
2830

2931
################ WINDOWS ##################
3032
# Set some compiler options for Windows
3133
# required for libopenshot-audio headers
32-
IF (WIN32)
33-
STRING(REPLACE "/" "\\\\" TEST_MEDIA_PATH TEST_MEDIA_PATH)
34+
if(WIN32)
3435
add_definitions( -DIGNORE_JUCE_HYPOT=1 )
35-
SET(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -include cmath")
36-
ENDIF(WIN32)
37-
38-
add_definitions( -DTEST_MEDIA_PATH="${TEST_MEDIA_PATH}" )
36+
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -include cmath")
37+
endif()
3938

4039
################### UNITTEST++ #####################
4140
# Find UnitTest++ libraries (used for unit testing)
42-
FIND_PACKAGE(UnitTest++ REQUIRED)
41+
find_package(UnitTest++)
42+
43+
if (NOT UnitTest++_FOUND)
44+
set(TESTS_ENABLED OFF PARENT_SCOPE)
45+
return()
46+
endif()
4347

4448
# Include UnitTest++ headers (needed for compile)
4549
include_directories(${UNITTEST++_INCLUDE_DIR})
4650

4751
################ IMAGE MAGICK ##################
4852
# Set the Quantum Depth that ImageMagick was built with (default to 16 bits)
49-
IF (MAGICKCORE_QUANTUM_DEPTH)
53+
if(MAGICKCORE_QUANTUM_DEPTH)
5054
add_definitions( -DMAGICKCORE_QUANTUM_DEPTH=${MAGICKCORE_QUANTUM_DEPTH} )
51-
ELSE (MAGICKCORE_QUANTUM_DEPTH)
55+
else()
5256
add_definitions( -DMAGICKCORE_QUANTUM_DEPTH=16 )
53-
ENDIF (MAGICKCORE_QUANTUM_DEPTH)
54-
IF (MAGICKCORE_HDRI_ENABLE)
57+
endif()
58+
59+
if(MAGICKCORE_HDRI_ENABLE)
5560
add_definitions( -DMAGICKCORE_HDRI_ENABLE=${MAGICKCORE_HDRI_ENABLE} )
56-
ELSE (MAGICKCORE_HDRI_ENABLE)
61+
else()
5762
add_definitions( -DMAGICKCORE_HDRI_ENABLE=0 )
58-
ENDIF (MAGICKCORE_HDRI_ENABLE)
59-
IF (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
63+
endif()
64+
65+
if(OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
6066
add_definitions( -DOPENSHOT_IMAGEMAGICK_COMPATIBILITY=${OPENSHOT_IMAGEMAGICK_COMPATIBILITY} )
61-
ELSE (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
67+
else()
6268
add_definitions( -DOPENSHOT_IMAGEMAGICK_COMPATIBILITY=0 )
63-
ENDIF (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
69+
endif()
6470

6571
# Find the ImageMagick++ library
66-
FIND_PACKAGE(ImageMagick COMPONENTS Magick++ MagickWand MagickCore)
67-
IF (ImageMagick_FOUND)
72+
find_package(ImageMagick COMPONENTS Magick++ MagickWand MagickCore)
73+
if(ImageMagick_FOUND)
6874
# Include ImageMagick++ headers (needed for compile)
6975
include_directories(${ImageMagick_INCLUDE_DIRS})
7076

7177
# define a global var (used in the C++)
7278
add_definitions( -DUSE_IMAGEMAGICK=1 )
73-
SET(CMAKE_SWIG_FLAGS "-DUSE_IMAGEMAGICK=1")
74-
75-
ENDIF (ImageMagick_FOUND)
79+
set(CMAKE_SWIG_FLAGS "-DUSE_IMAGEMAGICK=1")
80+
endif()
7681

7782
################# LIBOPENSHOT-AUDIO ###################
7883
# Find JUCE-based openshot Audio libraries
79-
FIND_PACKAGE(OpenShotAudio 0.1.9 REQUIRED)
84+
find_package(OpenShotAudio 0.1.9 REQUIRED)
8085

8186
# Include Juce headers (needed for compile)
8287
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
8388

8489

8590
################# BLACKMAGIC DECKLINK ###################
86-
IF (ENABLE_BLACKMAGIC)
91+
if(ENABLE_BLACKMAGIC)
8792
# Find BlackMagic DeckLinkAPI libraries
88-
FIND_PACKAGE(BlackMagic)
93+
find_package(BlackMagic)
8994

90-
IF (BLACKMAGIC_FOUND)
95+
if(BLACKMAGIC_FOUND)
9196
# Include Blackmagic headers (needed for compile)
9297
include_directories(${BLACKMAGIC_INCLUDE_DIR})
93-
ENDIF (BLACKMAGIC_FOUND)
94-
ENDIF (ENABLE_BLACKMAGIC)
98+
endif()
99+
endif()
95100

96101

97102
############### SET TEST SOURCE FILES #################
98-
SET ( OPENSHOT_TEST_FILES
99-
Cache_Tests.cpp
100-
Clip_Tests.cpp
101-
Color_Tests.cpp
102-
Coordinate_Tests.cpp
103-
ReaderBase_Tests.cpp
104-
ImageWriter_Tests.cpp
105-
FFmpegReader_Tests.cpp
106-
FFmpegWriter_Tests.cpp
107-
Fraction_Tests.cpp
108-
Frame_Tests.cpp
109-
FrameMapper_Tests.cpp
110-
KeyFrame_Tests.cpp
111-
Point_Tests.cpp
112-
Settings_Tests.cpp
113-
Timeline_Tests.cpp )
103+
set(OPENSHOT_TEST_FILES
104+
Cache_Tests.cpp
105+
Clip_Tests.cpp
106+
Color_Tests.cpp
107+
Coordinate_Tests.cpp
108+
ReaderBase_Tests.cpp
109+
ImageWriter_Tests.cpp
110+
FFmpegReader_Tests.cpp
111+
FFmpegWriter_Tests.cpp
112+
Fraction_Tests.cpp
113+
Frame_Tests.cpp
114+
FrameMapper_Tests.cpp
115+
KeyFrame_Tests.cpp
116+
Point_Tests.cpp
117+
Settings_Tests.cpp
118+
Timeline_Tests.cpp )
114119

115120
################ TESTER EXECUTABLE #################
116121
# Create unit test executable (openshot-test)
117122
message (STATUS "Tests enabled, test executable will be built as tests/openshot-test")
118123
add_executable(openshot-test
119-
tests.cpp
120-
${OPENSHOT_TEST_FILES} )
124+
tests.cpp
125+
${OPENSHOT_TEST_FILES} )
121126

122127
# Link libraries to the new executable
123128
target_link_libraries(openshot-test openshot ${UNITTEST++_LIBRARY})
124129

125130
##### RUNNING TESTS (make os_test / make test) #####
126131
# Hook up the 'make os_test' target to the 'openshot-test' executable
127-
ADD_CUSTOM_TARGET(os_test COMMAND openshot-test)
132+
add_custom_target(os_test COMMAND openshot-test)
128133

129134
# Also hook up 'make test', if possible
130135
# This requires CMake 3.11+, where the CMP0037 policy

0 commit comments

Comments
 (0)