Skip to content

Instantly share code, notes, and snippets.

@AlecTaylor
Created September 14, 2018 14:47
Show Gist options
  • Save AlecTaylor/2df914df77f2315c3868bcc7de1ef2a6 to your computer and use it in GitHub Desktop.
Save AlecTaylor/2df914df77f2315c3868bcc7de1ef2a6 to your computer and use it in GitHub Desktop.
Handling version with CMake
cmake_minimum_required(VERSION 3.12)
project(c VERSION 0.0.1)
set(CMAKE_C_STANDARD 11)
configure_file(lib/version.h.in version.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-Wno-implicit-function-declaration)
add_executable(foo foo.c)
#ifndef VERSION_H
#define VERSION_H
#cmakedefine PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#ifndef PROJECT_VERSION_MAJOR
#define PROJECT_VERSION_MAJOR 0
#endif
#cmakedefine PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#ifndef PROJECT_VERSION_MINOR
#define PROJECT_VERSION_MINOR 0
#endif
#cmakedefine PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#ifndef PROJECT_VERSION_PATCH
#define PROJECT_VERSION_PATCH 0
#endif
#endif //VERSION_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment