Improve CMake to separate built and dynamically installed SFML

This commit is contained in:
NaiJi ✨ 2021-09-14 17:51:06 +03:00
parent 944ad6a5bd
commit 3388aac813
1 changed files with 19 additions and 18 deletions

View File

@ -2,32 +2,33 @@ cmake_minimum_required(VERSION 3.5)
project(project-kyoku LANGUAGES CXX) project(project-kyoku LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wpedantic -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wpedantic -g")
set(CMAKE_THREAD_LIBS_INIT "-lpthread") set(CMAKE_THREAD_LIBS_INIT "-lpthread")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1) set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0) set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1) set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
file(GLOB_RECURSE SOURCES "include/*.h" "src/*.cpp" "src/*.h") file(GLOB_RECURSE SOURCES "include/*.h" "src/*.cpp" "src/*.h")
# STATIC #
# You need to build SFML from sources with cmake
set(SFML_LIB_DIR
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.so.2.5)
set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include)
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
add_executable(project-kyoku ${SOURCES}) add_executable(project-kyoku ${SOURCES})
target_link_libraries(project-kyoku ${SFML_LIB_DIR})
# DYNAMIC # option(SFML_BUILT "SFML_BUILT" ON)
# You only need to install SFML from your package manager
#find_package(SFML REQUIRED graphics window system) if(SFML_BUILT)
#add_executable(project-kyoku ${SOURCES}) set(SFML_LIB_DIR
#include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include) ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5
#target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.so.2.5)
set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include)
target_link_libraries(project-kyoku ${SFML_LIB_DIR})
else()
find_package(SFML)
target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network)
endif()
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)