使用cmake在Windows上编译glfw

时间:2018-09-07 06:56:24

标签: c++ windows cmake glfw

我不知道该如何命名,这是非常不准确的。无论如何,这里是一个问题:

我想在Visual Studio中创建一个必须使用glfw的CMake项目。但是,我不想使用预编译的二进制文件,我想使用CMakeLists.txt文件将glfw与应用程序一起编译。

这是我的CMake文件:

# CMakeList.txt : CMake project for BasicMandelbrotAnimation, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project(BasicMandelbrotAnimation)

# Set the main file to main.cpp
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup")

# Include our different directories
include_directories(include)
include_directories(source)

# Include all source files in source directory
file(GLOB SOURCE source/*)

# Compile GLFW
add_subdirectory(extlibs/GLFW)

# CMake GLFW Settings
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

# Add source to this project's executable.
add_executable (${PROJECT_NAME} ${SOURCE})
target_link_libraries(${PROJECT_NAME} glfw)

find_package(OpenGL REQUIRED)

target_include_directories(${PROJECT_NAME} PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${OPENGL_gl_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${OPENGL_glu_LIBRARY})

# TODO: Add tests and install targets if needed.

我得到的错误是“无法打开包含文件:'unistd.h':没有这样的文件或目录”,这使我很烦,因为这是UNIX文件,因此如何使这些文件适合在Windows中编译? / p>

谢谢。

编辑:

这个问题似乎是重复的,但并非如此。 unistd.h只是第一个问题,让我们看一下有问题的文件:

#ifndef _glfw3_x11_platform_h_
#define _glfw3_x11_platform_h_

#include <unistd.h>
#include <signal.h>
#include <stdint.h>
#include <dlfcn.h>

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xcursor/Xcursor.h>

// The XRandR extension provides mode setting and gamma control
#include <X11/extensions/Xrandr.h>

// The Xkb extension provides improved keyboard support
#include <X11/XKBlib.h>

// The Xinerama extension provides legacy monitor indices
#include <X11/extensions/Xinerama.h>

#if defined(_GLFW_HAS_XF86VM)
 // The Xf86VidMode extension provides fallback gamma control
 #include <X11/extensions/xf86vmode.h>
#endif

在这里,首先是unistdh丢失了,我将其替换为另一篇文章中提出的内容,但是现在丢失了其他文件,特别是dlfcn.h和X11文件,我不知道如何解决这个问题。

谢谢。

EDIT2:

忘记x11_platform.h中的内容。问题在这一行:

target_link_libraries(${PROJECT_NAME} glfw)

执行此操作时,cmake需要x11_platform.h,这在Windows上不存在。有人知道如何跳过此文件或以其他方式链接吗?

谢谢。

0 个答案:

没有答案