Compare to manual Project version if not from git
[apps/app-templates.git] / cmake / cmake.d / 03-macros.cmake
index 3602aa8..2de89f3 100644 (file)
 #     Customise your preferences in "./conf.d/cmake/config.cmake"
 #--------------------------------------------------------------------------
 # CMake 3.6 imported macros to simulate list(FILTER ...) subcommand
-# -----------------------
+#--------------------------------------------------------------------------
+MACRO(prevent_in_source_build)
+       execute_process(COMMAND rm -rf ${CMAKE_SOURCE_DIR}/CMakeCache.txt ${CMAKE_SOURCE_DIR}/CMakeCacheForScript.cmake ${CMAKE_SOURCE_DIR}/CMakeFiles ${CMAKE_SOURCE_DIR}/cmake_install.cmake)
+
+       get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
+       get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
+
+       if(${srcdir} STREQUAL ${bindir})
+               message(FATAL_ERROR "${Red}**** ERROR: You trying to build the project from the source directory or a previous build in-source occured. This isn't allowed, you have to clean CMakeCache.txt file from your source directory (${srcdir}), and build from a separate directory. ****\n")
+       endif()
+ENDMACRO(prevent_in_source_build)
+
 MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
-SET(DEFAULT_ARGS)
-FOREACH(arg_name ${arg_names})
-  SET(${prefix}_${arg_name})
-ENDFOREACH(arg_name)
-FOREACH(option ${option_names})
-  SET(${prefix}_${option} FALSE)
-ENDFOREACH(option)
-
-SET(current_arg_name DEFAULT_ARGS)
-SET(current_arg_list)
-FOREACH(arg ${ARGN})
-  LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
-  IF (is_arg_name)
-       SET(${prefix}_${current_arg_name} ${current_arg_list})
-       SET(current_arg_name ${arg})
+       SET(DEFAULT_ARGS)
+       FOREACH(arg_name ${arg_names})
+       SET(${prefix}_${arg_name})
+       ENDFOREACH(arg_name)
+       FOREACH(option ${option_names})
+       SET(${prefix}_${option} FALSE)
+       ENDFOREACH(option)
+
+       SET(current_arg_name DEFAULT_ARGS)
        SET(current_arg_list)
-  ELSE (is_arg_name)
-       LIST_CONTAINS(is_option ${arg} ${option_names})
-       IF (is_option)
-  SET(${prefix}_${arg} TRUE)
-       ELSE (is_option)
-  SET(current_arg_list ${current_arg_list} ${arg})
-       ENDIF (is_option)
-  ENDIF (is_arg_name)
-ENDFOREACH(arg)
-SET(${prefix}_${current_arg_name} ${current_arg_list})
+       FOREACH(arg ${ARGN})
+       LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
+       IF (is_arg_name)
+               SET(${prefix}_${current_arg_name} ${current_arg_list})
+               SET(current_arg_name ${arg})
+               SET(current_arg_list)
+       ELSE (is_arg_name)
+               LIST_CONTAINS(is_option ${arg} ${option_names})
+               IF (is_option)
+       SET(${prefix}_${arg} TRUE)
+               ELSE (is_option)
+       SET(current_arg_list ${current_arg_list} ${arg})
+               ENDIF (is_option)
+       ENDIF (is_arg_name)
+       ENDFOREACH(arg)
+       SET(${prefix}_${current_arg_name} ${current_arg_list})
 ENDMACRO(PARSE_ARGUMENTS)
 
 MACRO(LIST_CONTAINS var value)
@@ -258,11 +269,6 @@ endmacro()
 # Pre-packaging
 macro(project_targets_populate)
        # Default Widget default directory
-       set(BINDIR bin)
-       set(ETCDIR etc)
-       set(LIBDIR lib)
-       set(HTTPDIR htdocs)
-       set(DATADIR data)
        set(PACKAGE_BINDIR  ${PROJECT_PKG_BUILD_DIR}/${BINDIR})
        set(PACKAGE_ETCDIR  ${PROJECT_PKG_BUILD_DIR}/${ETCDIR})
        set(PACKAGE_LIBDIR  ${PROJECT_PKG_BUILD_DIR}/${LIBDIR})
@@ -528,3 +534,23 @@ macro(project_closing_msg)
                        ${PROJECT_TARGETS} populate)
        endif()
 endmacro()
+
+macro(check_version)
+       if(${GIT_PROJECT_VERSION})
+               if(${GIT_PROJECT_VERSION} VERSION_GREATER ${APP_TEMPLATES_VERSION})
+                       message(STATUS "${Yellow}.. Your app-templates submodule version seems outdated. You should update it with 'git submodule update --remote ${PROJECT_APP_TEMPLATES_DIR}'.
+               - App-templates version: ${APP_TEMPLATES_VERSION}
+               - Project version according AGL Git tag: ${GIT_PROJECT_VERSION}"
+               )
+               endif()
+       elseif(${PROJECT_VERSION})
+               if(${PROJECT_VERSION} VERSION_GREATER ${APP_TEMPLATES_VERSION})
+                       message(STATUS "${Yellow}.. Your app-templates submodule version seems outdated. You should update it with 'git submodule update --remote ${PROJECT_APP_TEMPLATES_DIR}'.
+               - App-templates version: ${APP_TEMPLATES_VERSION}
+               - Project version according AGL Git tag: ${PROJECT_VERSION}"
+               )
+               endif()
+       else()
+               message(STATUS "${Yellow} Your git project repo doesn't have any version tags nor hosted by AGL gerrit infrastructure. Can't compare version between project and app-templates ${APP_TEMPLATES_VERSION} ${ColourReset}")
+       endif()
+endmacro()