Only build tests when libdivide is the main project #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.