Skip to content

Commit

Permalink
cmake: add version information
Browse files Browse the repository at this point in the history
Additionally made PKG_CONFIG the default library discover method on
non-MSVC builds.

Signed-off-by: Mahyar Koshkouei <[email protected]>
  • Loading branch information
deltabeard committed Apr 9, 2022
1 parent 6db35ef commit c22bfd4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
18 changes: 14 additions & 4 deletions examples/sdl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vim: ts=4:sw=4:expandtab
CMAKE_MINIMUM_REQUIRED(VERSION 3.19)
CMAKE_MINIMUM_REQUIRED(VERSION 3.18...3.23)

## Check user set options.
IF(NOT CMAKE_BUILD_TYPE)
Expand All @@ -14,9 +14,14 @@ ELSE()
ENDIF()
ENDIF()

# Obtain version
INCLUDE(../../version.all)

# Initialise project information.
PROJECT(peanut-sdl
LANGUAGES C
VERSION
${HAIYAJAN_VERSION_MAJOR}.${HAIYAJAN_VERSION_MINOR}.${HAIYAJAN_VERSION_PATCH}
DESCRIPTION "Peanut-GB example with SDL2"
HOMEPAGE_URL "https://github.com/deltabeard/peanut-gb")

Expand All @@ -37,7 +42,12 @@ TARGET_SOURCES(${PROJECT_NAME} PRIVATE peanut_sdl.c
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE ../../)

# Discover libraries
SET(LIBRARY_DISCOVER_METHOD "CPM" CACHE STRING
IF(MSVC)
SET(DEFAULT_LIBRARY_DISCOVER_METHOD "CPM")
ELSE()
SET(DEFAULT_LIBRARY_DISCOVER_METHOD "PKG_CONFIG")
ENDIF()
SET(LIBRARY_DISCOVER_METHOD DEFAULT_LIBRARY_DISCOVER_METHOD CACHE STRING
"Tool to use for discovering dependencies; options are: PKG_CONFIG, CPM")

IF(${LIBRARY_DISCOVER_METHOD} STREQUAL "PKG_CONFIG")
Expand All @@ -47,7 +57,7 @@ ELSEIF(${LIBRARY_DISCOVER_METHOD} STREQUAL "CPM")
INCLUDE(CPM.cmake)
CPMADDPACKAGE(GITHUB_REPOSITORY libsdl-org/SDL
NAME SDL2
GIT_TAG release-2.0.18
GIT_TAG release-2.0.20
OPTIONS
"SDL_SHARED_ENABLED_BY_DEFAULT OFF"
"SDL_STATIC_ENABLED_BY_DEFAULT ON")
Expand Down Expand Up @@ -91,7 +101,7 @@ SET(CPACK_PACKAGE_ICON meta/icon.ico)
SET(CPACK_PACKAGE_EXECUTABLES peanut-sdl;Peanut-SDL)
INCLUDE(CPack)

MESSAGE(STATUS "Peanut-SDL will build with the following options:")
MESSAGE(STATUS "Peanut-SDL ${peanut-sdl_VERSION} will build with the following options:")
MESSAGE(STATUS " CC: ${CMAKE_C_COMPILER} '${CMAKE_C_COMPILER_ID}' on '${CMAKE_SYSTEM_NAME}'")
MESSAGE(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
MESSAGE(STATUS " LDFLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
3 changes: 2 additions & 1 deletion peanut_gb.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* MIT License
*
* Copyright (c) 2018 Mahyar Koshkouei
* Copyright (c) 2018-2022 Mahyar Koshkouei
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -31,6 +31,7 @@

#pragma once

#include "version.all"
#include <stdint.h> /* Required for int types */
#include <time.h> /* Required for tm struct */

Expand Down
9 changes: 9 additions & 0 deletions version.all
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#if 0
SET(HAIYAJAN_VERSION_MAJOR 1)
SET(HAIYAJAN_VERSION_MINOR 0)
SET(HAIYAJAN_VERSION_PATCH 0)
#endif

#define HAIYAJAN_VERSION_MAJOR 1
#define HAIYAJAN_VERSION_MINOR 0
#define HAIYAJAN_VERSION_PATCH 0

0 comments on commit c22bfd4

Please sign in to comment.