diff options
author | Jannick <thirdedition@gmx.net> | 2019-11-07 00:13:27 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-11-15 16:46:06 (GMT) |
commit | c5fb36a4cb8bd3272e2e0b54e3947886ad7eb778 (patch) | |
tree | d67a021cd11e8a7dba8c1cee1e252ffb0e429fc8 /Modules/FindFLEX.cmake | |
parent | 5695b0464b411746b207da2ee23b8e2d9f8ffec2 (diff) | |
download | CMake-c5fb36a4cb8bd3272e2e0b54e3947886ad7eb778.zip CMake-c5fb36a4cb8bd3272e2e0b54e3947886ad7eb778.tar.gz CMake-c5fb36a4cb8bd3272e2e0b54e3947886ad7eb778.tar.bz2 |
FindFLEX: Add policy CMP0098 to run flex in build tree
Diffstat (limited to 'Modules/FindFLEX.cmake')
-rw-r--r-- | Modules/FindFLEX.cmake | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index d22b7ec..90e5f86 100644 --- a/Modules/FindFLEX.cmake +++ b/Modules/FindFLEX.cmake @@ -142,8 +142,6 @@ if(FLEX_EXECUTABLE) #============================================================ # macro(FLEX_TARGET Name Input Output) - set(FLEX_TARGET_outputs "${Output}") - set(FLEX_EXECUTABLE_opts "") set(FLEX_TARGET_PARAM_OPTIONS) set(FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS @@ -165,31 +163,68 @@ if(FLEX_EXECUTABLE) if(NOT "${FLEX_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "") message(SEND_ERROR ${FLEX_TARGET_usage}) else() + + cmake_policy(GET CMP0098 _flex_CMP0098 + PARENT_SCOPE # undocumented, do not use outside of CMake + ) + set(_flex_INPUT "${Input}") + if("x${_flex_CMP0098}x" STREQUAL "xNEWx") + set(_flex_WORKING_DIR "${CMAKE_CURRENT_BINARY_DIR}") + if(NOT IS_ABSOLUTE "${_flex_INPUT}") + set(_flex_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_flex_INPUT}") + endif() + else() + set(_flex_WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + unset(_flex_CMP0098) + + set(_flex_OUTPUT "${Output}") + if(NOT IS_ABSOLUTE ${_flex_OUTPUT}) + set(_flex_OUTPUT "${_flex_WORKING_DIR}/${_flex_OUTPUT}") + endif() + set(_flex_TARGET_OUTPUTS "${_flex_OUTPUT}") + + set(_flex_EXE_OPTS "") if(NOT "${FLEX_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "") - set(FLEX_EXECUTABLE_opts "${FLEX_TARGET_ARG_COMPILE_FLAGS}") - separate_arguments(FLEX_EXECUTABLE_opts) + set(_flex_EXE_OPTS "${FLEX_TARGET_ARG_COMPILE_FLAGS}") + separate_arguments(_flex_EXE_OPTS) endif() + + set(_flex_OUTPUT_HEADER "") if(NOT "${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "") - list(APPEND FLEX_TARGET_outputs "${FLEX_TARGET_ARG_DEFINES_FILE}") - list(APPEND FLEX_EXECUTABLE_opts --header-file=${FLEX_TARGET_ARG_DEFINES_FILE}) + set(_flex_OUTPUT_HEADER "${FLEX_TARGET_ARG_DEFINES_FILE}") + if(IS_ABSOLUTE "${_flex_OUTPUT_HEADER}") + set(_flex_OUTPUT_HEADER_ABS "${_flex_OUTPUT_HEADER}") + else() + set(_flex_OUTPUT_HEADER_ABS "${_flex_WORKING_DIR}/${_flex_OUTPUT_HEADER}") + endif() + list(APPEND _flex_TARGET_OUTPUTS "${_flex_OUTPUT_HEADER_ABS}") + list(APPEND _flex_EXE_OPTS --header-file=${_flex_OUTPUT_HEADER_ABS}) endif() - add_custom_command(OUTPUT ${FLEX_TARGET_outputs} - COMMAND ${FLEX_EXECUTABLE} ${FLEX_EXECUTABLE_opts} -o${Output} ${Input} + get_filename_component(_flex_EXE_NAME_WE "${FLEX_EXECUTABLE}" NAME_WE) + add_custom_command(OUTPUT ${_flex_TARGET_OUTPUTS} + COMMAND ${FLEX_EXECUTABLE} ${_flex_EXE_OPTS} -o${_flex_OUTPUT} ${_flex_INPUT} VERBATIM - DEPENDS ${Input} - COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + DEPENDS ${_flex_INPUT} + COMMENT "[FLEX][${Name}] Building scanner with ${_flex_EXE_NAME_WE} ${FLEX_VERSION}" + WORKING_DIRECTORY ${_flex_WORKING_DIR}) set(FLEX_${Name}_DEFINED TRUE) - set(FLEX_${Name}_OUTPUTS ${Output}) - set(FLEX_${Name}_INPUT ${Input}) - set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts}) - if("${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "") - set(FLEX_${Name}_OUTPUT_HEADER "") - else() - set(FLEX_${Name}_OUTPUT_HEADER ${FLEX_TARGET_ARG_DEFINES_FILE}) - endif() + set(FLEX_${Name}_OUTPUTS ${_flex_TARGET_OUTPUTS}) + set(FLEX_${Name}_INPUT ${_flex_INPUT}) + set(FLEX_${Name}_COMPILE_FLAGS ${_flex_EXE_OPTS}) + set(FLEX_${Name}_OUTPUT_HEADER ${_flex_OUTPUT_HEADER}) + + unset(_flex_EXE_NAME_WE) + unset(_flex_EXE_OPTS) + unset(_flex_INPUT) + unset(_flex_OUTPUT) + unset(_flex_OUTPUT_HEADER) + unset(_flex_OUTPUT_HEADER_ABS) + unset(_flex_TARGET_OUTPUTS) + unset(_flex_WORKING_DIR) + endif() endmacro() #============================================================ |