Skip to content

Commit b724f2e

Browse files
authored
Merge pull request #400 from ferdnyc/add-features
CMake: Add Features for docs, unit tests
2 parents 8b78ddf + 600e884 commit b724f2e

File tree

3 files changed

+165
-110
lines changed

3 files changed

+165
-110
lines changed

CMakeLists.txt

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,23 @@ include(FeatureSummary)
7373
# Optional build settings for libopenshot
7474
option(USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON)
7575
option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
76-
option(DISABLE_TESTS "Don't build unit tests" OFF)
7776
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
78-
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
77+
option(ENABLE_TESTS "Build unit tests (requires UnitTest++)" ON)
78+
option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON)
79+
80+
# Legacy commandline override
81+
if (DISABLE_TESTS)
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)
92+
endif()
7993

8094
########## Configure Version.h header ##############
8195
configure_file(include/OpenShotVersion.h.in include/OpenShotVersion.h @ONLY)
@@ -115,7 +129,7 @@ if (ENABLE_COVERAGE)
115129
message(STATUS "Coverage enabled, setting build type to Debug")
116130
endif()
117131
include(CodeCoverage)
118-
APPEND_COVERAGE_COMPILER_FLAGS()
132+
append_coverage_compiler_flags()
119133
endif()
120134
add_feature_info("Coverage" ENABLE_COVERAGE "analyze test coverage and generate report")
121135

@@ -124,27 +138,33 @@ add_subdirectory(src)
124138

125139
################### DOCUMENTATION ###################
126140
# Find Doxygen (used for documentation)
127-
include(cmake/Modules/UseDoxygen.cmake)
128-
129-
# Doxygen was found
130-
if (TARGET doc)
131-
message(STATUS "Doxygen found, documentation target enabled")
132-
message("\nTo compile documentation in doc/html, run: 'make doc'")
133-
134-
# Install docs, if the user builds them with `make doc`
135-
install(CODE "MESSAGE(\"Checking for documentation files to install...\")")
136-
install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")")
137-
138-
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/
139-
DESTINATION ${CMAKE_INSTALL_DOCDIR}/API
140-
MESSAGE_NEVER # Don't spew about file copies
141-
OPTIONAL ) # No error if the docs aren't found
141+
set(DOCS_ENABLED FALSE) # Only set true if Doxygen is found and configured
142+
if (ENABLE_DOCS)
143+
include(cmake/Modules/UseDoxygen.cmake)
144+
145+
# Doxygen was found
146+
if (TARGET doc)
147+
message(STATUS "Doxygen found, documentation target enabled")
148+
set(DOCS_ENABLED TRUE)
149+
150+
# Install docs, if the user builds them with `make doc`
151+
install(CODE "MESSAGE(\"Checking for documentation files to install...\")")
152+
install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")")
153+
154+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/
155+
DESTINATION ${CMAKE_INSTALL_DOCDIR}/API
156+
MESSAGE_NEVER # Don't spew about file copies
157+
OPTIONAL ) # No error if the docs aren't found
158+
endif()
142159
endif()
160+
add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'make doc'")
143161

144162
############# PROCESS tests/ DIRECTORY ##############
145-
if(NOT DISABLE_TESTS)
163+
if(ENABLE_TESTS)
164+
set(TESTS_ENABLED TRUE) # May be overridden by tests/CMakeLists.txt
146165
add_subdirectory(tests)
147166
endif()
167+
add_feature_info("Unit tests" TESTS_ENABLED "Compile unit tests for library functions")
148168

149169
############## COVERAGE REPORTING #################
150170
if (ENABLE_COVERAGE)

