Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
2021-04-20 19:38:46 +00:00
|
|
|
if(NOT REV_MAJOR)
|
|
|
|
set(REV_MAJOR 0)
|
|
|
|
endif()
|
|
|
|
if(NOT REV_MINOR)
|
|
|
|
set(REV_MINOR 0)
|
|
|
|
endif()
|
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
#
|
|
|
|
# Finds the current version of the current folder.
|
|
|
|
#
|
|
|
|
|
|
|
|
find_package(Git QUIET)
|
|
|
|
# ${CMAKE_SOURCE_DIR}/.git may be a directory or a regular file
|
2020-09-25 11:55:25 +00:00
|
|
|
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# Make sure LC_ALL is set to something desirable
|
|
|
|
set(SAVED_LC_ALL "$ENV{LC_ALL}")
|
|
|
|
set(ENV{LC_ALL} C)
|
|
|
|
|
|
|
|
# Assume the dir is not modified
|
|
|
|
set(REV_MODIFIED 0)
|
|
|
|
|
|
|
|
# Refresh the index to make sure file stat info is in sync, then look for modifications
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} update-index --refresh
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
OUTPUT_QUIET
|
|
|
|
)
|
|
|
|
|
|
|
|
# See if git tree is modified
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} diff-index HEAD
|
|
|
|
OUTPUT_VARIABLE IS_MODIFIED
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT IS_MODIFIED STREQUAL "")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(REV_MODIFIED 2)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Get last commit hash
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD
|
|
|
|
OUTPUT_VARIABLE FULLHASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
set(REV_HASH "${FULLHASH}")
|
|
|
|
|
|
|
|
string(SUBSTRING "${FULLHASH}" 0 10 SHORTHASH)
|
|
|
|
|
|
|
|
# Get the last commit date
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} show -s --pretty=format:%ci HEAD
|
|
|
|
OUTPUT_VARIABLE COMMITDATE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
string(REGEX REPLACE "([0-9]+)-([0-9]+)-([0-9]+).*" "\\1\\2\\3" COMMITDATE "${COMMITDATE}")
|
|
|
|
set(REV_ISODATE "${COMMITDATE}")
|
2020-06-05 19:43:22 +00:00
|
|
|
string(SUBSTRING "${REV_ISODATE}" 0 4 REV_YEAR)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
# Get the branch
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref -q HEAD
|
|
|
|
OUTPUT_VARIABLE BRANCH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
string(REGEX REPLACE ".*/" "" BRANCH "${BRANCH}")
|
|
|
|
|
|
|
|
# Get the tag
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} name-rev --name-only --tags --no-undefined HEAD
|
|
|
|
OUTPUT_VARIABLE TAG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
string(REGEX REPLACE "\^0$" "" TAG "${TAG}")
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(REV_MODIFIED EQUAL 0)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(HASHPREFIX "-g")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif(REV_MODIFIED EQUAL 2)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(HASHPREFIX "-m")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(HASHPREFIX "-u")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set the version string
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT TAG STREQUAL "")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(REV_VERSION "${TAG}")
|
|
|
|
set(REV_ISTAG 1)
|
|
|
|
|
2020-06-05 01:42:31 +00:00
|
|
|
string(REGEX REPLACE "^[0-9.]+$" "" STABLETAG "${TAG}")
|
2021-04-01 11:04:34 +00:00
|
|
|
if(STABLETAG STREQUAL "")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(REV_ISSTABLETAG 1)
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(REV_ISSTABLETAG 0)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
else()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
set(REV_VERSION "${REV_ISODATE}-${BRANCH}${HASHPREFIX}${SHORTHASH}")
|
|
|
|
set(REV_ISTAG 0)
|
|
|
|
set(REV_ISSTABLETAG 0)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
# Restore LC_ALL
|
|
|
|
set(ENV{LC_ALL} "${SAVED_LC_ALL}")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif(EXISTS "${CMAKE_SOURCE_DIR}/.ottdrev")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
file(READ "${CMAKE_SOURCE_DIR}/.ottdrev" OTTDREV)
|
2020-06-05 19:43:22 +00:00
|
|
|
string(REPLACE "\n" "" OTTDREV "${OTTDREV}")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
string(REPLACE "\t" ";" OTTDREV "${OTTDREV}")
|
|
|
|
list(GET OTTDREV 0 REV_VERSION)
|
|
|
|
list(GET OTTDREV 1 REV_ISODATE)
|
|
|
|
list(GET OTTDREV 2 REV_MODIFIED)
|
|
|
|
list(GET OTTDREV 3 REV_HASH)
|
|
|
|
list(GET OTTDREV 4 REV_ISTAG)
|
|
|
|
list(GET OTTDREV 5 REV_ISSTABLETAG)
|
|
|
|
list(GET OTTDREV 6 REV_YEAR)
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
message(WARNING "No version detected; this build will NOT be network compatible")
|
|
|
|
set(REV_VERSION "norev0000")
|
|
|
|
set(REV_ISODATE "19700101")
|
|
|
|
set(REV_MODIFIED 1)
|
|
|
|
set(REV_HASH "unknown")
|
|
|
|
set(REV_ISTAG 0)
|
|
|
|
set(REV_ISSTABLETAG 0)
|
|
|
|
set(REV_YEAR "1970")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
message(STATUS "Version string: ${REV_VERSION}")
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(GENERATE_OTTDREV)
|
2019-04-07 10:01:32 +00:00
|
|
|
message(STATUS "Generating .ottdrev")
|
|
|
|
file(WRITE ${CMAKE_SOURCE_DIR}/.ottdrev "${REV_VERSION}\t${REV_ISODATE}\t${REV_MODIFIED}\t${REV_HASH}\t${REV_ISTAG}\t${REV_ISSTABLETAG}\t${REV_YEAR}\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-04-07 10:01:32 +00:00
|
|
|
message(STATUS "Generating rev.cpp")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/src/rev.cpp.in"
|
|
|
|
"${FIND_VERSION_BINARY_DIR}/rev.cpp")
|
|
|
|
|
2021-06-10 20:14:08 +00:00
|
|
|
if(WINDOWS)
|
2019-04-07 10:01:32 +00:00
|
|
|
message(STATUS "Generating ottdres.rc")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/src/os/windows/ottdres.rc.in"
|
|
|
|
"${FIND_VERSION_BINARY_DIR}/ottdres.rc")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 10:01:32 +00:00
|
|
|
|
|
|
|
message(STATUS "Generating CPackProperties.cmake")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/CPackProperties.cmake.in"
|
|
|
|
"${CPACK_BINARY_DIR}/CPackProperties.cmake" @ONLY)
|
2020-12-10 22:57:27 +00:00
|
|
|
|
|
|
|
message(STATUS "Generating Doxyfile")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/Doxyfile.in"
|
|
|
|
"${CPACK_BINARY_DIR}/Doxyfile")
|
|
|
|
|
|
|
|
message(STATUS "Generating Doxyfile_AI")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/src/script/api/Doxyfile_AI.in"
|
|
|
|
"${CPACK_BINARY_DIR}/Doxyfile_AI")
|
|
|
|
|
|
|
|
message(STATUS "Generating Doxyfile_GS")
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/src/script/api/Doxyfile_GS.in"
|
|
|
|
"${CPACK_BINARY_DIR}/Doxyfile_GS")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|