Skip to content

Commit

Permalink
CMake Modernization and cleanup in lib and plugin/adsk
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamed Sabri committed Mar 3, 2020
1 parent fe12690 commit e3d4771
Show file tree
Hide file tree
Showing 45 changed files with 1,496 additions and 1,465 deletions.
84 changes: 40 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# =======================================================================
# Copyright 2019 Autodesk
# Copyright 2020 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,16 +12,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =======================================================================
#

cmake_minimum_required(VERSION 3.12.0)
cmake_minimum_required(VERSION 3.13...3.17)

project(maya-usd)

#==============================================================================
# Define common build variables
#==============================================================================
#------------------------------------------------------------------------------
# options
#------------------------------------------------------------------------------
option(BUILD_MAYAUSD_LIBRARY "Build Core USD libraries." ON)
option(BUILD_ADSK_PLUGIN "Build Autodesk USD plugin." ON)
option(BUILD_PXR_PLUGIN "Build the Pixar USD plugin and libraries." ON)
Expand All @@ -31,32 +28,41 @@ option(BUILD_HDMAYA "Build the Maya-To-Hydra plugin and scene delegate." ON)
option(BUILD_TESTS "Build tests." ON)
option(CMAKE_WANT_UFE_BUILD "Enable building with UFE (if found)." ON)

#==============================================================================
# Internal flags to control build
#==============================================================================
#------------------------------------------------------------------------------
# internal flags to control build
#------------------------------------------------------------------------------
# MAYAUSD_TO_USD_RELATIVE_PATH : Set this variable to any relative path from install
# folder to USD location. If defined will set relative
# rpaths for USD libraries.

#------------------------------------------------------------------------------
# global options
#------------------------------------------------------------------------------
# Avoid noisy install messages
set(CMAKE_INSTALL_MESSAGE "NEVER")
#==============================================================================
# Modules and Definitions
#==============================================================================
list(APPEND CMAKE_MODULE_PATH

set(CMAKE_OSX_ARCHITECTURES "x86_64")

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
${CMAKE_CURRENT_SOURCE_DIR}/cmake/defaults
)

