Commit 42cd4ce4 authored by Brad King's avatar Brad King

Wrapping: Get preprocessor flags from CMake generator

Currently we explicitly construct a list of include directories and
compile definitions to pass to the wrapping parsers from module
variables.  With CMake 3.1 and above we can use `file(GENERATE)` and the
`$<TARGET_PROPERTY:...>` generator expression to get the
`INCLUDE_DIRECTORIES` and `COMPILE_DEFINITIONS` of the wrapped module
library at generate time from CMake.  This can actually be done in a few
earlier versions of CMake too but we need 3.1 to have a generator
expression in the `add_custom_command` `DEPENDS` option.

This approach avoids use of manually constructed lists of preprocessor
flags and always ensures that the wrapping parsers get the same
preprocessor flags as the compiler will get when compiling the module
library.  It will also allow us to get preprocessor flags through CMake
usage requirements (e.g. target_include_directories and
target_compile_definitions) for third-party system libraries.
parent f4af1aac
Pipeline #2716 passed with stage
......@@ -11,27 +11,40 @@ macro(VTK_WRAP_HIERARCHY module_name OUTPUT_DIR SOURCES)
endif()
# collect the common wrapper-tool arguments
set(_common_args)
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
# write wrapper-tool arguments to a file
set(_args_file ${module_name}Hierarchy.$<CONFIGURATION>.args)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_args_file} CONTENT "
$<$<BOOL:$<TARGET_PROPERTY:${module_name},COMPILE_DEFINITIONS>>:
-D\"$<JOIN:$<TARGET_PROPERTY:${module_name},COMPILE_DEFINITIONS>,\"
-D\">\">
$<$<BOOL:$<TARGET_PROPERTY:${module_name},INCLUDE_DIRECTORIES>>:
-I\"$<JOIN:$<TARGET_PROPERTY:${module_name},INCLUDE_DIRECTORIES>,\"
-I\">\">
")
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
set(_common_args)
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
# write wrapper-tool arguments to a file
set(_args_file ${module_name}Hierarchy.args)
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
# write wrapper-tool arguments to a file
set(_args_file ${module_name}Hierarchy.args)
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
# list of all files to wrap
set(VTK_WRAPPER_INIT_DATA)
......
......@@ -41,24 +41,37 @@ macro(vtk_wrap_java3 TARGET SRC_LIST_NAME SOURCES)
set(_common_args "${_common_args}--types \"${KIT_HIERARCHY_FILE}\"\n")
endif()
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
# write wrapper-tool arguments to a file
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.$<CONFIGURATION>.args)
file(GENERATE OUTPUT ${_args_file} CONTENT "${_common_args}
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>>:
-D\"$<JOIN:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>,\"
-D\">\">
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>>:
-I\"$<JOIN:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>,\"
-I\">\">
")
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
SET(VTK_JAVA_DEPENDENCIES)
SET(VTK_JAVA_DEPENDENCIES_FILE)
......
......@@ -43,24 +43,37 @@ macro(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES)
set(_common_args "${_common_args}--types \"${KIT_HIERARCHY_FILE}\"\n")
endif()
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
# write wrapper-tool arguments to a file
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.$<CONFIGURATION>.args)
file(GENERATE OUTPUT ${_args_file} CONTENT "${_common_args}
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>>:
-D\"$<JOIN:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>,\"
-D\">\">
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>>:
-I\"$<JOIN:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>,\"
-I\">\">
")
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
# for each class
foreach(FILE ${SOURCES})
......
......@@ -78,24 +78,37 @@ MACRO(VTK_WRAP_TCL3 TARGET SRC_LIST_NAME SOURCES COMMANDS)
set(_common_args "${_common_args}--types \"${KIT_HIERARCHY_FILE}\"\n")
endif()
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
# write wrapper-tool arguments to a file
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.$<CONFIGURATION>.args)
file(GENERATE OUTPUT ${_args_file} CONTENT "${_common_args}
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>>:
-D\"$<JOIN:$<TARGET_PROPERTY:${TARGET},COMPILE_DEFINITIONS>,\"
-D\">\">
$<$<BOOL:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>>:
-I\"$<JOIN:$<TARGET_PROPERTY:${TARGET},INCLUDE_DIRECTORIES>,\"
-I\">\">
")
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
# all the include directories
if(VTK_WRAP_INCLUDE_DIRS)
set(TMP_INCLUDE_DIRS ${VTK_WRAP_INCLUDE_DIRS})
else()
set(TMP_INCLUDE_DIRS ${VTK_INCLUDE_DIRS})
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
endif()
foreach(INCLUDE_DIR ${TMP_INCLUDE_DIRS})
set(_common_args "${_common_args}-I\"${INCLUDE_DIR}\"\n")
endforeach()
get_directory_property(_def_list DEFINITION COMPILE_DEFINITIONS)
foreach(TMP_DEF ${_def_list})
set(_common_args "${_common_args}-D${TMP_DEF}\n")
endforeach()
# write wrapper-tool arguments to a file
string(STRIP "${_common_args}" CMAKE_CONFIGURABLE_FILE_CONTENT)
set(_args_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.args)
configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${_args_file} @ONLY)
# for each class
FOREACH(FILE ${SOURCES})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment