问题
I am writing project in c++, and I have problem with importing libraries in cmake. The third party library, which is importing, does not propagate include directories.
Root /CMakeLists.txt
# Top level CMakeLists.txt
cmake_minimum_required(VERSION 3.9.2 FATAL_ERROR)
project(camera_calib)
add_subdirectory(${PROJECT_SOURCE_DIR}/nana)
file(GLOB SRC "${PROJECT_SOURCE_DIR}/src/*.cpp")
add_executable(camera_calib_exe ${SRC})
target_include_directories(camera_calib_exe PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(camera_calib_exe nana_lib)
/nana/CMakeLists.txt
# nana c++ gui CMakeLists.txt
cmake_minimum_required(VERSION 3.9.2 FATAL_ERROR)
project(nana VERSION 1.5.6 LANGUAGES CXX)
add_library(nana_lib STATIC IMPORTED)
set_property(TARGET nana_lib PROPERTY IMPORTED_IMPLIB_DEBUG ${PROJECT_SOURCE_DIR}/lib/nana_v141_Debug_x64.lib)
set_property(TARGET nana_lib PROPERTY IMPORTED_IMPLIB_RELEASE ${PROJECT_SOURCE_DIR}/lib/nana_v141_Release_x64.lib)
set_property(TARGET nana_lib PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include)
#set_property(TARGET nana_lib PROPERTY INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include)
Example of code /src/main.cpp
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
int main(int argc, char** argv)
{
nana::form fm(nana::rectangle(0, 0, 1900, 1000));
fm.caption("Camera Calibration");
nana::button btn_openCam(fm, nana::rectangle(1770, 20, 100, 30));
btn_openCam.caption("Open cameras");
btn_openCam.events().click(nana::API::exit_all);
nana::button btn_closeCam(fm, nana::rectangle(1770, 20 + 30 + 20, 100, 30));
btn_closeCam.enabled(false);
btn_closeCam.caption("Close cameras");
btn_closeCam.events().click(nana::API::exit_all);
nana::button btn_exit(fm, nana::rectangle(1770, 900, 100, 30));
btn_exit.caption("Exit");
btn_exit.events().click(nana::API::exit_all);
fm.show();
nana::exec();
std::cout << "lala";
return 0;
}
The Error List is:
E1696 cannot open source file "nana/gui.hpp"
E1696 cannot open source file "nana/gui/widgets/label.hpp"
E1696 cannot open source file "nana/gui/widgets/button.hpp"
Why nana_lib target does not propagate include directories for camera_calib_exe target? How to solve that issue?
Thank you in advance.
回答1:
The scope for imported target's is important. Try to add the GLOBAL
option to add_library()
:
add_library(nana_lib STATIC IMPORTED GLOBAL)
"The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility."
Reference
- add_library()
来源:https://stackoverflow.com/questions/48355884/include-directories-for-imported-library