aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthecharlesblake2017-10-03 23:40:54 +0100
committerthecharlesblake2017-10-13 18:46:14 +0100
commitc5064699ca59935cda93be77555ad77650bd00e1 (patch)
tree40178f7c2f2d8276e7e4b686e3f7faea350c889f
parentAdd CLion basic project, including CMake build (diff)
downloadmetasol-c5064699ca59935cda93be77555ad77650bd00e1.tar.gz
metasol-c5064699ca59935cda93be77555ad77650bd00e1.zip

Create proper CMake build (install & resources)

-rw-r--r--.idea/.name1
-rw-r--r--CMakeLists.txt58
-rw-r--r--src/main/main.cpp (renamed from main.cpp)0
3 files changed, 54 insertions, 5 deletions
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..a8eb715
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+solitaire_pip \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1199237..b29582d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,55 @@
-cmake_minimum_required(VERSION 3.8)
-project(GeneralSolitaireSolver)
+# File based on solitaire_pip at https://stackoverflow.com/questions/21163188/most-simple-but-complete-cmake-example
-set(CMAKE_CXX_STANDARD 17)
+cmake_minimum_required(VERSION 3.0)
+project(solitaire_pip)
-set(SOURCE_FILES main.cpp)
-add_executable(GeneralSolitaireSolver ${SOURCE_FILES}) \ No newline at end of file
+set(CMAKE_CXX_STANDARD 14)
+
+###############################################################################
+## file globbing ##############################################################
+###############################################################################
+
+# these instructions search the directory tree when cmake is
+# invoked and put all files that match the pattern in the variables
+# `sources` and `data`
+file(GLOB_RECURSE sources src/main/*.cpp src/main/*.h)
+file(GLOB_RECURSE sources_test src/test/*.cpp)
+file(GLOB_RECURSE data resources/*)
+
+###############################################################################
+## target definitions #########################################################
+###############################################################################
+
+# add the data to the target, so it becomes visible in some IDE
+add_executable(solitaire_pip ${sources} ${data})
+
+# just for example add some compiler flags
+target_compile_options(solitaire_pip PUBLIC -std=c++1y -Wall -Wfloat-conversion)
+
+# this lets me include files relative to the root src dir with a <> pair
+target_include_directories(solitaire_pip PUBLIC src/main)
+
+# this copies all resource files in the build directory
+# we need this, because we want to work with paths relative to the executable
+file(COPY ${data} DESTINATION resources)
+
+###############################################################################
+## packaging ##################################################################
+###############################################################################
+
+# all install commands get the same destination. this allows us to use paths
+# relative to the executable.
+install(TARGETS solitaire_pip DESTINATION solitaire_pip)
+# this is basically a repeat of the file copy instruction that copies the
+# resources in the build directory, but here we tell cmake that we want it
+# in the package
+install(DIRECTORY resources DESTINATION solitaire_pip)
+
+set(CPACK_OUTPUT_FILE_PREFIX installer)
+set(CPACK_PACKAGE_VERSION "1.0.0")
+
+# we don't want to split our program up into several things
+set(CPACK_MONOLITHIC_INSTALL 1)
+
+# This must be last
+include(CPack) \ No newline at end of file
diff --git a/main.cpp b/src/main/main.cpp
index f253cbe..f253cbe 100644
--- a/main.cpp
+++ b/src/main/main.cpp