cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

cmake_policy(VERSION 2.6)

# . Project Name

project(svp-env NONE)

# . Project Build

string(TOUPPER $ENV{SVP_PLATFORM} SVP_PLATFORM)

string(TOUPPER $ENV{SVP_BASELINE} SVP_BASELINE)

set(SVP_UPSTREAM_VERSION "18.08")

set(SVP_VERSION "")

string(TIMESTAMP SVP_BUILD_DATE "%Y-%m-%d %H:%M:%S")

set(SVP_TIMEZONE "+0800")
MESSAGE("-----------------${SVP_BUILD_DATE}")
configure_file(conf/svp.version.sh.in svp.version.sh @ONLY) # . Project Install install(DIRECTORY conf/ DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
FILES_MATCHING PATTERN svp.*.sh PATTERN *.ini PATTERN *.conf PATTERN *.json) install(FILES conf/$ENV{SVP_PLATFORM}.svp.env.dev.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.env.dev.sh) install(FILES conf/$ENV{SVP_PLATFORM}.svp.env.uit.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.env.uit.sh) install(FILES conf/$ENV{SVP_PLATFORM}.svp.env.extra.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.env.extra.sh) install(FILES conf/$ENV{SVP_PLATFORM}.svp.init.cgroup.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.init.cgroup.sh) install(FILES conf/$ENV{SVP_PLATFORM}.svp.startup.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.startup.sh) install(FILES conf/$ENV{SVP_PLATFORM}.svp.update.sh
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
RENAME svp.update.sh) install(FILES ${CMAKE_BINARY_DIR}/svp.version.sh DESTINATION ${CMAKE_INSTALL_SYSCONFDIR})

cmakelist 定义字符串,替换到脚本中。-LMLPHP

svp.version.sh.in

export SVP_VERSION="@SVP_PLATFORM@_SVP@SVP_BASELINE@_@SVP_UPSTREAM_VERSION@.@SVP_VERSION@"

export SVP_BUILD_DATE="@SVP_BUILD_DATE@@SVP_TIMEZONE@"

使用了configure_file 把cmakelist里面的变量,用它的值代替。

cmakelist 定义字符串,替换到脚本中。-LMLPHP

configure_file 的作用是让普通文件也能使用CMake中的变量。
也就是说代码文件中可以使用CMake中的变量。
语法如下:
configure_file(<input> <output>
[COPYONLY] [ESCAPE_QUOTES] [@ONLY]
[NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
Copies an <input> file to an <output> file and substitutes variable values referenced as @VAR@ or ${VAR} in the input file content.
Each variable reference will be replaced with the current value of the variable, or the empty string if the variable is not defined.
Furthermore, input lines of the form: 拷贝一个 <input>(输入文件) 文件到 <output> (输出文件),并且替换输入文件中被 @VAR@ 或者 ${VAR} 引用的变量值。每一个变量将被替换成当前的变量值(注:CMake中的变量值)或者空串当变量未定义。
05-13 18:31