Skip to content

Disable testing when using BUILD_TESTING #1682

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

Merged
merged 1 commit into from
Aug 18, 2020
Merged

Conversation

pfultz2
Copy link
Contributor

@pfultz2 pfultz2 commented Feb 1, 2019

CMake uses this variable to enable/disable tests in their CTest module(which is why the variable name is highlighted by github as a special value).

More importantly, it allows pybind to be installed directly with cget with cget install pybind11/pybind since cget also sets BUILD_TESTING to Off when not testing a package.

It will still default to On when pybind is not a master project, and Off when it is not.

@wjakob
Copy link
Member

wjakob commented Jun 10, 2019

Seems reasonable, but can't you do this without introducing a redundant option (which already exists internally in CMake). This will probably not work, but something like:

option(PYBIND11_TEST    "Build pybind11 test suite?"     ${BUILD_TESTING} AND ${PYBIND11_MASTER_PROJECT})

@wjakob
Copy link
Member

wjakob commented Jul 15, 2019

ping?

@pfultz2
Copy link
Contributor Author

pfultz2 commented Jul 15, 2019

Seems reasonable, but can't you do this without introducing a redundant option

That option only exists if you include CTest, and it will default to On always. This will set the default based on whether its a subproject.

This is also similar to the BUILD_SHARED_LIBS variable. It is recommended to set it by default to On in the project when you want the library to be built as a shared library(but the user can override the variable to get a static library), from BUILD_SHARED_LIBS:

This variable is often added to projects as an OPTION so that each user of a project can decide if they want to build the project using shared or static libraries.

@henryiii
Copy link
Collaborator

henryiii commented Aug 18, 2020

I thought I'd fixed issues like this, but my logic for BUILD_TESTING was not quite right.

The normal/simplest/best way to do this for a project that uses CTest (which I think we should look at using later) would be:

if(PYBIND11_MASTER_PROJECT)
  include(CTest) # defines BUILD_TESTING
  if(BUILD_TESTING)
    add_subdirectory(tests)
  endif()
endif()

The downside is that you can't build the tests if this is not the master project, but in general that's not a good idea and probably not really supported anyway.

@henryiii henryiii self-assigned this Aug 18, 2020
@henryiii henryiii merged commit 69821d9 into pybind:master Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants