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

MAYA-124107 - MayaUSD: build as Universal Binary 2 (x86_64 + arm64) #2575

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(CMAKE_INSTALL_MESSAGE "NEVER")

if(APPLE)
if(BUILD_UB2)
message(STATUS "Building with Universal Binary 2")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
else()
Expand Down
29 changes: 25 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,28 @@ def GetVisualStudioCompilerAndVersion():
return (msvcCompiler, tuple(int(v) for v in match.groups()))
return None

def IsVisualStudio2017OrGreater():
VISUAL_STUDIO_2017_VERSION = (15, 0)
def IsVisualStudioVersionOrGreater(desiredVersion):
if not Windows():
return False

msvcCompilerAndVersion = GetVisualStudioCompilerAndVersion()
if msvcCompilerAndVersion:
_, version = msvcCompilerAndVersion
return version >= VISUAL_STUDIO_2017_VERSION
return version >= desiredVersion
return False

def IsVisualStudio2022OrGreater():
VISUAL_STUDIO_2022_VERSION = (17, 0)
return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2022_VERSION)

def IsVisualStudio2019OrGreater():
VISUAL_STUDIO_2019_VERSION = (16, 0)
return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2019_VERSION)

def IsVisualStudio2017OrGreater():
VISUAL_STUDIO_2017_VERSION = (15, 0)
return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2017_VERSION)
Comment on lines +110 to +130
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added support for both VS2019 and VS2022.


def GetCPUCount():
try:
return multiprocessing.cpu_count()
Expand Down Expand Up @@ -245,14 +259,21 @@ def RunCMake(context, extraArgs=None, stages=None):
# building a 64-bit project. (Surely there is a better way to do this?)
# TODO: figure out exactly what "vcvarsall.bat x64" sets to force x64
if generator is None and Windows():
if IsVisualStudio2017OrGreater():
if IsVisualStudio2022OrGreater():
generator = "Visual Studio 17 2022"
elif IsVisualStudio2019OrGreater():
generator = "Visual Studio 16 2019"
elif IsVisualStudio2017OrGreater():
generator = "Visual Studio 15 2017 Win64"
else:
generator = "Visual Studio 14 2015 Win64"

if generator is not None:
generator = '-G "{gen}"'.format(gen=generator)

if generator and 'Visual Studio' in generator and IsVisualStudio2019OrGreater():
generator = generator + " -A x64"

# get build variant
variant= BuildVariant(context)

Expand Down
6 changes: 0 additions & 6 deletions cmake/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ macro(fetch_googletest)
# sequence parsing errors. PPT, 22-Nov-2018.
file(TO_CMAKE_PATH ${CMAKE_MAKE_PROGRAM} CMAKE_MAKE_PROGRAM)

# Force the use of ABI version 0 on Linux.
# This is what Maya has been using for 2019...2023
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(FORCE_OLD_ABI "-D_GLIBCXX_USE_CXX11_ABI=0")
endif()
Comment on lines -28 to -32
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved into new helper: get_external_project_default_values()


if (GOOGLETEST_SRC_DIR)
configure_file(cmake/googletest_src.txt.in ${GOOGLETEST_BUILD_ROOT}/googletest-config/CMakeLists.txt)
else()
Expand Down
5 changes: 2 additions & 3 deletions cmake/googletest_download.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ ExternalProject_Add(googletest
SOURCE_DIR "${GOOGLETEST_BUILD_ROOT}/googletest-src"
BINARY_DIR "${GOOGLETEST_BUILD_ROOT}/googletest-build"
CMAKE_ARGS
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
"${MAYAUSD_EXTERNAL_PROJECT_GENERAL_SETTINGS}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just like Maya does, use a set of general settings for all external projects (MayaUsd currently only has one for googletest).

"-DCMAKE_INSTALL_PREFIX=${GOOGLETEST_BUILD_ROOT}/googletest-install"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-Dgtest_force_shared_crt=ON"
"-DBUILD_GMOCK=OFF"
"-DBUILD_SHARED_LIBS=ON"
Expand All @@ -32,5 +31,5 @@ ExternalProject_Add(googletest
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}"
"-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}"
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ${FORCE_OLD_ABI}"
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
)
5 changes: 2 additions & 3 deletions cmake/googletest_src.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ ExternalProject_Add(googletest
SOURCE_DIR "${GOOGLETEST_SRC_DIR}"
BINARY_DIR "${GOOGLETEST_BUILD_ROOT}/googletest-build"
CMAKE_ARGS
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
"${MAYAUSD_EXTERNAL_PROJECT_GENERAL_SETTINGS}"
"-DCMAKE_INSTALL_PREFIX=${GOOGLETEST_BUILD_ROOT}/googletest-install"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-Dgtest_force_shared_crt=ON"
"-DBUILD_GMOCK=OFF"
"-DBUILD_SHARED_LIBS=ON"
Expand All @@ -29,5 +28,5 @@ ExternalProject_Add(googletest
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}"
"-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}"
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ${FORCE_OLD_ABI}"
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
)
52 changes: 52 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,55 @@ function(set_python_module_property target)
)
endif()
endfunction()

# This fuction will populate "out_var" with the default values external
# projects are expected to need.
# It can take an optional argument that will replace the list separator
# in CMake values. For instance, if an external project uses a different
# list separator, the values in here must be changed to reflect this.
function(get_external_project_default_values out_var)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically copied this function from Maya for how it setup the external projects.

# Some of these variables might end up not being used by some projects
# Therefore avoid useless warnings in the log.
list(APPEND setting_list --no-warn-unused-cli)

# Force the use of ABI version 0 on Linux.
# This is what Maya has been using for 2019...2023
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND setting_list -D_GLIBCXX_USE_CXX11_ABI=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This was supposed to change for 2024, I don't know what is the current status of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I'm aware of this. Its part of the support for RHEL8. We'll need changes for USD and MayaUsd at some point.

endif()
Comment on lines +279 to +281
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved from googletest.cmake


if(ARGN)
list(GET ARGN 0 custom_sep)
endif()

# Macro to add the value only if it's present.
macro(external_project_conditional_define option)
if (${option})
if(custom_sep)
# This will change the list separator to the desired one.
# i.e. -DCMAKE_OSX_ARCHITECTURES=x86_64;arm64 -> -DCMAKE_OSX_ARCHITECTURES=x86_64|arm64
string(REPLACE ";" ${custom_sep} ${option} "${${option}}")
endif()
list(APPEND setting_list -D${option}=${${option}})
endif()
endmacro(external_project_conditional_define)

external_project_conditional_define(CMAKE_INSTALL_MESSAGE)
external_project_conditional_define(CMAKE_BUILD_TYPE)
external_project_conditional_define(CMAKE_MAKE_PROGRAM)

if(BUILD_UB2)
# UB2 builds require this flag
external_project_conditional_define(CMAKE_OSX_ARCHITECTURES)
external_project_conditional_define(CMAKE_OSX_DEPLOYMENT_TARGET)
endif()
Comment on lines +303 to +307
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add flags for UB2


# Debugging informations for external projects
external_project_conditional_define(CMAKE_VERBOSE_MAKEFILE)
external_project_conditional_define(CMAKE_FIND_DEBUG_MODE)

set(${out_var} ${setting_list} PARENT_SCOPE)
endfunction(get_external_project_default_values)

# Create one for all the project using the default list separator
get_external_project_default_values(MAYAUSD_EXTERNAL_PROJECT_GENERAL_SETTINGS "$<SEMICOLON>")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Create one variable "MAYAUSD_EXTERNAL_PROJECT_GENERAL_SETTINGS" with all general settings. Used by googletest external project.