OSX 기준.
$ brew install sfml
$ brew install cmake
아래부터는 이 링크에 따름
cmake_modules
폴더를 생성cmake_modules
안에 둔다.CmakeLists.txt
작성하여 프로젝트 루트에 둔다. 위 폴더와는 관련 없다.
```c++# Enable debug symbols by default
# must be done before project() statement
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()
# (you can also set it on the command line: -D CMAKE_BUILD_TYPE=Release)
project(myproject)
# Set version information in a config.h file
set(myproject_VERSION_MAJOR 1)
set(myproject_VERSION_MINOR 0)
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")
# Define sources and executable
set(EXECUTABLE_NAME "myproject")
add_executable(${EXECUTABLE_NAME} main.cpp)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED network audio graphics window system)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()
# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
# CPack packaging
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${myproject_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${myproject_VERSION_MINOR}")
include(CPack)
```
예제 코드 main.cpp
는 다음과 같다.
#include "config.h"
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main(int argc, char* argv[]) {
// Code adapted from the SFML 2 "Window" example.
cout << "Version " << myproject_VERSION_MAJOR << "." << myproject_VERSION_MINOR << endl;
sf::Window App(sf::VideoMode(800, 600), "myproject");
while (App.isOpen()) {
sf::Event Event;
while (App.pollEvent(Event)) {
if (Event.type == sf::Event::Closed)
App.close();
}
App.display();
}
}
config.h
에서 설정 정보를 읽어와 출력하는 것.config.h.in
파일을 다음과 같이 작성한다. cmake를 통해서 config.h
를 생성할 것이다. #define myproject_VERSION_MAJOR @myproject_VERSION_MAJOR@
#define myproject_VERSION_MINOR @myproject_VERSION_MINOR@
$ cmake .
명령어로 빌드한다. Makefile
, config.h
등이 생성된다.make
명령어로 컴파일한다. myproject
이름으로 실행파일이 생성된다. $ ./myproject
로 실행해볼 수 있다.