# Use RUNPATH instead of RPATH for all shared libs and executables on Linux
if(IS_LINUX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")
endif()

#------------------------------------------------------------------------------
# modules and definitions
#------------------------------------------------------------------------------
if (BUILD_MAYAUSD_LIBRARY)
include(cmake/mayausd_version.info)
set(MAYAUSD_VERSION "${MAYAUSD_MAJOR_VERSION}.${MAYAUSD_MINOR_VERSION}.${MAYAUSD_PATCH_LEVEL}")
endif()

if (APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif()

if (DEFINED PYTHON_INCLUDE_DIR AND DEFINED PYTHON_LIBRARIES AND DEFINED Python_EXECUTABLE)
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
SET(PYTHONLIBS_FOUND TRUE)
Expand Down Expand Up @@ -119,9 +125,9 @@ else()
message(STATUS "QT_LOCATION not set. Building Qt features will be disabled.")
endif()

#==============================================================================
# Compiler
#==============================================================================
#------------------------------------------------------------------------------
# compiler configuration
#------------------------------------------------------------------------------
# CXXDefaults will set a variety of variables for the project.
# Consume them here. This is an effort to keep the most common
# build files readable.
Expand All @@ -137,36 +143,27 @@ if(NOT WIN32)
endif()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

# Use RUNPATH instead of RPATH for all shared libs and executables on Linux
if(IS_LINUX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-new-dtags")
endif()

#==============================================================================
# Tests
#==============================================================================
#------------------------------------------------------------------------------
# test
#------------------------------------------------------------------------------
if (BUILD_TESTS)
include(cmake/Googletest.cmake)
fetch_googletest()

enable_testing()

add_subdirectory(test)

set(MAYAUSD_GTEST_PATH "PATH+:=lib/gtest")
endif()

#==============================================================================
# CORE
#==============================================================================
#------------------------------------------------------------------------------
# lib
#------------------------------------------------------------------------------
if (BUILD_MAYAUSD_LIBRARY)
add_subdirectory(lib)
endif()

#==============================================================================
# PLUGINS
#==============================================================================
#------------------------------------------------------------------------------
# plugins
#------------------------------------------------------------------------------
if (BUILD_PXR_PLUGIN)
add_subdirectory(plugin/pxr)
endif()
Expand All @@ -187,11 +184,10 @@ if (BUILD_ADSK_PLUGIN)
add_subdirectory(plugin/adsk)
endif()

#==============================================================================
# Install mayaUSD.mod
#==============================================================================
#------------------------------------------------------------------------------
# install
#------------------------------------------------------------------------------
configure_file(mayaUSD.mod.template ${PROJECT_BINARY_DIR}/mayaUSD.mod)
install(FILES ${PROJECT_BINARY_DIR}/mayaUSD.mod
DESTINATION ${CMAKE_INSTALL_PREFIX}
)

25 changes: 14 additions & 11 deletions cmake/jinja.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#-
# =======================================================================
# Copyright 2018 Autodesk, Inc. All rights reserved.
#
# This computer source code and related instructions and comments are the
# unpublished confidential and proprietary information of Autodesk, Inc.
# and are protected under applicable copyright and trade secret law. They
# may not be disclosed to, copied or used by any third party without the
# prior written consent of Autodesk, Inc.
# =======================================================================
#+

# Copyright 2020 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#------------------------------------------------------------------------------
#
# Gets the Jinja2 and the dependant MarkupSafe python libraries from
Expand Down
3 changes: 1 addition & 2 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# - OS-specific defines
# - Post-commnad for correcting Qt library linking on osx
# - Windows link flags for exporting initializePlugin/uninitializePlugin
macro(MAYA_SET_PLUGIN_PROPERTIES target)
macro(maya_set_plugin_properties target)
set_target_properties(${target} PROPERTIES
SUFFIX ${MAYA_PLUGIN_SUFFIX})

Expand All @@ -56,7 +56,6 @@ macro(MAYA_SET_PLUGIN_PROPERTIES target)
PRIVATE
${_maya_DEFINES}
)

endmacro()
#=============================================================================

Expand Down
6 changes: 1 addition & 5 deletions cmake/usd.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# =======================================================================
# Copyright 2019 Autodesk
# Copyright 2020 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,10 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =======================================================================
#


function(init_usd)
# Adjust PYTHONPATH, PATH
mayaUsd_append_path_to_env_var("PYTHONPATH" "${PXR_USD_LOCATION}/lib/python")
Expand Down
75 changes: 20 additions & 55 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# =======================================================================
# Copyright 2019 Autodesk
# Copyright 2020 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =======================================================================
#

include(CMakeParseArguments)

# The name of the operating system for which CMake is to build
Expand Down Expand Up @@ -150,7 +147,7 @@ function(mayaUsd_install_rpath rpathRef NAME)
endfunction()

function(mayaUsd_promoteMayaUsdHeader)
set(srcFile ${CMAKE_CURRENT_SOURCE_DIR}/base/mayaUsd.h.src)
set(srcFile ${CMAKE_CURRENT_SOURCE_DIR}/mayaUsd.h.src)
set(dstFile ${CMAKE_BINARY_DIR}/include/mayaUsd/mayaUsd.h)
if (NOT EXISTS ${dstFile})
message(STATUS "promoting: " ${srcFile})
Expand All @@ -160,55 +157,21 @@ endfunction()

#
# mayaUsd_promoteHeaderList(
# [SUBDIR <optional sub-directory>])
# [FILES <list of files>]
# [SUBDIR <sub-directory name>]
# [FILES <list of files>]
# [BASEDIR <sub-directory name>])
#
# SUBDIR - sub-directory in which to promote files.
# FILES - list of files to promote.
# BASESDIR - base dirctory where promoted headers are installed into.
# if not defined, mayaUsd subdirectory is used by default.
#
# SUBDIR - optional sub-directory in which to promote files.
# FILES - list of files to promote.
#
function(mayaUsd_promoteHeaderList)
cmake_parse_arguments(PREFIX
"" # options
"SUBDIR" # one_value keywords
"HEADERS" # multi_value keywords
${ARGN}
)

set(DEST_DIR ${CMAKE_BINARY_DIR}/include/mayaUsd)
if(PREFIX_SUBDIR)
set(DEST_DIR ${DEST_DIR}/${PREFIX_SUBDIR})
endif()

if(PREFIX_HEADERS)
set(headerFiles ${PREFIX_HEADERS})
else()
message(FATAL_ERROR "HEADERS keyword is not specified.")
endif()

foreach(header ${headerFiles})
set(srcFile ${CMAKE_CURRENT_SOURCE_DIR}/${header})
set(dstFile ${DEST_DIR}/${header})

set(content "#pragma once\n#include \"${srcFile}\"\n")

if (NOT EXISTS ${dstFile})
message(STATUS "promoting: " ${srcFile})
file(WRITE ${dstFile} "${content}")
else()
file(READ ${dstFile} oldContent)
if (NOT "${content}" STREQUAL "${oldContent}")
message(STATUS "Promoting ${srcfile}")
file(WRITE ${dstFile} "${content}")
endif()
endif()
endforeach()
endfunction()

function(mayaUsd_promoteHeaderListWithSubdir)
cmake_parse_arguments(PREFIX
""
"SUBDIR" # one_value keywords
"HEADERS;BASE_PATH" # multi_value keywords
"HEADERS;BASEDIR" # multi_value keywords
${ARGN}
)

Expand All @@ -218,20 +181,20 @@ function(mayaUsd_promoteHeaderListWithSubdir)
message(FATAL_ERROR "HEADERS keyword is not specified.")
endif()

set(basePath ${CMAKE_BINARY_DIR}/include)
if (PREFIX_BASE_PATH)
set(basePath ${basePath}/${PREFIX_BASE_PATH})
set(baseDir ${CMAKE_BINARY_DIR}/include)
if (PREFIX_BASEDIR)
set(baseDir ${baseDir}/${PREFIX_BASEDIR})
else()
set(basePath ${basePath}/mayaUsd)
set(baseDir ${baseDir}/mayaUsd)
endif()

if (PREFIX_SUBDIR)
set(basePath ${basePath}/${PREFIX_SUBDIR})
set(baseDir ${baseDir}/${PREFIX_SUBDIR})
endif()

foreach(header ${headerFiles})
set(srcFile ${CMAKE_CURRENT_SOURCE_DIR}/${header})
set(dstFile ${basePath}/${header})
set(dstFile ${baseDir}/${header})

set(content "#pragma once\n#include \"${srcFile}\"\n")

Expand Down Expand Up @@ -401,15 +364,17 @@ function(separate_argument_list listName)
endfunction()

# python extension module suffix
function(set_python_module_suffix target)
function(set_python_module_property target)
if(IS_WINDOWS)
set_target_properties(${target}
PROPERTIES
PREFIX ""
SUFFIX ".pyd"
)
elseif(IS_LINUX OR IS_MACOSX)
set_target_properties(${target}
PROPERTIES
PREFIX ""
SUFFIX ".so"
)
endif()
Expand Down
Loading

0 comments on commit e3d4771

Please sign in to comment.