Discussion:
[cmake-developers] Setting additional compile flags to .hlsl files?
Robert Goulet
2015-01-26 17:20:24 UTC
Permalink
Hi all,

Any reasons why setting additional compile flags on .hlsl files would not work?

I tried this:

set_source_files_properties(${SHADER_FILE} PROPERTIES COMPILE_FLAGS "/I${CMAKE_SOURCE_DIR}/src")

...and it didn't get written to the .vcxproj file at all. In this specific case, I want to add include directories when I build this .hlsl shader. Is it correct to assume that it should have passed the additional flag to this file? Or maybe there's another way to do this? Thanks.



Robert Goulet
Senior Software Developer
Games Solutions Group
Autodesk Media & Entertainment

MAIN +1 514 393 1616
DIRECT +1 514 954 3911
MOBILE +1 438 397 4075

Autodesk, Inc.
10 Rue Duke
Montreal, QC, H3C 2L7
www.autodesk.com<http://www.autodesk.com/>

[Description: Email_Signature_Logobar]
Brad King
2015-01-26 17:42:44 UTC
Permalink
Post by Robert Goulet
set_source_files_properties(${SHADER_FILE} PROPERTIES COMPILE_FLAGS "/I${CMAKE_SOURCE_DIR}/src")
and it didn't get written to the .vcxproj file at all.
Right now .hlsl files are written by

cmVisualStudio10TargetGenerator::WriteExtraSource

because they are (perhaps incorrectly) not classified as
compiled sources. Look at use of GetObjectSources in
cmVisualStudio10TargetGenerator::WriteAllSources for where
compiled sources get handled. The OutputSourceSpecificFlags
method handles source-specific COMPILE_FLAGS.

The reason .hlsl files are not classified as compiled sources
is because HLSL is not a first-class language in CMake that
one enables via enable_language(). This also prevents them
from being handled by non-VS generators. If you are
interested in working on making HLSL a first-class language
I can help you get started.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-26 18:04:21 UTC
Permalink
Do we really need to go down the road of making hlsl a 'first-class' language to add support for additional compile flags?

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Monday, January 26, 2015 12:43 PM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Robert Goulet
set_source_files_properties(${SHADER_FILE} PROPERTIES COMPILE_FLAGS
"/I${CMAKE_SOURCE_DIR}/src") and it didn't get written to the .vcxproj file at all.
Right now .hlsl files are written by

cmVisualStudio10TargetGenerator::WriteExtraSource

because they are (perhaps incorrectly) not classified as compiled sources. Look at use of GetObjectSources in cmVisualStudio10TargetGenerator::WriteAllSources for where compiled sources get handled. The OutputSourceSpecificFlags method handles source-specific COMPILE_FLAGS.

The reason .hlsl files are not classified as compiled sources is because HLSL is not a first-class language in CMake that one enables via enable_language(). This also prevents them from being handled by non-VS generators. If you are interested in working on making HLSL a first-class language I can help you get started.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Brad King
2015-01-26 18:07:46 UTC
Permalink
Post by Robert Goulet
Do we really need to go down the road of making hlsl a 'first-class'
language to add support for additional compile flags?
Right now the Visual Studio generator has custom logic for .hlsl
sources, so the rest of CMake knows nothing about them and treats
them like .txt files. So, one could either add more custom logic
to the VS .hlsl support to honor COMPILE_FLAGS, or add the needed
infrastructure for enable_language(HLSL). The latter approach
is much more general.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-26 18:10:55 UTC
Permalink
Considering HLSL is DirectX only, I don't think we need (yet) to add it as a first-class language. And also because of time constraints, I might just go and add the COMPILE_FLAGS into the custom logic. I will send a patch when I can. Thanks!

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Monday, January 26, 2015 1:08 PM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Robert Goulet
Do we really need to go down the road of making hlsl a 'first-class'
language to add support for additional compile flags?
Right now the Visual Studio generator has custom logic for .hlsl sources, so the rest of CMake knows nothing about them and treats them like .txt files. So, one could either add more custom logic to the VS .hlsl support to honor COMPILE_FLAGS, or add the needed infrastructure for enable_language(HLSL). The latter approach is much more general.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Brad King
2015-01-26 18:23:20 UTC
Permalink
Post by Robert Goulet
I might just go and add the COMPILE_FLAGS into the custom logic.
Okay. Look at the OutputSourceSpecificFlags logic as a reference.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-26 19:28:37 UTC
Permalink
Here's a patch for adding additional compile flags to .hlsl files in Visual Studio. For this I simply added the new VS_SHADER_FLAGS source file property and basically did the same as other VS_SHADER_* properties. Tested in my project and it works. Please consider merging in master.

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Monday, January 26, 2015 1:23 PM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Robert Goulet
I might just go and add the COMPILE_FLAGS into the custom logic.
Okay. Look at the OutputSourceSpecificFlags logic as a reference.

