[cmake,configure_file] Refactor config file generation
* for multi configuration generators generate a configuration file for each supported configuration * add a custom target that copies the currently used configuration to the expected destination * replace compiler flags et al in configuration files with currently active values
This commit is contained in:
parent
a210e7b86d
commit
7f89396fdd
@ -4,19 +4,45 @@
|
||||
# Handy if the generated files might have changed
|
||||
#
|
||||
|
||||
function(cleaning_configure_file SRC DST)
|
||||
configure_file(${SRC} ${DST} ${ARGN})
|
||||
set_property(
|
||||
DIRECTORY
|
||||
APPEND
|
||||
PROPERTY ADDITIONAL_CLEAN_FILES
|
||||
${DST}
|
||||
)
|
||||
set_property(
|
||||
DIRECTORY
|
||||
APPEND
|
||||
PROPERTY CMAKE_CONFIGURE_DEPENDS
|
||||
${SRC}
|
||||
${DST}
|
||||
)
|
||||
include (CFlagsToVar)
|
||||
|
||||
function(cleaning_configure_file RSRC RDST)
|
||||
get_filename_component(SRC "${RSRC}" ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
get_filename_component(DST "${RDST}" ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
get_filename_component(DST_DIR "${DST}" DIRECTORY)
|
||||
if (CMAKE_CONFIGURATION_TYPES)
|
||||
foreach(CFG ${CMAKE_CONFIGURATION_TYPES})
|
||||
set(CURRENT_BUILD_CONFIG ${CFG})
|
||||
CFlagsToVar(CURRENT_C_FLAGS ${CURRENT_BUILD_CONFIG})
|
||||
configure_file(${SRC} ${DST}_${CFG} ${ARGN})
|
||||
unset(CURRENT_BUILD_CONFIG)
|
||||
unset(CURRENT_C_FLAGS)
|
||||
endforeach()
|
||||
else()
|
||||
# We call this also from CMake scripts without a CMAKE_BUILD_TYPE
|
||||
# Fall back to an explicitly unsupported build type to point out something is wrond
|
||||
# if this variable is used during such a call
|
||||
if (CMAKE_BUILD_TYPE)
|
||||
set(CURRENT_BUILD_CONFIG ${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(CURRENT_BUILD_CONFIG "InvalidBuildType")
|
||||
endif()
|
||||
CFlagsToVar(CURRENT_C_FLAGS ${CURRENT_BUILD_CONFIG})
|
||||
configure_file(${SRC} ${DST}_${CMAKE_BUILD_TYPE} ${ARGN})
|
||||
unset(CURRENT_BUILD_CONFIG)
|
||||
unset(CURRENT_C_FLAGS)
|
||||
endif()
|
||||
|
||||
configure_file(${SRC} ${DST} ${ARGN})
|
||||
|
||||
string(SHA256 DST_HASH "${DST}")
|
||||
if (NOT TARGET ct-${DST_HASH})
|
||||
add_custom_target(ct-${DST_HASH} ALL
|
||||
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${DST_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} "-E" "copy" "${DST}_$<CONFIG>" "${DST}"
|
||||
COMMAND ${CMAKE_COMMAND} "-E" "sha256sum" "${DST}_$<CONFIG>" > ${DST}.hash
|
||||
DEPENDS ${DST}
|
||||
BYPRODUCTS ${DST}.hash
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
@ -38,9 +38,6 @@ if (WIN32)
|
||||
string(REPLACE "\\" "\\\\" NATIVE_FREERDP_PROXY_PLUGINDIR "${NATIVE_FREERDP_PROXY_PLUGINDIR}")
|
||||
endif()
|
||||
|
||||
include(CFlagsToVar)
|
||||
CFlagsToVar(C_FLAGS)
|
||||
|
||||
cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h)
|
||||
cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h)
|
||||
cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/config.h)
|
||||
|
@ -33,9 +33,6 @@ FOREACH(var ${res})
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
|
||||
include(CFlagsToVar)
|
||||
CFlagsToVar(C_FLAGS)
|
||||
|
||||
string(REPLACE ";" " " UWAC_BUILD_CONFIG "${UWAC_BUILD_CONFIG_LIST}")
|
||||
cleaning_configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/version.h)
|
||||
cleaning_configure_file(buildflags.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/buildflags.h)
|
||||
|
@ -15,9 +15,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
include(CFlagsToVar)
|
||||
CFlagsToVar(C_FLAGS)
|
||||
|
||||
cleaning_configure_file(config/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h)
|
||||
cleaning_configure_file(config/wtypes.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/wtypes.h)
|
||||
cleaning_configure_file(config/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/build-config.h)
|
||||
|
Loading…
Reference in New Issue
Block a user