Skip to content

Commit 85ca6c5

Browse files
committed
CMake: Add features for docs, unit tests
- A new CMake option, ENABLE_TESTS, is created and defaults ON (Legacy -DDISABLE_TESTS=1 on the command line will override) - Target info for docs and tests is shown in the FeatureSummary
1 parent fe8ea21 commit 85ca6c5

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

CMakeLists.txt

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ 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+
set(ENABLE_TESTS OFF CACHE BOOL "Build unit tests (requires UnitTest++)" FORCE)
83+
endif()
7984

8085
########## Configure Version.h header ##############
8186
configure_file(include/OpenShotVersion.h.in include/OpenShotVersion.h @ONLY)
@@ -124,27 +129,32 @@ add_subdirectory(src)
124129

125130
################### DOCUMENTATION ###################
126131
# 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
132+
set(DOCS_ENABLED FALSE) # Only set true if Doxygen is found and configured
133+
if (ENABLE_DOCS)
134+
include(cmake/Modules/UseDoxygen.cmake)
135+
136+
# Doxygen was found
137+
if (TARGET doc)
138+
message(STATUS "Doxygen found, documentation target enabled")
139+
set(DOCS_ENABLED TRUE)
140+
141+
# Install docs, if the user builds them with `make doc`
142+
install(CODE "MESSAGE(\"Checking for documentation files to install...\")")
143+
install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")")
144+
145+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/
146+
DESTINATION ${CMAKE_INSTALL_DOCDIR}/API
147+
MESSAGE_NEVER # Don't spew about file copies
148+
OPTIONAL ) # No error if the docs aren't found
149+
endif()
142150
endif()
151+
add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'make doc'")
143152

144153
############# PROCESS tests/ DIRECTORY ##############
145-
if(NOT DISABLE_TESTS)
154+
if(ENABLE_TESTS)
146155
add_subdirectory(tests)
147156
endif()
157+
add_feature_info("Unit tests" ENABLE_TESTS "Compile unit tests for library functions")
148158

149159
############## COVERAGE REPORTING #################
150160
if (ENABLE_COVERAGE)

tests/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ target_link_libraries(openshot-test openshot ${UNITTEST++_LIBRARY})
125125
##### RUNNING TESTS (make os_test / make test) #####
126126
# Hook up the 'make os_test' target to the 'openshot-test' executable
127127
ADD_CUSTOM_TARGET(os_test COMMAND openshot-test)
128-
list(APPEND OS_TEST_CMDS "'make os_test'")
129128

130129
# Also hook up 'make test', if possible
131130
# This requires CMake 3.11+, where the CMP0037 policy
@@ -137,8 +136,8 @@ endif()
137136
if (CMAKE_VERSION VERSION_GREATER 3.11)
138137
message(STATUS "Cmake 3.11+ detected, enabling 'test' target")
139138
add_custom_target(test COMMAND openshot-test)
140-
list(APPEND OS_TEST_CMDS " or " "'make test'")
139+
set(TEST_TARGET_NAME "test")
140+
else()
141+
set(TEST_TARGET_NAME "os_test")
141142
endif()
142-
143-
string(CONCAT t ${OS_TEST_CMDS})
144-
message("\nTo run unit tests, use: ${t}")
143+
add_feature_info("Testrunner" ENABLE_TESTS "Run unit tests with 'make ${TEST_TARGET_NAME}'")

0 commit comments

Comments
 (0)