Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The aim of this PR is to allow compiler flags to be easily and clearly added within Maya USD build echo system. #412

Merged
merged 15 commits into from
Apr 21, 2020

Conversation

HamedSabri-adsk
Copy link
Contributor

PR Goal

The aim of this PR is to allow compiler flags to be easily and clearly added within Maya USD build echo system using modern cmake.

Background

When we originally started the Maya USD project, I brought in Pixar's compiler configuration( a.k.a defaults ) under the top level cmake to consume it's configurations.

This was done for two reasons:
1- It already worked out of the box when we migrated third-party/maya and it was convenient to use them for the sake of saving time.
2- other projects ( e.g Animal Logic ) was also consuming the exact same compiler configuration.

Problems

1- Pixar's compiler flags/options have a global affect and setting/appending to CMAKE_CXX_FLAGS is no longer a good practice ( see CMake documentation around this ). Everytime a compiler flag/option is added/removed/modified, it affects the entire project and literally everyone (Animal Logic , mayaUsd, mayaUsdPlugin, pxrusd).

2- Many of the compiler flags/options that came with defaults are either redundant or not needed at all which are carried over from core usd and old third-party/maya.

3- Hard to fine tune compiler options/flags around specific targets.

Solution

Introducing compiler_config.cmake where all the compiler flags/options are applied to a specific cmake echo system ( e.g mayaUsd and mayaUsdPlugin ). We use modern cmake functions ( target_compile_features, target_compile_options, target_compile_definitions) to control the options and flags. All of the compiler flags for Gnu, Clang, VS are picked as needed and are
privately added via mayaUsd_compile_config function.

Where is cmake/defaults?

cmake/defaults is moved to it's original place under plugin/pxr/cmake/defaults. I also made a small surgery in top-level AL's cmakelist to continue consuming pxr/cmake/defaults as before.

…y added within Maya USD build echo system.
@HamedSabri-adsk HamedSabri-adsk added the build Related to building maya-usd repository label Apr 8, 2020

