1# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; version 2 of the License. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program; if not, write to the Free Software 14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA 15 16 17# Handle/create the "INFO_*" files describing a MariaDB (server) binary. 18# This is part of the fix for bug#42969. 19 20 21# Several of cmake's variables need to be translated from '@' notation 22# to '${}', this is done by the "configure" call in top level "CMakeLists.txt". 23# If further variables are used in this file, add them to this list. 24 25SET(VERSION "@VERSION@") 26SET(MAJOR_VERSION "@MAJOR_VERSION@") 27SET(MINOR_VERSION "@MINOR_VERSION@") 28SET(PATCH_VERSION "@PATCH_VERSION@") 29SET(CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@") 30SET(CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@") 31SET(CMAKE_GENERATOR "@CMAKE_GENERATOR@") 32SET(CMAKE_SIZEOF_VOID_P "@CMAKE_SIZEOF_VOID_P@") 33SET(GIT_EXECUTABLE "@GIT_EXECUTABLE@") 34SET(CMAKE_CROSSCOMPILING "@CMAKE_CROSSCOMPILING@") 35SET(CMAKE_HOST_SYSTEM "@CMAKE_HOST_SYSTEM@") 36SET(CMAKE_HOST_SYSTEM_PROCESSOR "@CMAKE_HOST_SYSTEM_PROCESSOR@") 37SET(CMAKE_SYSTEM "@CMAKE_SYSTEM@") 38SET(CMAKE_SYSTEM_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@") 39 40 41# Create an "INFO_SRC" file with information about the source (only). 42# We use "git log", if possible, and the "VERSION" contents. 43# 44# Outside development (git tree), the "INFO_SRC" file will not be modified 45# provided it exists (from "make dist" or a source tarball creation). 46 47MACRO(CREATE_INFO_SRC target_dir) 48 SET(INFO_SRC "${target_dir}/INFO_SRC") 49 50 SET(PERLSCRIPT 51 "use warnings; use POSIX qw(strftime); " 52 "print strftime \"%F %T %z\", localtime;") 53 EXECUTE_PROCESS( 54 COMMAND perl -e "${PERLSCRIPT}" 55 RESULT_VARIABLE result 56 OUTPUT_VARIABLE bdate 57 ERROR_VARIABLE error 58 ) 59 IF(error) 60 MESSAGE(STATUS "Could not determine build-date: <${error}>") 61 ENDIF() 62 63 IF(GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git) 64 # Sources are in a GIT repository: Always update. 65 EXECUTE_PROCESS( 66 COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD 67 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 68 OUTPUT_VARIABLE bname 69 ) 70 71 EXECUTE_PROCESS( 72 COMMAND ${GIT_EXECUTABLE} log -1 73 --pretty="commit: %H%ndate: %ci%nbuild-date: ${bdate} %nshort: %h%nbranch: ${bname}" 74 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 75 OUTPUT_VARIABLE VERSION_INFO 76 ) 77 78 ## Output from git is quoted with "", remove them. 79 STRING(REPLACE "\"" "" VERSION_INFO "${VERSION_INFO}") 80 FILE(WRITE ${INFO_SRC} "${VERSION_INFO}\n") 81 # to debug, add: FILE(APPEND ${INFO_SRC} "\nResult ${RESULT}\n") 82 # For better readability ... 83 FILE(APPEND ${INFO_SRC} 84 "MariaDB source ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}\n") 85 ELSEIF(EXISTS ${INFO_SRC}) 86 # Outside a git tree, there is no need to change an existing "INFO_SRC", 87 # it cannot be improved. 88 ELSEIF(EXISTS ${CMAKE_SOURCE_DIR}/Docs/INFO_SRC) 89 # If we are building from a source distribution, it also contains "INFO_SRC". 90 # Similar, the export used for a release build already has the file. 91 FILE(READ ${CMAKE_SOURCE_DIR}/Docs/INFO_SRC SOURCE_INFO) 92 FILE(WRITE ${INFO_SRC} "${SOURCE_INFO}\n") 93 ELSEIF(EXISTS ${CMAKE_SOURCE_DIR}/INFO_SRC) 94 # This is not the proper location, but who knows ... 95 FILE(READ ${CMAKE_SOURCE_DIR}/INFO_SRC SOURCE_INFO) 96 FILE(WRITE ${INFO_SRC} "${SOURCE_INFO}\n") 97 ELSE() 98 # This is a fall-back. 99 FILE(WRITE ${INFO_SRC} "\nMariaDB source ${VERSION}\n") 100 ENDIF() 101ENDMACRO(CREATE_INFO_SRC) 102 103 104# This is for the "real" build, must be run again with each cmake run 105# to make sure we report the current flags (not those of some previous run). 106 107MACRO(CREATE_INFO_BIN) 108 SET(INFO_BIN "Docs/INFO_BIN") 109 110 FILE(WRITE ${INFO_BIN} "===== Information about the build process: =====\n") 111 IF (WIN32) 112 EXECUTE_PROCESS(COMMAND cmd /c date /T 113 OUTPUT_VARIABLE TMP_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) 114 ELSEIF(UNIX) 115 EXECUTE_PROCESS(COMMAND date "+%Y-%m-%d %H:%M:%S" 116 OUTPUT_VARIABLE TMP_DATE OUTPUT_STRIP_TRAILING_WHITESPACE) 117 ELSE() 118 SET(TMP_DATE "(no date command known for this platform)") 119 ENDIF() 120 SITE_NAME(HOSTNAME) 121 FILE(APPEND ${INFO_BIN} "Build was run at ${TMP_DATE} on host '${HOSTNAME}'\n\n") 122 123 # According to the cmake docs, these variables should always be set. 124 # However, they are empty in my tests, using cmake 2.6.4 on Linux, various Unix, and Windows. 125 # Still, include this code, so we will profit if a build environment does provide that info. 126 IF(CMAKE_HOST_SYSTEM) 127 FILE(APPEND ${INFO_BIN} "Build was done on ${CMAKE_HOST_SYSTEM} using ${CMAKE_HOST_SYSTEM_PROCESSOR}\n") 128 ENDIF() 129 IF(CMAKE_CROSSCOMPILING) 130 FILE(APPEND ${INFO_BIN} "Build was done for ${CMAKE_SYSTEM} using ${CMAKE_SYSTEM_PROCESSOR}\n") 131 ENDIF() 132 133 # ${CMAKE_VERSION} doesn't work in 2.6.0, use the separate components. 134 FILE(APPEND ${INFO_BIN} "Build was done using cmake ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} \n\n") 135 136 IF (WIN32) 137 FILE(APPEND ${INFO_BIN} "===== Compiler / generator used: =====\n") 138 FILE(APPEND ${INFO_BIN} ${CMAKE_GENERATOR} "\n\n") 139 ELSEIF(UNIX) 140 FILE(APPEND ${INFO_BIN} "===== Compiler flags used (from the 'sql/' subdirectory): =====\n") 141 IF(EXISTS sql/CMakeFiles/sql.dir/flags.make) 142 EXECUTE_PROCESS(COMMAND egrep "^# compile|^C_|^CXX_" sql/CMakeFiles/sql.dir/flags.make OUTPUT_VARIABLE COMPILE_FLAGS) 143 FILE(APPEND ${INFO_BIN} ${COMPILE_FLAGS} "\n") 144 ELSE() 145 FILE(APPEND ${INFO_BIN} "File 'sql/CMakeFiles/sql.dir/flags.make' is not yet found.\n\n") 146 ENDIF() 147 ENDIF() 148 FILE(APPEND ${INFO_BIN} "Pointer size: ${CMAKE_SIZEOF_VOID_P}\n\n") 149 150 FILE(APPEND ${INFO_BIN} "===== Feature flags used: =====\n") 151 IF(EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt) 152 # Attention: "-N" prevents cmake from entering a recursion, and it must be a separate flag from "-L". 153 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -N -L ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE FEATURE_FLAGS) 154 FILE(APPEND ${INFO_BIN} ${FEATURE_FLAGS} "\n") 155 ELSE() 156 FILE(APPEND ${INFO_BIN} "File 'CMakeCache.txt' is not yet found.\n\n") 157 ENDIF() 158 159 FILE(APPEND ${INFO_BIN} "===== EOF =====\n") 160ENDMACRO(CREATE_INFO_BIN) 161 162