Make a Linux version of OpenSiv3D with find_package a little easier

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

Make a Linux version of OpenSiv3D with find_package a little easier
Let's make dependency management with pip a little easier
Make C compilation a little easier
[PyTorch] A little understanding of CrossEntropyLoss with mathematical formulas
Make your cursor a photo of your choice on Linux
It was a little difficult to do flask with the docker version of nginx-unit
Make a LINE bot with GoogleAppEngine / py. Simple naked version
Make a SonicWall SSL VPN connection with the Linux CLI
Make a fortune with Python
A brief summary of Linux
A little stuck with chainer
Make a fire with kdeplot
Write processing time measurement a little easier using the with clause
On Linux, the time stamp of a file is a little past.
I tried to make a mechanism of exclusive control with Go
Let's make a GUI with python.
Make a sound with Jupyter notebook
Let's make a breakout with wxPython
Make a recommender system with python
Make a filter with a django template
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Make a nice graph with plotly
Run a batch of Python 2.7 with nohup on Amazon Linux AMI on EC2
Make a DNN-CRF with Chainer and recognize the chord progression of music
I made a tool that makes decompression a little easier with CLI (Python3)
Building a Python3 environment with Amazon Linux2
Let's make a shiritori game with Python
Make a video player with PySimpleGUI + OpenCV
A little niche feature introduction of faiss
[Linux] Summary of middleware version confirmation commands
Try to make a kernel of Jupyter
Make a relation diagram of Python module
Make a rare gacha simulator with Flask
Make a Notebook Pipeline with Kedro + Papermill
A little scrutiny of pandas 1.0 and dask
A quick overview of the Linux kernel
Make Unity Accelerator a service on Linux
Make a partially zoomed figure with matplotlib
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Create a virtual environment with Python_Mac version
Make pypy submission easier with atcoder-cli (python)
Make a cascade classifier with google colaboratory
Let's make a simple language with PLY 1
Make a logic circuit with a perceptron (multilayer perceptron)
[Linux] Build a jenkins environment with Docker
Make a Yes No Popup with Kivy
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Make API of switchbot thermo-hygrometer with Node-RED
Let's make a web framework with Python! (2)
Make common settings with subplot of matplotlib
[Linux] Build a Docker environment with Amazon Linux 2
Introducing AE scripts that may make sound matching in C4D a little easier
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 3] ~ Implementation of nervous breakdown ~