【发布时间】:2017-04-29 00:49:45
【问题描述】:
我正在制作一个使用 GLEW 的 cmake 项目。我想即时构建 GLEW(不仅仅是针对已编译库的链接)。我使用 add_subdirectory 将第 3 方库添加到我的项目中。这是我的 CMakeLists.txt 现在的样子:
cmake_minimum_required (VERSION 2.6)
project (quokka)
#configure_file (
# "${CMAKE_CURRENT_SOURCE_DIR}/TutorialConfig.h.in"
# "${CMAKE_CURRENT_SOURCE_DIR}/TutorialConfig.h"
# )
include_directories(${CMAKE_SOURCE_DIR}/../3rd_party/glew/include)
include_directories(${CMAKE_SOURCE_DIR}/../3rd_party/glfw/include)
include_directories(${CMAKE_SOURCE_DIR}/../3rd_party/freetype-2.6.2/include)
include_directories(${CMAKE_SOURCE_DIR})
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../../temp)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=c++11")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OUTPUT_LIB_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../../temp/Debug)
endif ()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(OUTPUT_LIB_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../../temp/Release)
endif ()
set(GLFW ${OUTPUT_LIB_DIRECTORIES}/glfw)
set(FREETYPE ${OUTPUT_LIB_DIRECTORIES}/freetype)
set(GLEW ${OUTPUT_LIB_DIRECTORIES}/glew)
add_subdirectory(${CMAKE_SOURCE_DIR}/../3rd_party/glfw/ ${CMAKE_CURRENT_SOURCE_DIR}/../../temp/lib/glfw)
add_subdirectory(${CMAKE_SOURCE_DIR}/../3rd_party/glew/build/cmake ${CMAKE_CURRENT_SOURCE_DIR}/../../temp/lib/glew)
add_subdirectory(${CMAKE_SOURCE_DIR}/../3rd_party/freetype-2.6.2/ ${CMAKE_CURRENT_SOURCE_DIR}/../../temp/lib/freetype)
add_subdirectory(Input)
add_subdirectory(Process)
add_subdirectory(Application)
add_subdirectory(View)
add_subdirectory(GameLogic)
add_subdirectory(UID)
add_subdirectory(Actor)
add_subdirectory(AssetManager)
add_subdirectory(GUI)
add_subdirectory(GraphicsEngine)
add_executable(quokka main.cpp)
target_link_libraries(quokka Input ProcessLibrary Application View GameLogic UID Actor AssetManager GUI GraphicsEngine)
target_link_libraries(quokka glfw freetype)
if (UNIX)
target_link_libraries(quokka glew Xrandr Xinerama Xi Xcursor X11 Xxf86vm pthread GL)
endif (UNIX)
if (WIN32)
target_link_libraries(quokka glew32 opengl32)
endif (WIN32)
如您所见,我为 3rd 方库指定了输出目录 (${CMAKE_CURRENT_SOURCE_DIR}/../../temp/lib/glfw),它适用于 GLFW 和 freetype,但 GLEW 最终会出现在其他地方。因此,我使用此设置生成 Visual Studio 项目,出于某种原因,GLEW 的输出目录是C:\_work\quokka_plus\temp\VSProjects\bin\Debug\。结果,当我构建我的项目时,它找不到 glew32.lib。为什么 CMake 对 GLEW 的行为与对 GLFW 和 freetype 的行为不同,以及如何在不接触 GLEW 的 CMake 源的情况下将编译后的库放置在我需要的地方?
【问题讨论】:
-
Why does CMake act differently for GLEW than it does for GLFW and freetype- GLEW 项目本身可能会修改变量 LIBRARY_OUTPUT_PATH 左右。这种变量的外部修改并不是每个项目都应该准备的。how to make it place compiled lib in a place I need without touching CMake sources of GLEW?- 通常,您不能强制 3d 方项目将东西 构建 到特定位置。但是安装的东西是不同的:大多数项目在安装库时遵循一些通常的约定等等。 -
@Tsyvarev 您是否建议我将第 3 方库与我的项目分开构建和安装,而不是将其构建为我的项目的一部分?
-
您可以在配置项目时构建和安装 3d 方库(使用
execute_process命令)。