diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fc91cc6..770fa046 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(taglib) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +include(CTest) + if(DEFINED ENABLE_STATIC) message(FATAL_ERROR "This option is no longer available, use BUILD_SHARED_LIBS instead") endif() @@ -32,7 +34,6 @@ if(ENABLE_CCACHE) endif() option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) -option(BUILD_TESTS "Build the test suite" OFF) option(BUILD_EXAMPLES "Build the examples" OFF) option(BUILD_BINDINGS "Build the bindings" ON) @@ -147,9 +148,13 @@ if(BUILD_BINDINGS) add_subdirectory(bindings) endif() -if(BUILD_TESTS AND NOT BUILD_SHARED_LIBS) - enable_testing() - add_subdirectory(tests) +if(BUILD_TESTING) + find_package(CppUnit) + if(CppUnit_FOUND) + add_subdirectory(tests) + else() + message(WARNING "BUILD_TESTING requested, but CppUnit not found, skipping tests.") + endif() endif() if(BUILD_EXAMPLES) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index bcdbfe20..2fe2f129 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -187,16 +187,6 @@ if(NOT ZLIB_SOURCE) endif() endif() -# Determine whether CppUnit is installed. - -if(BUILD_TESTS AND NOT BUILD_SHARED_LIBS) - find_package(CppUnit) - if(NOT CppUnit_FOUND) - message(STATUS "CppUnit not found, disabling tests.") - set(BUILD_TESTS OFF) - endif() -endif() - # Detect WinRT mode if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") set(PLATFORM WINRT 1) diff --git a/INSTALL.md b/INSTALL.md index a398654e..19771aca 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -167,7 +167,7 @@ Unit Tests If you want to run the test suite to make sure TagLib works properly on your system, you need to have cppunit installed. To build the tests, include -the option `-DBUILD_TESTS=ON -DBUILD_SHARED_LIBS=OFF` when running cmake. +the option `-DBUILD_TESTING=ON` when running cmake. The test suite has a custom target in the build system, so you can run the tests using make: @@ -183,7 +183,7 @@ Windows MinGW: - `mingw32-make; mingw32-make install DESTDIR=/path/to/install/dir` * Build TagLib with testing enabled: - ``` - cmake -G "MinGW Makefiles" -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=OFF \ + cmake -G "MinGW Makefiles" -DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=OFF \ -DCPPUNIT_INCLUDE_DIR=/path/to/cppunit/include \ -DCPPUNIT_LIBRARIES=/path/to/cppunit/lib/libcppunit.a \ -DCPPUNIT_INSTALLED_VERSION=1.15.1 @@ -200,7 +200,7 @@ Windows MSVS: - It may fail, but the needed libraries should be available in src\cppunit\DebugDll. * Build TagLib with testing enabled: - ``` - cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON + cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=OFF -DENABLE_STATIC_RUNTIME=ON -DCPPUNIT_INCLUDE_DIR=\path\to\cppunit\include -DCPPUNIT_LIBRARIES=\path\to\cppunit\DebugDll\cppunitd_dll.lib