I am currently trying to deepen my understanding regarding CMake. I try to use http://libqglviewer.com/introduction.html]LibQGLViewer as a Third-Party library in a C++ Project of mine.
The CMakeLists.txt in the associated subdirectory looks like the following where the part, I have questions is the add_libary section and some header and source files were omitted for clarity
cmake_minimum_required (VERSION 3.5.1 FATAL_ERROR)
set(target_name QGLViewerQt5)
project(${target_name})
message(STATUS "BUILDING QGLViewer-2.7.0 FROM SOURCE!")
set(BASE_DIR QGLViewer)
set(VRENDER_DIR VRender)
set(CMAKE_AUTOMOC ON)
set(QGLheaders
${BASE_DIR}/camera.h
${BASE_DIR}/config.h
${BASE_DIR}/${VRENDER_DIR}/AxisAlignedBox.h
${BASE_DIR}/${VRENDER_DIR}/Exporter.h
)
set(QGLsources
${BASE_DIR}/camera.cpp
${BASE_DIR}/${VRENDER_DIR}/Exporter.cpp
)
add_library(${target_name} ${QGLsources} ${QGLheaders})
target_include_directories(${target_name}
PUBLIC .
)
target_link_libraries(${target_name}
${OPENGL_LIBRARIES}
Qt5::Core
Qt5::Widgets
Qt5::Xml
Qt5::OpenGL
)
set(CMAKE_AUTOMOC OFF)
install(TARGETS ${target_name} DESTINATION lib)
My Application runs and everything is fine.
However, I read that one should only include the source files with add_library and then use target_include_directories to consider the associated header files. So I changes the above part to
add_library(${target_name} SHARED ${QGLsources})
target_include_directories(${target_name}
PUBLIC
${PROJECT_SOURCE_DIR}/QGLViewer
${PROJECT_SOURCE_DIR}/QGLViewer/VRender
)
but now, I get an error trying to make my project
fatal error: QGLViewer/qglviewer.h: No such file or directory compilation terminated.
can you please tell me
- What exactly does PUBLIC . do? I know what PUBLIC does but what does the point mean?
- Why does it not work as before?
thank you in advance
PS: The folder structure is as follows