简体   繁体   中英

Issue with CMake and find_package

I'm very new to CMake, and I try to write a CMake file for my project. My project consists of .h and .cpp files, generating an executable, and using the SFML library. I've installed the findSFML script, I use the find_package function of CMake:

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. 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...

What have I done wrong ?

Thanks !

EDIT:

CMake generation output:

-- 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):

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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