From 5cdd1808ade8da251d3dc14e11a0344afad92181 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Wed, 27 Jan 2021 00:21:06 +0800 Subject: [PATCH] Define version number and project name with cmake --- .gitignore | 2 ++ CMakeLists.txt | 3 ++- src/args.cpp | 3 ++- src/config.hpp.in | 8 ++++++++ src/graphics.cpp | 3 ++- src/main.cpp | 2 +- 6 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/config.hpp.in diff --git a/.gitignore b/.gitignore index 9e56bd7..4474fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ fc2d build/ + +src/config.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2babe84..97b373a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required( VERSION 3.0 ) -project( FaceCam2D VERSION 0.1.0 ) +project( Facecam2D VERSION 0.1.0 ) find_package( OpenCV REQUIRED ) message (STATUS "Found OpenCV at: " ${OpenCV_INCLUDE_DIRS} ) find_package( OpenGL REQUIRED ) @@ -16,6 +16,7 @@ include_directories( ${GLEW_INCLUDE_DIRS} ) include_directories( ${GLM_INCLUDE_DIRS} ) include_directories( ${GLUT_INCLUDE_DIR} ) include_directories( ${PROJECT_SOURCE_DIR}/src ) +configure_file( ${PROJECT_SOURCE_DIR}/src/config.hpp.in ${PROJECT_SOURCE_DIR}/src/config.hpp @ONLY ) file( COPY ${PROJECT_SOURCE_DIR}/models diff --git a/src/args.cpp b/src/args.cpp index 2773f80..b6cddb8 100644 --- a/src/args.cpp +++ b/src/args.cpp @@ -1,7 +1,8 @@ #include +#include const char* argp_program_version = - "Facecam2D 0.1.0\n" + PROJECT_NAME " " VERSION_CODE "\n" "License: GPLv3 \n" "If you did not receive a copy of the source code, it is\n" "available at ."; diff --git a/src/config.hpp.in b/src/config.hpp.in new file mode 100644 index 0000000..8aea302 --- /dev/null +++ b/src/config.hpp.in @@ -0,0 +1,8 @@ +#ifndef CONFIG_HPP +#define CONFIG_HPP + +#define PROJECT_NAME "@PROJECT_NAME@" + +#define VERSION_CODE "@PROJECT_VERSION@" + +#endif diff --git a/src/graphics.cpp b/src/graphics.cpp index 722be8d..c72bdb5 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -13,6 +13,7 @@ #include #include #include +#include GLuint shader; //standard shader program used for all elements GLuint transUniform; //location of the "transMatrix" transformation matrix uniform in the shader @@ -73,7 +74,7 @@ void initGraphics () { char *argv[1] = {(char*)"fc2d"}; glutInit(&argc, argv); - glutCreateWindow("FaceCam2D"); + glutCreateWindow(PROJECT_NAME); glutInitWindowSize(512, 512); glewExperimental = GL_TRUE; diff --git a/src/main.cpp b/src/main.cpp index e3c7376..64c4010 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,7 @@ int main (int argc, char** argv) { argp_parse(&argp, argc, argv, 0, 0, 0); - std::cout << "Facecam2D is starting..." << std::endl; + std::cout << PROJECT_NAME " is starting..." << std::endl; initPrefixes(); std::cout << "Custom asset prefix: " << prefixCustom << std::endl;