1# 2# Rules for generated source files 3# 4 5 6# Hand-build deftwmrc.c 7set(defc ${CMAKE_CURRENT_BINARY_DIR}/deftwmrc.c) 8set(mkdefc ${TOOLS}/mk_deftwmrc.sh) 9add_custom_command(OUTPUT ${defc} 10 DEPENDS system.ctwmrc ${mkdefc} 11 COMMAND ${mkdefc} ${CMAKE_CURRENT_SOURCE_DIR}/system.ctwmrc > ${defc} 12) 13 14 15# Hand-build ctwm_atoms.[ch] 16set(ctwm_atoms ctwm_atoms.h ctwm_atoms.c) 17add_custom_command(OUTPUT ${ctwm_atoms} 18 DEPENDS ctwm_atoms.in ${TOOLS}/mk_atoms.sh 19 COMMAND ${TOOLS}/mk_atoms.sh ${CMAKE_CURRENT_SOURCE_DIR}/ctwm_atoms.in ctwm_atoms CTWM 20) 21 22 23# Generate up the event names lookup source 24set(en_list ${CMAKE_CURRENT_SOURCE_DIR}/event_names.list) 25set(en_out ${CMAKE_CURRENT_BINARY_DIR}/event_names_table.h) 26set(en_mk ${TOOLS}/mk_event_names.sh) 27add_custom_command(OUTPUT ${en_out} 28 DEPENDS ${en_list} ${en_mk} 29 COMMAND ${en_mk} ${en_list} > ${en_out} 30) 31# Have to manually add this, or cmake won't notice that it's needed in 32# time to make it. 33#set_source_files_properties(event_names.c OBJECT_DEPENDS ${en_out}) 34# This also seems a blessed hackaround, and avoids having to encode the 35# knowledge of what files #include it. 36list(APPEND CTWMSRC ${CMAKE_CURRENT_BINARY_DIR}/event_names_table.h) 37 38 39# Create function bits 40set(fd_list ${CMAKE_CURRENT_SOURCE_DIR}/functions_defs.list) 41set(fd_mk ${TOOLS}/mk_function_bits.sh) 42set(fd_h ${CMAKE_CURRENT_BINARY_DIR}/functions_defs.h) 43set(fdd_h ${CMAKE_CURRENT_BINARY_DIR}/functions_deferral.h) 44set(fpt_h ${CMAKE_CURRENT_BINARY_DIR}/functions_parse_table.h) 45set(fde_h ${CMAKE_CURRENT_BINARY_DIR}/functions_dispatch_execution.h) 46add_custom_command( 47 OUTPUT ${fd_h} ${fdd_h} ${fpt_h} ${fde_h} 48 DEPENDS ${fd_list} ${fd_mk} 49 COMMAND ${fd_mk} ${fd_list} ${CMAKE_CURRENT_BINARY_DIR} 50) 51list(APPEND CTWMSRC ${fd_h} ${fdd_h} ${fpt_h} ${fde_h}) 52 53 54# Setup config header file 55configure_file(ctwm_config.h.in ctwm_config.h ESCAPE_QUOTES) 56 57 58# Fill in version info 59 60# Need the VCS bits; add a guard here to prevent dev screwups when 61# working on the build system. 62if(NOT VCS_CHECKS_RUN) 63 message(FATAL_ERROR "Internal error: VCS checks not done yet!") 64endif() 65 66# Building the version.c file happens in 2 steps. First, an original 67# source file (${version_c_src}) is processed with tools/mk_version_in.sh 68# to write in the ctwm version info found in the VERSION file in the root 69# of the tree. That's written to an intermediate file (${version_c_in}). 70# Secondly, the intermediate file is processed to store up info about the 71# VCS revision being built from, into the final file (${version_c}) which 72# is actually compiled. 73# 74# A special case occurs when there's no VCS info we can find to work 75# with, AND we have a pregen'd .in file (${vresion_c_gen}); this is 76# commonly the case with a release tarball, where part of the release 77# building process pre-stashes the bzr revision info. In that case, we 78# swap the original (${version_c_src}) to point to the pregen'd file 79# (which already has the VCS info), and make the second step just cp the 80# intermediate file over. 81set(version_c_src ${CMAKE_CURRENT_SOURCE_DIR}/version.c.in) 82set(version_c_in ${CMAKE_CURRENT_BINARY_DIR}/version.c.in) 83set(version_c ${CMAKE_CURRENT_BINARY_DIR}/version.c) 84 85# Maybe a pregen'd 86set(version_c_gen ${GENSRCDIR}/version.c.in) 87 88# Override 89if(FORCE_PREGEN_FILES) 90 set(HAS_BZR 0) 91 set(HAS_GIT 0) 92endif() 93 94# Now, what's our process for going from the intermediate .c.in file to 95# the final .c with the VCS revision info added? This is the 2nd step in 96# the process, but we describe it first here so we can change where 97# ${version_c_src} points if necessary. 98if(IS_BZR_CO AND HAS_BZR) 99 # We're in a bzr tree, so write in the bzr revision info 100 set(rw_ver_bzr "${TOOLS}/rewrite_version_bzr.sh") 101 add_custom_command(OUTPUT ${version_c} 102 DEPENDS ${version_c_in} ${BZR_DIRSTATE_FILE} ${rw_ver_bzr} 103 COMMAND env BZR_CMD=${BZR_CMD} ${rw_ver_bzr} < ${version_c_in} > ${version_c} 104 COMMENT "Generating version.c from current WT state." 105 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 106 ) 107elseif(IS_GIT_CO AND HAS_GIT) 108 # We're in a git tree, so write in the git revision info 109 set(rw_ver_git "${TOOLS}/rewrite_version_git.sh") 110 add_custom_command(OUTPUT ${version_c} 111 DEPENDS ${version_c_in} ${GIT_INDEX_FILE} ${rw_ver_git} 112 COMMAND ${rw_ver_git} < ${version_c_in} > ${version_c} 113 COMMENT "Generating version.c from current git state." 114 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 115 ) 116elseif(EXISTS ${version_c_gen}) 117 # There's a prebuilt one to use; commonly this means we're building 118 # from a release tarball, and it includes pre-stashed bzr revision 119 # info about the release. So, in this case, we replace the original 120 # source with our pregen'd one (which already has the info in it), 121 # and just use 'cp' to turn the intermediate .c.in into the final .c. 122 set(version_c_src ${version_c_gen}) 123 124 add_custom_command(OUTPUT ${version_c} 125 DEPENDS ${version_c_in} 126 COMMAND cp ${version_c_in} ${version_c} 127 COMMENT "Using pregenerated version.c." 128 ) 129else() 130 # We've got nothing at all, so just NULL out the VCS info; it's all 131 # we can do. 132 add_custom_command(OUTPUT ${version_c} 133 DEPENDS ${version_c_in} 134 COMMAND sed -e 's/%%VCSTYPE%%/NULL/' -e 's/%%REVISION%%/NULL/' 135 < ${version_c_in} > ${version_c} 136 COMMENT "Using null version.c." 137 ) 138endif() 139 140# Now handle the first step; turning the original source .c.in into the 141# intermediate .c.in with the ctwm version written in. That's _usually_ 142# starting with the version.c.in in the source tree, but in the "no VCS 143# info, but we have a pregen'd gen/version.c to use" case above it's the 144# pregen'd file. 145add_custom_command(OUTPUT ${version_c_in} 146 DEPENDS ${version_c_src} ${CMAKE_CURRENT_SOURCE_DIR}/VERSION 147 DEPENDS ${TOOLS}/mk_version_in.sh 148 COMMAND ${TOOLS}/mk_version_in.sh ${version_c_src} > ${version_c_in} 149 COMMENT "Writing version info into version.c.in" 150) 151 152 153# Setup a 'version' binary build tool too, for easily printing bits or 154# wholes of our version. 155# 156# Not currently being used, but left as an example of possibilities. If 157# we need the version in the build process, we'll get it from the 158# ${ctwm_version_*} vars now. 159#add_executable(version ${version_c}) 160#set_target_properties(version PROPERTIES COMPILE_FLAGS "-DBUILD_VERSION_BIN") 161