-
Notifications
You must be signed in to change notification settings - Fork 543
Skip building tests by default #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
18107c1
to
62b82e3
Compare
62b82e3
to
f40a8b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake has an semi-built-in option for this feature, BUILD_TESTING
. At the top CMakeLists.txt
, add:
if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING OFF) # Set this to OFF by default
endif()
include(CTest)
@@ -12,24 +12,28 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious if this will work, but I haven't tested it:
if(NOT BUILD_TESTING)
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL TRUE)
endif()
(and then the remainder of the file is reverted to as-it-was). IIUC, this should exclude every added target from the implicit all
, but still defined them and are available for building by being named explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the suggestion to exclude test targets from all
, but still have them defined.
Example: Targets in the examples directory are currently excluded from the all target with:
add_custom_target(examples DEPENDS ${MONGOCXX_EXAMPLE_EXECUTABLES} ${BSONCXX_EXAMPLE_EXECUTABLES})
But the example targets are still defined. CMake targets can be listed with cmake --build cmake-build --target help
. An example target can be built by including the --target
argument: cmake --build cmake-build --target aggregation_examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work when I try it. The test programs are built by default when I implement this like so:
CMakeLists.txt
:
if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING OFF) # Set this to OFF by default
endif()
src/bsoncxx/test/CMakeLists.txt
and src/mongocxx/test/CMakeLists.txt
:
if(NOT BUILD_TESTING)
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL TRUE)
endif()
include_directories(
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I can figure why the directory property doesn't work, so just discard that suggestion for now. On the other hand, the BUILD_TESTING variable should work? Are you sure to clear it from your cache before configuring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found the issue, and after applying the fix below, your suggestion then works. I pushed these changes and the tests are green.
- set(ENABLE_TESTS OLD_ENABLE_TESTS)
- set(BUILD_TESTING OLD_BUILD_TESTING)
+ set(ENABLE_TESTS ${OLD_ENABLE_TESTS})
+ set(BUILD_TESTING ${OLD_BUILD_TESTING})
Co-authored-by: vector-of-bool <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. One more comment.
CMakeLists.txt
Outdated
if(NOT DEFINED BUILD_TESTING) | ||
set(BUILD_TESTING OFF) # Set this to OFF by default | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest: Move this below project()
. Will also want to include(CTest)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based off our conversation in slack, we'll leave off the include(CTest)
for now since it is currently causing the tests to be built unconditionally.
CXX-1792
CXX-2702
Tests will not be compiled by default.
To enable building tests, build with
-DBUILD_TESTING=ON