Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
cmake: Simplify version handling and setting, add patch version
Browse files Browse the repository at this point in the history
  • Loading branch information
wltjr committed Jan 25, 2018
1 parent 126db27 commit e2df358
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
25 changes: 8 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@

cmake_minimum_required (VERSION 2.6)
project (jem)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_PATCH 0)
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

file(STRINGS "${PROJECT_SOURCE_DIR}/include/version.h"
JEM_BUILD_SPEC REGEX "^[ \t]*#define[ \t]+JEM_VERSION_[A-Z]+[ \t]+[0-9]+.*$")

if(JEM_BUILD_SPEC)
message(STATUS "${JEM_BUILD_SPEC}")
foreach(item IN ITEMS MAJOR MINOR PATCH)
string(REGEX REPLACE ".*#define[ \t]+JEM_VERSION_${item}[ \t]+([0-9]+).*"
"\\1" XYZ ${JEM_BUILD_SPEC})
set("JEM_VERSION_${item}" ${XYZ} CACHE STRING "Jem version")
endforeach()
else()
message(FATAL_ERROR "Version unavilable")
endif()

set(VERSION "${JEM_VERSION_MAJOR}.${JEM_VERSION_MINOR}")
configure_file ("${PROJECT_SOURCE_DIR}/include/version.h.in"
"${PROJECT_SOURCE_DIR}/include/version.h" )

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
Expand All @@ -48,8 +39,8 @@ add_library(jem SHARED src/output_formatter.c src/file_parser.c src/vm.c src/pac
add_executable(jem-cli src/main.c)
add_executable(jem-test EXCLUDE_FROM_ALL tests/test.c)
set_target_properties(jem PROPERTIES
SOVERSION ${JEM_VERSION_MAJOR}
VERSION ${JEM_VERSION_MAJOR}.${JEM_VERSION_MINOR})
SOVERSION ${VERSION_MAJOR}
VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
set_target_properties(jem-cli PROPERTIES OUTPUT_NAME jem)
target_link_libraries(jem-cli jem)
target_link_libraries(jem-test jem)
Expand Down
12 changes: 4 additions & 8 deletions include/version.h → include/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
* along with jem. If not, see <http://www.gnu.org/licenses/>.
*/

#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)

#define JEM_CONTACT "Obsidian-Studios, Inc. <[email protected]>"
#define JEM_VERSION_MAJOR 0
#define JEM_VERSION_MINOR 2
#define JEM_VERSION_SEPARATOR "."
#define JEM_VERSION_NUMERIC STR(JEM_VERSION_MAJOR) "." STR(JEM_VERSION_MINOR)
#define JEM_VERSION_STR "jem, v" JEM_VERSION_NUMERIC
#define JEM_VERSION_MAJOR @VERSION_MAJOR@
#define JEM_VERSION_MINOR @VERSION_MINOR@
#define JEM_VERSION_PATCH @VERSION_PATCH@
#define JEM_VERSION_STR "jem, v@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"

0 comments on commit e2df358

Please sign in to comment.