-Brad
Brad King
2015-01-26 20:09:15 UTC
Permalink
Post by Robert Goulet
Here's a patch for adding additional compile flags to .hlsl
files in Visual Studio. For this I simply added the new
VS_SHADER_FLAGS source file property and basically did the
same as other VS_SHADER_* properties.
Okay. Please use spaces instead of tabs and match the surrounding
indentation. Also please add/modify:

Help/prop_sf/VS_SHADER_FLAGS.rst
Help/manual/cmake-properties.7.rst

to add the documentation, and add a release note as:

Help/release/dev/vs-shader-flags.rst

following the style of other release note files in that directory.

Also please extend Tests/VSWinStorePhone/CMakeLists.txt with a
test for this feature.

Thanks,
-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-27 17:47:37 UTC
Permalink
There you go. Let me know if it's good now.

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Monday, January 26, 2015 3:09 PM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Robert Goulet
Here's a patch for adding additional compile flags to .hlsl files in
Visual Studio. For this I simply added the new VS_SHADER_FLAGS source
file property and basically did the same as other VS_SHADER_*
properties.
Okay. Please use spaces instead of tabs and match the surrounding indentation. Also please add/modify:

Help/prop_sf/VS_SHADER_FLAGS.rst
Help/manual/cmake-properties.7.rst

to add the documentation, and add a release note as:

Help/release/dev/vs-shader-flags.rst

following the style of other release note files in that directory.

Also please extend Tests/VSWinStorePhone/CMakeLists.txt with a test for this feature.

Thanks,
-Brad
Brad King
2015-01-27 17:59:29 UTC
Permalink
Post by Robert Goulet
There you go. Let me know if it's good now.
Thanks. I've committed the patch and merged for testing:

VS: Add source file property to set extra hlsl shader flags
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6b9bd827

In the test I see:

VS_SHADER_FLAGS "/Fh $(OutDir)%(Filename).h"

which can be manually verified but I do not see how the test
automatically verifies that the flag is correctly used.

Thanks,
-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-27 18:22:09 UTC
Permalink
If the flag would be wrong, compilation would fail.

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Tuesday, January 27, 2015 12:59 PM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Robert Goulet
There you go. Let me know if it's good now.
Thanks. I've committed the patch and merged for testing:

VS: Add source file property to set extra hlsl shader flags
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6b9bd827

In the test I see:

VS_SHADER_FLAGS "/Fh $(OutDir)%(Filename).h"

which can be manually verified but I do not see how the test automatically verifies that the flag is correctly used.

Thanks,
-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Brad King
2015-01-27 18:31:05 UTC
Permalink
Post by Robert Goulet
If the flag would be wrong, compilation would fail.
What if the flag is not added at all because the property is ignored?
The test needs to be something that would fail without this change.

Thanks,
-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Brad King
2015-01-28 14:31:43 UTC
Permalink
Post by Brad King
Post by Robert Goulet
If the flag would be wrong, compilation would fail.
What if the flag is not added at all because the property is ignored?
The test needs to be something that would fail without this change.
I revised the test to add preprocessor definitions as flags and
check for them in the .hlsl sources. I also fixed the /Fh flag
value to be quoted to work with a space in the path.

Revised commit:

VS: Add source file property to set extra hlsl shader flags
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4775c901

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2015-01-28 15:06:51 UTC
Permalink
Awesome, thanks!

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Wednesday, January 28, 2015 9:32 AM
To: Robert Goulet
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] Setting additional compile flags to .hlsl files?
Post by Brad King
Post by Robert Goulet
If the flag would be wrong, compilation would fail.
What if the flag is not added at all because the property is ignored?
The test needs to be something that would fail without this change.
I revised the test to add preprocessor definitions as flags and check for them in the .hlsl sources. I also fixed the /Fh flag value to be quoted to work with a space in the path.

Revised commit:

VS: Add source file property to set extra hlsl shader flags
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4775c901

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Loading...