target_link_libraries result incorrect relative path in Visual Studio
Hi,
My problem:
My environment:
- Win10
- CMake3.15
- Visual Studio 2019
My project folder structure:
root
| CMakeLists.txt
|
|-ThirdParty
| |-FreeGLUT
| |-GLEW
| |-GLM
|
|-src
| | CMakeLists.txt
| |
| |-Modules
| | | CMakeLists.txt
| | |
| | |-Common
| | | CMakeLists.txt
| | |-O3GL
| | | CMakeLists.txt
| |
| |-Apps
| | | CMakeLists.txt
| | |
| | |-testO3GL
| | | CMakeLists.txt
My CMakeLists:
- root/CMakeLists.txt
cmake_minimum_required( VERSION 3.2 )
#Create Project
project( PanoRGBD )
#Setup CMake
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OFF )
SET(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install/" CACHE PATH "${CMAKE_CURRENT_SOURCE_DIR}/install/" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Cmake/Modules/")
#Setup project setting
# Use folders (for IDE project grouping)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#Setup include path
include_directories(${CMAKE_SOURCE_DIR}/ThirdParty/GLM/src/)
include_directories(${CMAKE_SOURCE_DIR}/ThirdParty/GLEW/install/include/)
include_directories(${CMAKE_SOURCE_DIR}/ThirdParty/FreeGLUT/install/include/)
include_directories(${CMAKE_SOURCE_DIR}/ThirdParty/OpenCV/install/include/)
include_directories(${CMAKE_SOURCE_DIR}/ThirdParty/JSON/install/include/)
include_directories(${CMAKE_SOURCE_DIR}/src/Modules/)
#Setup predefine def
add_definitions(-D_USE_MATH_DEFINES)
#
add_subdirectory("src")
- root/src/CMakeLists.txt
#Modules
add_subdirectory("Modules")
#Apps
add_subdirectory("Apps")
- root/src/Modules/CMakeLists.txt
add_subdirectory("Common")
add_subdirectory("O3GL")
- root/src/Apps/CMakeLists.txt
add_subdirectory("testO3GL")
- root/src/Modules/Common/CMakeLists.txt
#Setup libraries
file(GLOB common_srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB common_hpps ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
file(GLOB common_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
add_library(Common STATIC ${common_srcs} ${common_hpps} ${common_hdrs})
target_link_libraries(Common ${CMAKE_SOURCE_DIR}/ThirdParty/GLM/build/glm/Release/glm_static.lib)
#Setup project setting
set_target_properties(Common PROPERTIES FOLDER "Modules")
#Setup install
install(FILES ${common_hpps} ${common_hdrs} DESTINATION include/Common/)
install(TARGETS Common
RUNTIME DESTINATION bin/Common
LIBRARY DESTINATION lib/Common
ARCHIVE DESTINATION lib/Common)
- root/src/Modules/O3GL/CMakeLists.txt
#Setup libraries
file(GLOB o3gl_srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB o3gl_hpps ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
file(GLOB o3gl_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
add_library(O3GL STATIC ${o3gl_srcs} ${o3gl_hpps} ${o3gl_hdrs})
target_link_libraries(O3GL ${CMAKE_SOURCE_DIR}/ThirdParty/GLEW/install/lib/glew.lib)
target_link_libraries(O3GL ${CMAKE_SOURCE_DIR}/ThirdParty/FreeGLUT/install/lib/freeglut_static.lib)
target_link_libraries(O3GL Common)
#Setup project setting
set_target_properties(O3GL PROPERTIES FOLDER "Modules")
#Setup install
install(FILES ${o3gl_hpps} ${o3gl_hdrs} DESTINATION include/O3GL/)
install(TARGETS O3GL
RUNTIME DESTINATION bin/O3GL
LIBRARY DESTINATION lib/O3GL
ARCHIVE DESTINATION lib/O3GL)
- root/src/Apps/testO3GL/CMakeLists.txt
#Setup libraries
file(GLOB testO3GL_srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB testO3GL_hpps ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
file(GLOB testO3GL_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
add_executable(testO3GL ${testO3GL_srcs} ${testO3GL_hpps} ${testO3GL_hdrs})
target_link_libraries(testO3GL O3GL)
#Setup project setting
set_target_properties(testO3GL PROPERTIES FOLDER "Apps")
#Setup install
install(TARGETS testO3GL
RUNTIME DESTINATION bin/testO3GL)