Skip to content

Commit

Permalink
CMake: Add features for docs, unit tests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ferdnyc committed Feb 26, 2020
1 parent fe8ea21 commit 85ca6c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
46 changes: 28 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ include(FeatureSummary)
# Optional build settings for libopenshot
option(USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON)
option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
option(DISABLE_TESTS "Don't build unit tests" OFF)
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
option(ENABLE_TESTS "Build unit tests (requires UnitTest++)" ON)
option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON)

# Legacy commandline override
if (DISABLE_TESTS)
set(ENABLE_TESTS OFF CACHE BOOL "Build unit tests (requires UnitTest++)" FORCE)
endif()

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

################### DOCUMENTATION ###################
# Find Doxygen (used for documentation)
include(cmake/Modules/UseDoxygen.cmake)

# Doxygen was found
if (TARGET doc)
message(STATUS "Doxygen found, documentation target enabled")
message("\nTo compile documentation in doc/html, run: 'make doc'")

# Install docs, if the user builds them with `make doc`
install(CODE "MESSAGE(\"Checking for documentation files to install...\")")
install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")")

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/
DESTINATION ${CMAKE_INSTALL_DOCDIR}/API
MESSAGE_NEVER # Don't spew about file copies
OPTIONAL ) # No error if the docs aren't found
set(DOCS_ENABLED FALSE) # Only set true if Doxygen is found and configured
if (ENABLE_DOCS)
include(cmake/Modules/UseDoxygen.cmake)

# Doxygen was found
if (TARGET doc)
message(STATUS "Doxygen found, documentation target enabled")
set(DOCS_ENABLED TRUE)

# Install docs, if the user builds them with `make doc`
install(CODE "MESSAGE(\"Checking for documentation files to install...\")")
install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")")

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/
DESTINATION ${CMAKE_INSTALL_DOCDIR}/API
MESSAGE_NEVER # Don't spew about file copies
OPTIONAL ) # No error if the docs aren't found
endif()
endif()
add_feature_info("Documentation" DOCS_ENABLED "Build API documentation with 'make doc'")

############# PROCESS tests/ DIRECTORY ##############
if(NOT DISABLE_TESTS)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()
add_feature_info("Unit tests" ENABLE_TESTS "Compile unit tests for library functions")

############## COVERAGE REPORTING #################
if (ENABLE_COVERAGE)
Expand Down
9 changes: 4 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ target_link_libraries(openshot-test openshot ${UNITTEST++_LIBRARY})
##### RUNNING TESTS (make os_test / make test) #####
# Hook up the 'make os_test' target to the 'openshot-test' executable
ADD_CUSTOM_TARGET(os_test COMMAND openshot-test)
list(APPEND OS_TEST_CMDS "'make os_test'")

# Also hook up 'make test', if possible
# This requires CMake 3.11+, where the CMP0037 policy
Expand All @@ -137,8 +136,8 @@ endif()
if (CMAKE_VERSION VERSION_GREATER 3.11)
message(STATUS "Cmake 3.11+ detected, enabling 'test' target")
add_custom_target(test COMMAND openshot-test)
list(APPEND OS_TEST_CMDS " or " "'make test'")
set(TEST_TARGET_NAME "test")
else()
set(TEST_TARGET_NAME "os_test")
endif()

string(CONCAT t ${OS_TEST_CMDS})
message("\nTo run unit tests, use: ${t}")
add_feature_info("Testrunner" ENABLE_TESTS "Run unit tests with 'make ${TEST_TARGET_NAME}'")

0 comments on commit 85ca6c5

Please sign in to comment.