Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

[CMake BUG] If I don't install, the built target opentracing won't carry correct INTERFACE include directories #132

Open
XuanYang-cn opened this issue Aug 15, 2020 · 0 comments

Comments

@XuanYang-cn
Copy link

CLion won't build install target of CMake. And if I build from source by CLion, the built targets won't carry correct INTERFACE include directories. So when linking with opentracing, the compiler will complain about not find the .h files.

something like this:

In file included from /somepath/TextMapCarrier.cpp:12:0:
/somepath/TextMapCarrier.h:14:10: fatal error: opentracing/propagation.h: No such file or directory
 #include <opentracing/propagation.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
otherpath/CMakeFiles/tracing.dir/build.make:62: recipe for target 'otherpath/CMakeFiles/tracing.dir/TextMapCarrier.cpp.o' failed
make[3]: *** [otherpath/CMakeFiles/tracing.dir/TextMapCarrier.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....
In file included from /somepath/TraceContext.cpp:12:0:
/somepath/TraceContext.h:14:10: fatal error: opentracing/tracer.h: No such file or directory
 #include <opentracing/tracer.h>
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
otherpath/tracing.dir/build.make:75: recipe for target 'src/tracing/CMakeFiles/tracing.dir/TraceContext.cpp.o' failed
make[3]: *** [otherpath/tracing.dir/TraceContext.cpp.o] Error 1
/sompath/TracerUtil.cpp:14:10: fatal error: opentracing/dynamic_load.h: No such file or directory
 #include <opentracing/dynamic_load.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

REASON

The reason is your CMakeLists.txt didn't give opentracing target a correct interface include directories. List below.

if (BUILD_SHARED_LIBS)
  add_library(opentracing SHARED ${SRCS})
  target_link_libraries(opentracing ${LIBRARIES})
  target_include_directories(opentracing INTERFACE "$<INSTALL_INTERFACE:include/>")
 ...
endif()

if (BUILD_STATIC_LIBS)
  add_library(opentracing-static STATIC ${SRCS})
 ...
  target_include_directories(opentracing-static INTERFACE "$<INSTALL_INTERFACE:include/>")
...
endif()

You only give an INSTALL_INTERFACE include directories for the target

So if I don't install (If I use CLion or trying to integrate opentracing with my own cmake project), When I link with opentracing, the above build errors will occur.

Suggestions

add other include directories to opentracing's INTERFACE include directories, something like this:

if (BUILD_SHARED_LIBS)
  add_library(opentracing SHARED ${SRCS})
  target_link_libraries(opentracing ${LIBRARIES})
  target_include_directories( opentracing INTERFACE 
"$<INSTALL_INTERFACE:include/>"
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/include> )
 ...
endif()
@XuanYang-cn XuanYang-cn changed the title If I don't install, the built target opentracing won't carry correct INTERFACE include directories [CMake BUG] If I don't install, the built target opentracing won't carry correct INTERFACE include directories Aug 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant