ridiculousfish / libdivide

Official git repository for libdivide: optimized integer division
http://libdivide.com
Other
1.1k stars 79 forks source link

Only build tests when libdivide is the main project #110

Closed qak closed 11 months ago

qak commented 11 months ago

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.