cmake/Modules/FindUnitTest++.cmake

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
1-
# Locate UNITTEST
1+
# Locate UnitTest++
22
# This module defines
3-
# UNITTEST++_LIBRARY
4-
# UNITTEST++_FOUND, if false, do not try to link to gdal
5-
# UNITTEST++_INCLUDE_DIR, where to find the headers
6-
7-
FIND_PATH(UNITTEST++_INCLUDE_DIR UnitTest++.h
8-
${UNITTEST_DIR}/include/unittest++
9-
$ENV{UNITTEST_DIR}/include/unittest++
10-
$ENV{UNITTEST_DIR}/src
3+
# UnitTest++_FOUND, if successful
4+
# UnitTest++_LIBRARIES, the library path
5+
# UnitTest++_INCLUDE_DIRS, where to find the headers
6+
7+
find_package(PkgConfig QUIET)
8+
if(PKG_CONFIG_FOUND)
9+
pkg_check_modules(PC_UnitTest QUIET UnitTest++)
10+
set(UnitTest++_VERSION ${PC_UnitTest_VERSION})
11+
endif()
12+
13+
14+
FIND_PATH(UnitTest++_INCLUDE_DIRS UnitTest++.h
15+
DOC
16+
"Location of UnitTest++ header files"
17+
PATH_SUFFIXES
18+
unittest++
19+
UnitTest++ # Fedora, Arch
20+
unittest-cpp # openSUSE
21+
HINTS
22+
${PC_UnitTest++_INCLUDEDIR}
23+
${PC_UnitTest++_INCLUDE_DIRS}
24+
PATHS
25+
${UnitTest++_ROOT}
26+
${UNITTEST_DIR}
27+
$ENV{UNITTEST_DIR}/src
1128
$ENV{UNITTEST_DIR}
1229
~/Library/Frameworks
1330
/Library/Frameworks
14-
/usr/local/include
15-
/usr/include
16-
/usr/include/unittest++
17-
/usr/include/UnitTest++ # Fedora
18-
/usr/include/unittest-cpp # openSUSE
19-
/usr/local/include/UnitTest++/ # Arch
20-
/sw/include # Fink
21-
/opt/local/include # DarwinPorts
22-
/opt/local/include/UnitTest++
23-
/opt/csw/include # Blastwave
24-
/opt/include
31+
/usr/local
32+
/sw # Fink
33+
/opt
34+
/opt/local # DarwinPorts
35+
/opt/csw # Blastwave
2536
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment]/include
26-
/usr/freeware/include
37+
/usr/freeware
2738
)
2839

