1
General / SFML and cmake
« on: September 14, 2013, 07:38:31 pm »
Hello, I am re-writing a CMakeLists.txt file for a project to use FindSFML.cmake and am having problems. The project builds fine but fails linking when static build is selected. I know it isn't a problem with the libs, I've linked to them without issue with the old CMakeLists.txt.
I would really appreciate if someone could point out what I am doing wrong or give me some suggestions. Here is my current attempt.
I would really appreciate if someone could point out what I am doing wrong or give me some suggestions. Here is my current attempt.
# ChessPlusPlus
#
# Configuration options:
# -DCMAKE_BUILD_TYPE=Release|Debug
# -DSTATIC_BUILD=1|0
cmake_minimum_required (VERSION 2.8)
project (CHESSPP)
if(WIN32)
set(SFML_ROOT "" CACHE PATH "Path to SFML root directory")
option(STATIC_BUILD OFF "Link statically")
endif()
if(NOT JSONLIB)
set(JSONLIB ${CHESSPP_SOURCE_DIR}/lib/json-parser)
endif()
if(NOT BOOSTLIB)
set(BOOSTLIB ${CHESSPP_SOURCE_DIR}/lib/boost)
endif()
include_directories (${JSONLIB})
include_directories (${BOOSTLIB})
file(GLOB_RECURSE CHESSPP_SOURCES "src/*.cpp")
file(GLOB_RECURSE CHESSPP_HEADERS "src/*.hpp")
list(APPEND CHESSPP_SOURCES "lib/json-parser/json.c")
set (CHESSPP_INCLUDE_DIRS "")
foreach (_headerFile ${CHESSPP_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND CHESSPP_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES CHESSPP_INCLUDE_DIRS)
include_directories(${CHESSPP_INCLUDE_DIRS})
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
if(STATIC_BUILD)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2 REQUIRED system window graphics network audio)
include_directories (${SFML_INCLUDE_DIR})
link_directories(${SFML_ROOT}/lib)
add_executable (chesspp ${CHESSPP_SOURCES})
target_link_libraries(chesspp ${SFML_LIBRARIES} boost_system boost_filesystem)
#
# Configuration options:
# -DCMAKE_BUILD_TYPE=Release|Debug
# -DSTATIC_BUILD=1|0
cmake_minimum_required (VERSION 2.8)
project (CHESSPP)
if(WIN32)
set(SFML_ROOT "" CACHE PATH "Path to SFML root directory")
option(STATIC_BUILD OFF "Link statically")
endif()
if(NOT JSONLIB)
set(JSONLIB ${CHESSPP_SOURCE_DIR}/lib/json-parser)
endif()
if(NOT BOOSTLIB)
set(BOOSTLIB ${CHESSPP_SOURCE_DIR}/lib/boost)
endif()
include_directories (${JSONLIB})
include_directories (${BOOSTLIB})
file(GLOB_RECURSE CHESSPP_SOURCES "src/*.cpp")
file(GLOB_RECURSE CHESSPP_HEADERS "src/*.hpp")
list(APPEND CHESSPP_SOURCES "lib/json-parser/json.c")
set (CHESSPP_INCLUDE_DIRS "")
foreach (_headerFile ${CHESSPP_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND CHESSPP_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES CHESSPP_INCLUDE_DIRS)
include_directories(${CHESSPP_INCLUDE_DIRS})
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
if(STATIC_BUILD)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2 REQUIRED system window graphics network audio)
include_directories (${SFML_INCLUDE_DIR})
link_directories(${SFML_ROOT}/lib)
add_executable (chesspp ${CHESSPP_SOURCES})
target_link_libraries(chesspp ${SFML_LIBRARIES} boost_system boost_filesystem)