Bug 2217275 - doctest CMake integration doesn't use /usr/include/doctest location
Summary: doctest CMake integration doesn't use /usr/include/doctest location
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: doctest
Version: 37
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Nick Black
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-06-25 21:08 UTC by Georg Sauthoff
Modified: 2023-06-25 21:08 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: ---
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Georg Sauthoff 2023-06-25 21:08:51 UTC
The doctest documentation on cmake includes a minimal example that fails to compile on Fedora 37, when doctest-devel is installed:

https://github.com/doctest/doctest/blob/master/doc/markdown/build-systems.md#cmake


```
add_executable(tests main.cpp)
target_compile_features(tests PRIVATE cxx_std_17)
target_link_libraries(tests PRIVATE doctest::doctest)
```

Reproducible: Always

Steps to Reproduce:
1. dnf install doctest-devel
2. create CMakeLists.txt, check.cc check_main.cc such that:
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.7...3.26)
project(foo CXX)
find_package(doctest REQUIRED)
add_executable(check check_main.cc check.cc)
target_link_libraries(check PRIVATE doctest::doctest)
$ cat check_main.cc
cat check_main.cc 
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
$ cat check.cc
#include <doctest.h>
TEST_CASE("dummy test")
{
    CHECK(23 == 46/2);
}
3. mkdir build
4. cd build
5. cmake ..
6. make check
Actual Results:  
/home/juser/doctest-foo/check_main.cc:2:10: fatal error: doctest.h: No such file or directory
    2 | #include <doctest.h>
      |          ^~~~~~~~~~~
compilation terminated

Expected Results:  
No compile errors and succeeding test.

Since the doctest-devel package installs the doctest header into /usr/include/doctest, the expectation here is that INCLUDE_DIRECTORIES property is updated accordingly when target linking doctest::doctest in CMakeLists.txt.

The package also contains /usr/lib64/cmake/doctest/doctestTargets.cmake contains code for this, but apparently it doesn't work for the Fedora specific install location.

This change fixes the issue for me:

```
--- doctestTargets.cmake	2023-06-25 22:44:46.100690490 +0200
+++ /usr/lib64/cmake/doctest/doctestTargets.cmake	2023-06-25 22:45:00.974747944 +0200
@@ -64,7 +64,7 @@
 
 set_target_properties(doctest::doctest PROPERTIES
   INTERFACE_COMPILE_FEATURES "cxx_std_11"
-  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
+  INTERFACE_INCLUDE_DIRECTORIES "/usr/include/doctest"
 )
 
 if(CMAKE_VERSION VERSION_LESS 3.0.0)
```

Of course, one can also work around it my manually adding /usr/include/doctest to the test executable cmake target, but that would be a quite Fedora specific workaround.

I think it's appropriate for the Fedora doctest-devel to include the above patch (or a similar one) - or simply to move the doctest.h header to /usr/include.


Note You need to log in before you can comment on or make changes to this bug.