From cf23e11c93926efede379ab230a59db19f32a015 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 5 Dec 2015 22:49:18 +0100 Subject: [PATCH] added simple CMake project file --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ angle.cpp | 4 ++-- config.h.in | 9 +++++++++ general.pri | 2 +- location.cpp | 4 ++-- location.h | 2 +- main.cpp | 15 +++++++++++---- main.h | 4 ++-- utils.cpp | 2 +- 9 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e81c6be --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +# meta data +set(META_PROJECT_NAME geocoordinatecalculator) +set(META_APP_NAME "geocoordinatecalculator") +set(META_APP_AUTHOR "Martchus") +set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") +set(META APP_DESCRIPTION "Command line tool for basic calculations with geo coordinates such as format conversions and calculation of distance, bearing, mid point, destination and more.") +set(META_VERSION_MAJOR 1) +set(META_VERSION_MINOR 0) +set(META_VERSION_PATCH 1) + +# define project +project(${META_PROJECT_NAME}) + +# stringification of meta data +set(META_PROJECT_NAME_STR "\"${META_PROJECT_NAME}\"") +set(META_APP_NAME_STR "\"${META_APP_NAME}\"") +set(META_APP_AUTHOR_STR "\"${META_APP_AUTHOR}\"") +set(META_APP_URL_STR "\"${META_APP_URL}\"") +set(APP_DESCRIPTION_STR "\"${APP_DESCRIPTION}\"") +set(META_APP_VERSION_STR "\"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}\"") + +# add configuration header +configure_file ( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h" +) +include_directories("${PROJECT_BINARY_DIR}") + +# add source and header files +file(GLOB PROJ_FILES "*.h" "*.cpp" "*.c") + +# executable and linking +add_executable(${META_PROJECT_NAME} ${PROJ_FILES}) +target_link_libraries(${META_PROJECT_NAME} c++utilities) + +# enable C++11 +set_property(TARGET ${META_PROJECT_NAME} PROPERTY CXX_STANDARD 11) + +# add install target +install(TARGETS ${META_PROJECT_NAME} DESTINATION bin) diff --git a/angle.cpp b/angle.cpp index f0970e0..b28d5da 100644 --- a/angle.cpp +++ b/angle.cpp @@ -1,5 +1,5 @@ -#include "utils.h" -#include "angle.h" +#include "./utils.h" +#include "./angle.h" #include diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..2f9ca46 --- /dev/null +++ b/config.h.in @@ -0,0 +1,9 @@ +#ifndef APP_METADATA_AVAIL +#define APP_METADATA_AVAIL +#define PROJECT_NAME @META_PROJECT_NAME_STR@ +#define APP_NAME @META_APP_NAME_STR@ +#define APP_VERSION @META_APP_VERSION_STR@ +#define APP_AUTHOR @META_APP_AUTHOR_STR@ +#define APP_URL @META_APP_URL_STR@ +#define APP_DESCRIPTION @META_APP_DESCRIPTION_STR@ +#endif // APP_METADATA_AVAIL diff --git a/general.pri b/general.pri index 60bf445..6e654cd 100644 --- a/general.pri +++ b/general.pri @@ -1,5 +1,4 @@ #dirs -UI_DIR = ./gui MOC_DIR = ./moc OBJECTS_DIR = ./obj RCC_DIR = ./res @@ -18,6 +17,7 @@ CONFIG(debug, debug|release) { TARGET = $${targetprefix}$${projectname} } # add defines +DEFINES += "APP_METADATA_AVAIL" DEFINES += "'PROJECT_NAME=\"$${projectname}\"'" DEFINES += "'APP_NAME=\"$${appname}\"'" DEFINES += "'APP_AUTHOR=\"$${appauthor}\"'" diff --git a/location.cpp b/location.cpp index 0a06b38..429abac 100644 --- a/location.cpp +++ b/location.cpp @@ -1,5 +1,5 @@ -#include "location.h" -#include "utils.h" +#include "./location.h" +#include "./utils.h" #include diff --git a/location.h b/location.h index 10b5f29..cdbe935 100644 --- a/location.h +++ b/location.h @@ -1,7 +1,7 @@ #ifndef LOCATION_H #define LOCATION_H -#include "angle.h" +#include "./angle.h" #include #include diff --git a/main.cpp b/main.cpp index f2d8b58..11f96d9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,11 @@ -#include "main.h" -#include "location.h" -#include "utils.h" +#include "./main.h" +#include "./location.h" +#include "./utils.h" + +// include configuration from separate header file when building with CMake +#ifndef APP_METADATA_AVAIL +#include "config.h" +#endif #include #include @@ -21,6 +26,8 @@ SystemForLocations outputSystemForLocations = SystemForLocations::LatitudeLongit int main(int argc, char *argv[]) { try { + SET_APPLICATION_INFO; + ArgumentParser argparser; Argument convert("convert", "c", "Converts the given coordinate or location to the specified output form."); @@ -144,7 +151,7 @@ int main(int argc, char *argv[]) cout << endl; printAngleFormatInfo(cout); } else if(version.isPresent()) { - cout << "1.0.0"; + cout << APP_VERSION; } else if(convert.isPresent()) { printConversion(convert.value(0)); } else if(distance.isPresent()) { diff --git a/main.h b/main.h index c1a4d75..b957b47 100644 --- a/main.h +++ b/main.h @@ -1,8 +1,8 @@ #ifndef MAIN_H_INCLUDED #define MAIN_H_INCLUDED -#include "angle.h" -#include "location.h" +#include "./angle.h" +#include "./location.h" #include #include diff --git a/utils.cpp b/utils.cpp index 9bfbc42..1323be0 100644 --- a/utils.cpp +++ b/utils.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "./utils.h" namespace Utils {