From c5064699ca59935cda93be77555ad77650bd00e1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 3 Oct 2017 23:40:54 +0100 Subject: Create proper CMake build (install & resources) --- .idea/.name | 1 + CMakeLists.txt | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++----- main.cpp | 6 ------ src/main/main.cpp | 6 ++++++ 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 .idea/.name delete mode 100644 main.cpp create mode 100644 src/main/main.cpp 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/main.cpp deleted file mode 100644 index f253cbe..0000000 --- a/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - std::cout << "Hello, World!" << std::endl; - return 0; -} \ No newline at end of file diff --git a/src/main/main.cpp b/src/main/main.cpp new file mode 100644 index 0000000..f253cbe --- /dev/null +++ b/src/main/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + return 0; +} \ No newline at end of file -- cgit v1.2.1