I have the following project structure
sandbox/
├── CMakeLists.txt
├── external
│ └── test_pkg
│ ├── CMakeLists.txt
│ ├── cmake
│ │ └── FindOnnxruntime.cmake
│ ├── include
│ │ └── pkg
│ │ └── test.hpp
│ └── src
│ ├── main.cpp
│ └── test.cpp
├── include
│ └── sandbox
│ └── sandbox.hpp
└── src
└── node.cpp
with sandbox/external/test_pkg/CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(test_pkg VERSION 0.1.0)
set(lib_target_name ${PROJECT_NAME}) # name of the library created by this project
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindOnnxruntime.cmake)
message("onnx includes: ${onnxruntime_INCLUDE_DIRS}")
message("onnx libraries: ${onnxruntime_LIBRARIES}")
# setup based on GPU
set(CMAKE_CUDA_ARCHITECTURES 86)
include_directories(
include
${onnxruntime_INCLUDE_DIRS}
)
add_library(${lib_target_name} SHARED
src/test.cpp
)
target_link_libraries(${lib_target_name}
${onnxruntime_LIBRARIES}
)
include(GNUInstallDirs)
target_include_directories(${lib_target_name}
PRIVATE
# where the library itself will look for its internal headers
${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC
# where top-level project will look for the library's public headers
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# where external projects will look for the library's public headers
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_executable(test_main src/main.cpp)
target_link_libraries(test_main
${lib_target_name}
)
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/pkg" # source directory
DESTINATION "include" # target directory
PATTERN "*.hpp" # select header files
)
sandbox/external/test_pkg/cmake/FindOnnxruntime.cmake
unset(onnxruntime_FOUND)
unset(onnxruntime_INCLUDE_DIRS)
unset(onnxruntime_LIBRARIES)
set(onnxruntime_INSTALL_PATH "/opt/onnxruntime")
find_path(onnxruntime_INCLUDE_DIRS NAMES onnxruntime_cxx_api.h
PATHS "${onnxruntime_INSTALL_PATH}/include")
find_library(onnxruntime_LIBRARIES
NAMES libonnxruntime.so
PATHS "${onnxruntime_INSTALL_PATH}/lib")
set(onnxruntime_INCLUDE_DIRS ${onnxruntime_INCLUDE_DIRS})
set(onnxruntime_LIBRARIES ${onnxruntime_LIBRARIES})
if(onnxruntime_INCLUDE_DIRS AND onnxruntime_LIBRARIES)
set(onnxruntime_FOUND 1)
endif(onnxruntime_INCLUDE_DIRS AND onnxruntime_LIBRARIES)
and top level sandbox/CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(sandbox)
add_subdirectory("external/test_pkg")
include_directories(
include
external/test_pkg/include
)
add_executable(sandbox_node src/node.cpp)
target_link_libraries(sandbox_node
test_pkg
)
test_pkg
project compiles fine standalone with cmake
When I use it as a subdirectory as above I get external/test_pkg/include/pkg/test.hpp:1:10: fatal error: onnxruntime_cxx_api.h: No such file or directory 1 | #include <onnxruntime_cxx_api.h>
What am I doing wrong here?