我正在制作一个使用GLEW的cmake项目。我想动态构建GLEW(不仅仅是链接编译库)。我使用add_subdirectory将第三方库添加到我的项目中。这是我的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)
正如您所看到的,我为第三方库指定了输出目录($ {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的作用,以及如何使它在我需要的地方放置编译的lib而不触及GLEW的CMake源?
答案 0 :(得分:0)
使用cmake构建GLEW源代码。您可以在cmake项目文件夹中创建一个名为 ./ external 的文件夹,并将GLEW代码放入该文件夹中。
有关详细信息,请参阅http://www.opengl-tutorial.org/的教程
和可运行的项目源代码:http://www.opengl-tutorial.org/download/
add_subdirectory (external)
include_directories(
external/AntTweakBar-1.16/include/
external/glfw-3.1.2/include/
external/glm-0.9.7.1/
external/glew-1.13.0/include/
external/assimp-3.0.1270/include/
external/bullet-2.81-rev2613/src/
.
)
set(ALL_LIBS
${OPENGL_LIBRARY}
glfw
GLEW_1130
)
add_definitions(
-DTW_STATIC
-DTW_NO_LIB_PRAGMA
-DTW_NO_DIRECT3D
-DGLEW_STATIC
)
target_link_libraries(FOO
${ALL_LIBS}
)