Bug 2217275

Summary: doctest CMake integration doesn't use /usr/include/doctest location
Product: [Fedora] Fedora Reporter: Georg Sauthoff <fedora>
Component: doctestAssignee: Nick Black <dank>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 37CC: dank
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.