CMakeLists.txt 2.88 KB
# -*- mode:cmake -*-
# Project to make a simple OSDEV versioned binary
cmake_minimum_required(VERSION 3.0)
project(osdevversion)

# get the directory containing this cmake script.
set( OSDEV_CURRENT_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR} )

# find python
find_package(PythonInterp REQUIRED)
if(NOT PYTHONINTERP_FOUND)
    message(FATAL_ERROR "-- Python interpreter not found.")
endif()

# build option to test OSDEV Version generation
option(OPTION_BUILD_TESTS "Build Caelus Version tests ." OFF)

# check environment for locations of configurations if not default.
if(NOT OSDEV_PRODUCT_SRC_DIR)
  message(FATAL_ERROR "-- ${OSDEV_PRODUCT_SRC_DIR} is not specified.")
endif()

# set OSDEV_CURRENT_CMAKE_DIR to point to product configuration folder
set(OSDEV_CONFIG_DIR ${OSDEV_CURRENT_CMAKE_DIR}/osdev_config/)

# Check HSOA Version DIR not overridden by existing environment path
if(EXISTS $ENV{OSDEV_CONFIG_DIR})
  set(OSDEV_CONFIG_DIR $ENV{OSDEV_CONFIG_DIR})
endif()

if(EXISTS ${OSDEV_CONFIG_DIR})
  message(STATUS "++ OSDEV_CONFIG_DIR=${OSDEV_CONFIG_DIR}")
else()
  message(FATAL_ERROR "-- ${OSDEV_CONFIG_DIR} does not exist")
endif()

# check for product configuration in environment, otherwise set to default
if(ENV{OSDEV_VERSION_PRODUCT_CONFIG})
  set(OSDEV_VERSION_PRODUCT_CONFIG $ENV{OSDEV_VERSION_PRODUCT_CONFIG})
elseif(OSDEV_VERSION_PRODUCT_CONFIG)
  set(ENV{OSDEV_VERSION_PRODUCT_CONFIG} ${OSDEV_VERSION_PRODUCT_CONFIG})
else()
  set(ENV{OSDEV_VERSION_PRODUCT_CONFIG} ${OSDEV_CONFIG_DIR}/product_config.txt)
  set(OSDEV_VERSION_PRODUCT_CONFIG $ENV{OSDEV_VERSION_PRODUCT_CONFIG})
endif()

# check product configuration file exists.
if(EXISTS ${OSDEV_VERSION_PRODUCT_CONFIG})
  message(STATUS "++ OSDEV_VERSION_PRODUCT_CONFIG=${OSDEV_VERSION_PRODUCT_CONFIG}")
else()
  message(FATAL_ERROR "-- ${OSDEV_VERSION_PRODUCT_CONFIG} does not exist")
endif()

# set default target paths for header file
set(OSDEV_VERSION_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/osdev_version/)
set(OSDEV_VERSION_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/osdev_version/)
set(OSDEV_VERSION_GENSCRIPT ${OSDEV_CURRENT_CMAKE_DIR}/osdev_create_version_include.sh)

if(NOT EXISTS ${OSDEV_VERSION_HEADER_FILE})
  message(STATUS "Creating dir ${OSDEV_VERSION_HEADER_DIR}")
  FILE(MAKE_DIRECTORY ${OSDEV_VERSION_HEADER_DIR})
  EXECUTE_PROCESS(
    COMMAND ${VERSION_GENSCRIPT} ${OSDEV_VERSION_CUSTOMER} ${OSDEV_VERSION_HEADER_DIR}
    WORKING_DIRECORY ${OSDEV_PRODUCT_SRC_DIR}
    COMMENT "First run of version header generator")
endif()

execute_process(
   COMMAND ${OSDEV_VERSION_GENSCRIPT} ${OSDEV_PRODUCT_SRC_DIR} ${OSDEV_VERSION_HEADER_DIR}
   WORKING_DIRECORY ${OSDEV_PRODUCT_SRC_DIR}
)

include( ${OSDEV_VERSION_HEADER_DIR}/osdev_version.cmake )

set(OSDEV_VERSION_INCLUDE_DIR ${OSDEV_VERSION_HEADER_DIR} CACHE STRING "osdev version include dir" FORCE)
set(OSDEV_VERSION_SRC_FILE ${OSDEV_VERSION_HEADER_DIR}/osdev_version.cpp CACHE STRING "osdev version src file" FORCE)