set(msvc_flags
# we want to be as strict as possible
/W3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently have to use level 3 (/W3) instead of level 4(/W4) for Visual studio compiler since Pixar's USD core needs to adopt their API library to respect this level. Switching to /W4 is out of commission at the moment.

More on /W4 here:
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=vs-2019

target_compile_features(${TARGET}
PRIVATE
$<$<VERSION_LESS:MAYA_APP_VERSION,2019>:cxx_std_11>
$<$<VERSION_GREATER_EQUAL:MAYA_APP_VERSION,2019>:cxx_std_14>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maya2018 ---> c++11
Maya2019 and above ---> c++14

@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
include(Version)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is redundant. It is already added at the top level cmake.

Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

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

Mostly looks good to me, but it looks like no C++ language standard is being specified for the AL and pxr plugin code? If we combine this PR with #395, it seems like that would be addressed.

Comment on lines 61 to 62
$<$<VERSION_LESS:MAYA_APP_VERSION,2019>:cxx_std_11>
$<$<VERSION_GREATER_EQUAL:MAYA_APP_VERSION,2019>:cxx_std_14>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little conflicted on burying the C++ language standard inside mayaUsd_compile_config(). It feels like this should be more of a repo-level setting. Do we envision having different parts of the repo on different standards? That would seem a bit weird to me.

And somewhat related to that, which parts of the tree do we expect would not call mayaUsd_compile_config() for their targets? For now, maybe that's the AL and pxr plugins, but do we expect that to be the case long term? I'm hoping to make some time in the not too distant future to remove all the pxr build stuff from the remaining pxr plugin code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little conflicted on burying the C++ language standard inside mayaUsd_compile_config().

There are two ways of adding C++ standard in modern CMake.

1- Setting the C++ standard directly before any targets being defined which is the approach you have in your PR:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

This setting applies to all targets globally which in this case is Ok because we obviously want all targets to use the exact same standard.

2- Setting the C++ standard based on features which is a more finer grained approach

target_compile_features(foo PRIVATE|PUBLIC|INTERFACE cxx_std_11)

Now, there reason I went with this approach is because mayaUsd_compile_config already use target_compile_options and target_compile_definitions and target_compile_features seems like a good fit there.

To be clear, every targets must add mayaUsd_compile_config. Notice that all the entries for target_compile_options, target_compile_definitions, target_compile_features are declared as PRIVATE which is very important. Any change in mayaUsd_compile_config affects all targets that are inheriting this function which simulates a global behavior.

It feels like this should be more of a repo-level setting. Do we envision having different parts of the repo on different standards? That would seem a bit weird to me.

Not at all, all targets should have the same standard.

And somewhat related to that, which parts of the tree do we expect would not call mayaUsd_compile_config() for their targets?

Every targets must add mayaUsd_compile_config

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. I guess I was reacting to two things:

  • The fact that we're already breaking the "every target must add mayaUsd_compile_config()" rule, since the AL and pxr plugin code do not use it. But that's probably a whole other can of beans, and they probably should use it eventually.
  • But more generally, we're saying that every target must add mayaUsd_compile_config() so that it picks up (effectively) global settings. It seems a little counter-intuitive to me to require authors to do something in their CMakeLists.txt so that they pick up the settings all targets need?

Anyway, it doesn't bother me that much, and I'm likely missing other context here. Just wanted to raise the question. Thanks for humoring me!

target_compile_definitions(${PROJECT_NAME}
target_compile_definitions(${PROJECT_NAME}
PUBLIC
USD_VERSION_NUM=${USD_VERSION_NUM}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems ok for now, but since it comes from a dependency, maybe it should be on the upstream libraries to ensure this is set on the imported target with INTERFACE_COMPILE_DEFINITIONS?

Hamed Sabri added 2 commits April 15, 2020 10:32
Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks @HamedSabri-adsk!

There might be an issue building for Maya 2018 against core USD 20.05+? We don't build for 2018 anymore, and I'm not sure how much longer you all are intending to support 2018 either.

Comment on lines 61 to 62
$<$<VERSION_LESS:MAYA_APP_VERSION,2019>:cxx_std_11>
$<$<VERSION_GREATER_EQUAL:MAYA_APP_VERSION,2019>:cxx_std_14>
Copy link
Contributor

Choose a reason for hiding this comment

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

Right. I guess I was reacting to two things:

  • The fact that we're already breaking the "every target must add mayaUsd_compile_config()" rule, since the AL and pxr plugin code do not use it. But that's probably a whole other can of beans, and they probably should use it eventually.
  • But more generally, we're saying that every target must add mayaUsd_compile_config() so that it picks up (effectively) global settings. It seems a little counter-intuitive to me to require authors to do something in their CMakeLists.txt so that they pick up the settings all targets need?

Anyway, it doesn't bother me that much, and I'm likely missing other context here. Just wanted to raise the question. Thanks for humoring me!

Comment on lines 21 to 25
if(${MAYA_APP_VERSION} STRLESS_EQUAL "2019")
set(CMAKE_CXX_STANDARD 11)
elseif(${MAYA_APP_VERSION} STRGREATER_EQUAL "2019")
set(CMAKE_CXX_STANDARD 14)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I think the version of USD factors into this decision as well. USD 20.05 and later will require C++14, so for example I think attempting to build maya-usd for Maya 2018 against USD 20.05 would fail with this?

@HamedSabri-adsk HamedSabri-adsk added the do-not-merge-yet Development is not finished, PR not ready for merge label Apr 15, 2020
$<$<BOOL:${IS_MACOSX}>:OSMac_>
$<$<BOOL:${IS_LINUX}>:LINUX>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have noticed a lot of targets are adding these two flags privately. Since these flags are needed for Maya, it makes more sense I make them as part of PUBLIC section in mayaUsd shared library. I will have a separate PR to address this but for now it should be ok.

…was added recently and is only defined when building against UFE 0.2.x.
PUBLIC
UFE_PREVIEW_VERSION_NUM=${UFE_PREVIEW_VERSION_NUM}
)
endif()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix 2019 build issue on Windows ( Fatal Error C1017 invalid integer constant expression ).

UFE_PREVIEW_VERSION_NUM is a new variable that was added recently and only defined when building against UFE 0.x.x.

…options are either unused or have been OFF for ever.
@HamedSabri-adsk
Copy link
Contributor Author

Hi @mattyjams,

I have updated this PR to respect the recent changes in dev branch. Following this, I decided to finish what we started in here and get plugin/pxr and plugin/al to adopt compiler configuration ( mayaUsd_compile_config) to avoid duplication and future confusions. The work is done in these 2 PRs( PR #443, PR #445 ).

Union of PR 412, 443, 445 makes this PR complete. Also defaults folders, is no longer in use and I didn't delete it until your confirmation.

Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks @HamedSabri-adsk!

@@ -110,6 +110,8 @@ BUILD_PXR_PLUGIN | builds the Pixar USD plugin and libraries.
BUILD_AL_PLUGIN | builds the Animal Logic USD plugin and libraries. | ON
BUILD_HDMAYA | builds the Maya-To-Hydra plugin and scene delegate. | ON
BUILD_TESTS | builds all unit tests. | ON
BUILD_STRICT_MODE | enforces all warnings as errors. | ON
BUILD_SHARED_LIBS | build libraries as shared or static. | ON
Copy link
Contributor

Choose a reason for hiding this comment

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

Funky whitespacing. Tab characters, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @mattyjams , indeed funky whitespacing but one thing I have noticed is that is how github shows it when it wraps charcaters. In my text editor, I usually have word wrap off when I work with *.md file.

I have also noticed that sometimes github doesn't properly visualize spaces vs tabs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is because Github uses a default tab size of 8. I have installed this chrome extension to allow me to set it back to the standard size of 4. https://chrome.google.com/webstore/detail/github-custom-tab-size/jcjfkmdkcaopkioccnpbhiemfcmpnghe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is because Github uses a default tab size of 8. I have installed this chrome extension to allow me to set it back to the standard size of 4. https://chrome.google.com/webstore/detail/github-custom-tab-size/jcjfkmdkcaopkioccnpbhiemfcmpnghe

Ughhhh... Thanks @seando-adsk. I didn't know that. I never use Chrome but try to see if they have a similar extension for Firefox.

…figuration_plugin_pxr

plugin/pxr is now adopting mayaUsd_compile_config routine
@HamedSabri-adsk HamedSabri-adsk removed the do-not-merge-yet Development is not finished, PR not ready for merge label Apr 21, 2020
@kxl-adsk kxl-adsk merged commit 09ae6ef into dev Apr 21, 2020
@kxl-adsk kxl-adsk deleted the sabrih/MAYA-103926/compiler_configuration_mayausd branch April 21, 2020 20:30
ppt-adsk pushed a commit that referenced this pull request May 30, 2023
* HYDRA-192 Remove WANT_UFE_BUILD option

Remove the build flags that allowed UFE to be turned off.  Make UFE a required library for the build.
Remove some UFE-related tests in FindMaya.cmake that were based on old Maya versions that we don't support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to building maya-usd repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants