Skip to content

Improve the handling of /external:I#13904

Merged
snnn merged 3 commits intomainfrom
snnn/cmake_improve
Dec 9, 2022
Merged

Improve the handling of /external:I#13904
snnn merged 3 commits intomainfrom
snnn/cmake_improve

Conversation

@snnn
Copy link
Copy Markdown
Contributor

@snnn snnn commented Dec 8, 2022

Description

Improve the handling of "/external:I". The "onnxruntime_external_lib_include_dir" variable may be:

  1. A simple file path
  2. A cmake generator expression like "$<INSTALL_INTERFACE:include>", "$<TARGET_PROPERTY:onnx_proto,INTERFACE_INCLUDE_DIRECTORIES>", "$<BUILD_INTERFACE:xxxx>". It seems that we can't simply put them in to the "target_compile_options" line. So this PR tries to parse the expression and extract the part we need out.

Motivation and Context

Comment thread cmake/CMakeLists.txt
@snnn snnn requested a review from edgchen1 December 9, 2022 17:12
@snnn
Copy link
Copy Markdown
Contributor Author

snnn commented Dec 9, 2022

/azp run orttraining-linux-gpu-ci-pipeline

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread cmake/CMakeLists.txt
if(onnxruntime_external_lib_include_dir MATCHES "^\\$<BUILD_INTERFACE:([^>]+)>$")
string(REGEX REPLACE "^\\$<BUILD_INTERFACE:([^>]+)>$" "\\1" onnxruntime_external_lib_include_dir_cmake "${onnxruntime_external_lib_include_dir}")
cmake_path(NATIVE_PATH onnxruntime_external_lib_include_dir_cmake NORMALIZE onnxruntime_external_lib_include_dir_native)
target_compile_options(${target_name} PRIVATE "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/external:I${onnxruntime_external_lib_include_dir_native}>")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the problem with nested generator expressions? would something like https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:GENEX_EVAL help?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the include dirs are empty. For example, it may have things like "$<BUILD_INTERFACE:>", which will be evaluated as an empty string. Then this "/external:I" probably doesn't have a value, and it may misuse another thing after it as the value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. might be useful to include a comment explaining why we need to do this

@snnn snnn merged commit d5b4522 into main Dec 9, 2022
@snnn snnn deleted the snnn/cmake_improve branch December 9, 2022 19:44
baijumeswani pushed a commit that referenced this pull request Dec 13, 2022
### Description

Improve the handling of "/external:I". The
"onnxruntime_external_lib_include_dir" variable may be:

1. A simple file path
2. A cmake generator expression like "$<INSTALL_INTERFACE:include>",
"$<TARGET_PROPERTY:onnx_proto,INTERFACE_INCLUDE_DIRECTORIES>",
"$<BUILD_INTERFACE:xxxx>". It seems that we can't simply put them in to
the "target_compile_options" line. So this PR tries to parse the
expression and extract the part we need out.

### Motivation and Context
Resolve the Github issue: #13893
simon-moo pushed a commit to simon-moo/onnxruntime that referenced this pull request Dec 26, 2022
### Description

Improve the handling of "/external:I". The
"onnxruntime_external_lib_include_dir" variable may be:

1. A simple file path
2. A cmake generator expression like "$<INSTALL_INTERFACE:include>",
"$<TARGET_PROPERTY:onnx_proto,INTERFACE_INCLUDE_DIRECTORIES>",
"$<BUILD_INTERFACE:xxxx>". It seems that we can't simply put them in to
the "target_compile_options" line. So this PR tries to parse the
expression and extract the part we need out.

### Motivation and Context
Resolve the Github issue: microsoft#13893
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants