Since it is troublesome that the Linux version of OpenSiv3D can only be built with the cloned file OpenSiv3D/Linux/App
, make it compatible with make install
.
Save the following patch as diff.patch
and
diff.patch
diff --git a/Linux/CMakeLists.txt b/Linux/CMakeLists.txt
index f59da581..fe1e7c97 100644
--- a/Linux/CMakeLists.txt
+++ b/Linux/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.0)
find_package(PkgConfig)
-project(OpenSiv3D_Linux CXX)
+project(Siv3D VERSION 0.4.3 LANGUAGES CXX)
enable_language(C)
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall -Wextra -Wno-unknown-pragmas -fPIC -msse4.1 -D_GLFW_X11")
@@ -26,10 +26,8 @@ endif()
#set(CMAKE_BUILD_TYPE Release)
pkg_check_modules(LIBSIV3D REQUIRED glib-2.0 gobject-2.0 gio-2.0 gl libpng libturbojpeg x11 xi xinerama xcursor xrandr gl glu freetype2 openal opencv4 ogg vorbis zlib)
-include_directories(
- "/usr/include"
- "."
+set(INCLUDE_DIRS
"../Siv3D/include"
"../Siv3D/src/Siv3D"
"../Siv3D/src/Siv3D-Platform/Linux"
@@ -725,6 +723,22 @@ set(SOURCE_FILES
add_library(Siv3D STATIC ${SOURCE_FILES})
-target_link_libraries(Siv3D
-)
-
+install(DIRECTORY ../Siv3D/include/ DESTINATION include/Siv3D)
+find_package(Boost REQUIRED COMPONENTS filesystem)
+target_link_libraries(Siv3D GLEW pthread dl udev freetype harfbuzz glib-2.0 gobject-2.0 gio-2.0 png turbojpeg gif webp openal ogg vorbis vorbisenc vorbisfile /usr/local/lib/libboost_filesystem.a avformat avcodec avutil swresample ${LIBSIV3D_LIBRARIES})
+target_include_directories(Siv3D PUBLIC
+ $<BUILD_INTERFACE:${INCLUDE_DIRS}>
+ $<INSTALL_INTERFACE:include/Siv3D>
+ $<INSTALL_INTERFACE:include/Siv3D/ThirdParty>)
+install(TARGETS Siv3D
+ EXPORT Siv3DConfig
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ INCLUDES DESTINATION include/Siv3D include/Siv3D/ThirdParty)
+install(EXPORT Siv3DConfig
+ DESTINATION lib/cmake/siv3d
+ EXPORT_LINK_INTERFACE_LIBRARIES)
+include(CMakePackageConfigHelpers)
+set(VERSION_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/Siv3DConfigVersion.cmake)
+write_basic_package_version_file(${VERSION_CONFIG} COMPATIBILITY ExactVersion)
+install(FILES ${VERSION_CONFIG} DESTINATION lib/cmake/siv3d)
$ git apply diff.patch
Apply at. After that, put in the necessary libraries as usual, and after cmake
make install
By doing so, the default path will install the necessary files in / usr/local /
. After the installation is complete, delete the cloned files as you don't need them.
When creating the app, create the following CMake file and Siv3D source file in the same directory
CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
project(App name CXX)
find_package(Siv3D 0.4.3 REQUIRED)
add_executable(App name Main.cpp)
set_target_properties(App name PROPERTIES CXX_STANDARD 17)
target_link_libraries(App name Siv3D)
$ mkdir build && cd build
$ cmake ..
$ make
With a file structure like this, just by saying
CMakeLists.txt
Main.cpp
build/
├── App executable file
└── Build logs, etc.
You can build without worrying about where to install Siv3D.
Furthermore, if you can do this, you can change the version with just the second argument of find_package, which makes it easier to manage.
Recommended Posts