简体   繁体   English

CMake和find_package问题

[英]Issue with CMake and find_package

I'm very new to CMake, and I try to write a CMake file for my project. 我是CMake的新手,我尝试为我的项目编写CMake文件。 My project consists of .h and .cpp files, generating an executable, and using the SFML library. 我的项目由.h和.cpp文件组成,生成可执行文件,并使用SFML库。 I've installed the findSFML script, I use the find_package function of CMake: 我已经安装了findSFML脚本,我使用了CMake的find_package函数:

cmake_minimum_required(VERSION 2.6)

# Projet name
project("Witch_Blast")

file(
        GLOB_RECURSE
        source_files
        src/*
)

add_executable(
        "Witch_Blast"
    ${source_files}
)

# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.1 REQUIRED system window graphics audio)
target_link_libraries(Witch_Blast ${SFML_LIBRARIES})

I try to generate a Windows Code::Blocks project. 我尝试生成Windows Code :: Blocks项目。 It finds the library and generate projects files. 它找到该库并生成项目文件。

My problem: It won't compile because it won't find the SFML header files, and I cannot modify the project setting... 我的问题:无法编译,因为找不到SFML头文件,并且我无法修改项目设置...

What have I done wrong ? 我做错了什么?

Thanks ! 谢谢 !

EDIT: 编辑:

CMake generation output: CMake生成输出:

-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found SFML 2.1 in C:/Lib/SFML-2.1_TDM/include
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Seb/Dev/Witch Blast/cmakedir

message(SFML_LIBRARIES): 消息(SFML_LIBRARIES):

debugC:/Lib/SFML-2.1_TDM/lib/libsfml-system-d.aoptimizedC:/Lib/SFML-2.1_TDM/lib/
libsfml-system.adebugC:/Lib/SFML-2.1_TDM/lib/libsfml-window-d.aoptimizedC:/Lib/S
FML-2.1_TDM/lib/libsfml-window.adebugC:/Lib/SFML-2.1_TDM/lib/libsfml-graphics-d.
aoptimizedC:/Lib/SFML-2.1_TDM/lib/libsfml-graphics.adebugC:/Lib/SFML-2.1_TDM/lib
/libsfml-audio-d.aoptimizedC:/Lib/SFML-2.1_TDM/lib/libsfml-audio.a

(But it's not a linker error, it's an include path error) (但这不是链接器错误,而是包含路径错误)

You need to add the header directory to you compiler's path. 您需要将头目录添加到编译器的路径。

include_directories(${SFML_INCLUDE_DIR})

All variables find_package(SFML) sets can be found here . 所有变量find_package(SFML)集都可以在此处找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM