CMake和find_package问题

时间:2014-04-13 09:13:13

标签: c++ cmake codeblocks sfml

我是CMake的新手,我尝试为我的项目编写一个CMake文件。 我的项目由.h和.cpp文件组成,生成可执行文件,并使用SFML库。 我已经安装了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})

我尝试生成一个Windows Code :: Blocks项目。 它找到了库并生成了项目文件。

我的问题: 它不会编译,因为它找不到SFML头文件,我无法修改项目设置...

我做错了什么?

谢谢!

编辑:

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

消息(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

(但这不是链接器错误,它是包含路径错误)

1 个答案:

答案 0 :(得分:1)

您需要将头目录添加到编译器的路径中。

include_directories(${SFML_INCLUDE_DIR})

可以找到所有变量find_package(SFML)here