29-
FIND_LIBRARY(UNITTEST++_LIBRARY
30-
NAMES unittest++ UnitTest++
31-
PATHS
32-
${UNITTEST_DIR}/lib
33-
$ENV{UNITTEST_DIR}/lib
34-
$ENV{UNITTEST_DIR}/build
40+
FIND_LIBRARY(UnitTest++_LIBRARIES
41+
NAMES unittest++ UnitTest++
42+
DOC
43+
"Location of UnitTest++ shared library"
44+
HINTS
45+
${PC_UnitTest++_LIBDIR}
46+
${PC_UnitTest++_LIBRARY_DIRS}
47+
PATHS
48+
${UnitTest++_ROOT}
49+
${UnitTest++_ROOT}/lib
50+
${UNITTEST_DIR}
3551
$ENV{UNITTEST_DIR}
52+
$ENV{UNITTEST_DIR}/lib
53+
$ENV{UNITTEST_DIR}/build
3654
~/Library/Frameworks
3755
/Library/Frameworks
3856
/usr/local/lib
39-
/usr/lib
40-
/usr/lib64/ # Fedora
4157
/sw/lib
4258
/opt/local/lib
4359
/opt/csw/lib
@@ -46,13 +62,24 @@ FIND_LIBRARY(UNITTEST++_LIBRARY
4662
/usr/freeware/lib64
4763
)
4864

49-
SET(UNITTEST++_FOUND "NO")
50-
IF(UNITTEST++_LIBRARY AND UNITTEST++_INCLUDE_DIR)
51-
SET(UNITTEST++_FOUND "YES")
52-
ENDIF(UNITTEST++_LIBRARY AND UNITTEST++_INCLUDE_DIR)
65+
if(UnitTest++_LIBRARIES AND UnitTest++_INCLUDE_DIRS)
66+
set(UnitTest++_FOUND TRUE)
67+
endif()
5368

5469
include(FindPackageHandleStandardArgs)
55-
# handle the QUIETLY and REQUIRED arguments and set UNITTEST++_FOUND to TRUE
56-
# if all listed variables are TRUE
57-
find_package_handle_standard_args(UNITTEST++ DEFAULT_MSG
58-
UNITTEST++_LIBRARY UNITTEST++_INCLUDE_DIR)
70+
find_package_handle_standard_args(UnitTest++
71+
REQUIRED_VARS
72+
UnitTest++_LIBRARIES
73+
UnitTest++_INCLUDE_DIRS
74+
VERSION_VAR
75+
UnitTest++_VERSION
76+
)
77+
78+
# Excessive backwards-compatibility paranoia
79+
set(UnitTest++_LIBRARY "${UnitTest++_LIBRARIES}" PARENT_SCOPE)
80+
set(UnitTest++_INCLUDE_DIR "${UnitTest++_INCLUDE_DIRS}" PARENT_SCOPE)
81+
# Even more excessive backwards-compatibility paranoia
82+
set(UNITTEST++_FOUND "${UnitTest++_FOUND}" PARENT_SCOPE)
83+
set(UNITTEST++_LIBRARY "${UnitTest++_LIBRARIES}" PARENT_SCOPE)
84+
set(UNITTEST++_INCLUDE_DIR "${UnitTest++_INCLUDE_DIRS}" PARENT_SCOPE)
85+

tests/CMakeLists.txt

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,108 +24,116 @@
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)
45-
include_directories(${UNITTEST++_INCLUDE_DIR})
49+
include_directories(${UnitTest++_INCLUDE_DIRS})
50+
51+
set_package_properties(UnitTest++ PROPERTIES
52+
TYPE RECOMMENDED
53+
PURPOSE "Unit testing framework")
4654

4755
################ IMAGE MAGICK ##################
4856
# Set the Quantum Depth that ImageMagick was built with (default to 16 bits)
49-
IF (MAGICKCORE_QUANTUM_DEPTH)
57+
if(MAGICKCORE_QUANTUM_DEPTH)
5058
add_definitions( -DMAGICKCORE_QUANTUM_DEPTH=${MAGICKCORE_QUANTUM_DEPTH} )
51-
ELSE (MAGICKCORE_QUANTUM_DEPTH)
59+
else()
5260
add_definitions( -DMAGICKCORE_QUANTUM_DEPTH=16 )
53-
ENDIF (MAGICKCORE_QUANTUM_DEPTH)
54-
IF (MAGICKCORE_HDRI_ENABLE)
61+
endif()
62+
63+
if(MAGICKCORE_HDRI_ENABLE)
5564
add_definitions( -DMAGICKCORE_HDRI_ENABLE=${MAGICKCORE_HDRI_ENABLE} )
56-
ELSE (MAGICKCORE_HDRI_ENABLE)
65+
else()
5766
add_definitions( -DMAGICKCORE_HDRI_ENABLE=0 )
58-
ENDIF (MAGICKCORE_HDRI_ENABLE)
59-
IF (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
67+
endif()
68+
69+
if(OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
6070
add_definitions( -DOPENSHOT_IMAGEMAGICK_COMPATIBILITY=${OPENSHOT_IMAGEMAGICK_COMPATIBILITY} )
61-
ELSE (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
71+
else()
6272
add_definitions( -DOPENSHOT_IMAGEMAGICK_COMPATIBILITY=0 )
63-
ENDIF (OPENSHOT_IMAGEMAGICK_COMPATIBILITY)
73+
endif()
6474

6575
# Find the ImageMagick++ library
66-
FIND_PACKAGE(ImageMagick COMPONENTS Magick++ MagickWand MagickCore)
67-
IF (ImageMagick_FOUND)
76+
find_package(ImageMagick COMPONENTS Magick++ MagickWand MagickCore)
77+
if(ImageMagick_FOUND)
6878
# Include ImageMagick++ headers (needed for compile)
6979
include_directories(${ImageMagick_INCLUDE_DIRS})
7080

7181
# define a global var (used in the C++)
7282
add_definitions( -DUSE_IMAGEMAGICK=1 )
73-
SET(CMAKE_SWIG_FLAGS "-DUSE_IMAGEMAGICK=1")
74-
75-
ENDIF (ImageMagick_FOUND)
83+
set(CMAKE_SWIG_FLAGS "-DUSE_IMAGEMAGICK=1")
84+
endif()
7685

7786
################# LIBOPENSHOT-AUDIO ###################
7887
# Find JUCE-based openshot Audio libraries
79-
FIND_PACKAGE(OpenShotAudio 0.2.0 REQUIRED)
88+
find_package(OpenShotAudio 0.2.0 REQUIRED)
8089

8190
# Include Juce headers (needed for compile)
8291
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
8392

8493

8594
################# BLACKMAGIC DECKLINK ###################
86-
IF (ENABLE_BLACKMAGIC)
95+
if(ENABLE_BLACKMAGIC)
8796
# Find BlackMagic DeckLinkAPI libraries
88-
FIND_PACKAGE(BlackMagic)
97+
find_package(BlackMagic)
8998

90-
IF (BLACKMAGIC_FOUND)
99+
if(BLACKMAGIC_FOUND)
91100
# Include Blackmagic headers (needed for compile)
92101
include_directories(${BLACKMAGIC_INCLUDE_DIR})
93-
ENDIF (BLACKMAGIC_FOUND)
94-
ENDIF (ENABLE_BLACKMAGIC)
102+
endif()
103+
endif()
95104

96105

97106
############### 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 )
107+
set(OPENSHOT_TEST_FILES
108+
Cache_Tests.cpp
109+
Clip_Tests.cpp
110+
Color_Tests.cpp
111+
Coordinate_Tests.cpp
112+
ReaderBase_Tests.cpp
113+
ImageWriter_Tests.cpp
114+
FFmpegReader_Tests.cpp
115+
FFmpegWriter_Tests.cpp
116+
Fraction_Tests.cpp
117+
Frame_Tests.cpp
118+
FrameMapper_Tests.cpp
119+
KeyFrame_Tests.cpp
120+
Point_Tests.cpp
121+
Settings_Tests.cpp
122+
Timeline_Tests.cpp )
114123

115124
################ TESTER EXECUTABLE #################
116125
# Create unit test executable (openshot-test)
117126
message (STATUS "Tests enabled, test executable will be built as tests/openshot-test")
118127
add_executable(openshot-test
119-
tests.cpp
120-
${OPENSHOT_TEST_FILES} )
128+
tests.cpp
129+
${OPENSHOT_TEST_FILES} )
121130

122131
# Link libraries to the new executable
123-
target_link_libraries(openshot-test openshot ${UNITTEST++_LIBRARY})
132+
target_link_libraries(openshot-test openshot ${UnitTest++_LIBRARIES})
124133

125134
##### RUNNING TESTS (make os_test / make test) #####
126135
# Hook up the 'make os_test' target to the 'openshot-test' executable
127-
ADD_CUSTOM_TARGET(os_test COMMAND openshot-test)
128-
list(APPEND OS_TEST_CMDS "'make os_test'")
136+
add_custom_target(os_test COMMAND openshot-test)
129137

130138
# Also hook up 'make test', if possible
131139
# This requires CMake 3.11+, where the CMP0037 policy
@@ -137,8 +145,8 @@ endif()
137145
if (CMAKE_VERSION VERSION_GREATER 3.11)
138146
message(STATUS "Cmake 3.11+ detected, enabling 'test' target")
139147
add_custom_target(test COMMAND openshot-test)
140-
list(APPEND OS_TEST_CMDS " or " "'make test'")
148+
set(TEST_TARGET_NAME "test")
149+
else()
150+
set(TEST_TARGET_NAME "os_test")
141151
endif()
142-
143-
string(CONCAT t ${OS_TEST_CMDS})
144-
message("\nTo run unit tests, use: ${t}")
152+
add_feature_info("Testrunner" ENABLE_TESTS "Run unit tests with 'make ${TEST_TARGET_NAME}'")

0 commit comments

Comments
 (0)