This pull request configures the LIBDIVIDE_BUILD_TESTS CMake option to be ON only when libdivide is being configured as the main project. This is because building tests by default when libdivide is not the main project can unexpectedly include libdivide's tests into the main project's tests. The fix in this pull request is inspired by an analogous fix in another C++ library here.
The issue can be explained as follows. When a user includes libdivide into their CMake project using FetchContent, CMake fully configures and builds libdivide during the main project's configuration phase and includes libdivide into the main project using add_subdirectory. The unexpected consequence is that libdivide's tests get added into the main project's tests that get run using the ctest command. Configuring the LIBDIVIDE_BUILD_TESTS option to be OFF when libdivide is not the main project prevents libdivide's tests from being added into the main project when the user doesn't expect so, but it let's them manually add libdivide's tests if they desire by toggling the LIBDIVIDE_BUILD_TESTS option.
This pull request configures the
LIBDIVIDE_BUILD_TESTS
CMake option to beON
only when libdivide is being configured as the main project. This is because building tests by default when libdivide is not the main project can unexpectedly include libdivide's tests into the main project's tests. The fix in this pull request is inspired by an analogous fix in another C++ library here.The issue can be explained as follows. When a user includes libdivide into their CMake project using
FetchContent
, CMake fully configures and builds libdivide during the main project's configuration phase and includes libdivide into the main project usingadd_subdirectory
. The unexpected consequence is that libdivide's tests get added into the main project's tests that get run using thectest
command. Configuring theLIBDIVIDE_BUILD_TESTS
option to beOFF
when libdivide is not the main project prevents libdivide's tests from being added into the main project when the user doesn't expect so, but it let's them manually add libdivide's tests if they desire by toggling theLIBDIVIDE_BUILD_TESTS
option.