Skip to content

Commit

Permalink
Sync with addfe23
Browse files Browse the repository at this point in the history
  • Loading branch information
qnzhou committed Oct 6, 2021
1 parent 6e2ab99 commit feab1fe
Show file tree
Hide file tree
Showing 129 changed files with 1,582 additions and 1,459 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ LagrangeOptions.cmake

/external
/dist
/scripts/.miniconda3
/scripts/.miniconda3

# CMake user presets
/CMakeUserPresets.json
43 changes: 35 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
endif()

# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.16.0")
set(REQUIRED_CMAKE_VERSION "3.20.0")
if(LAGRANGE_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
else()
Expand All @@ -40,7 +40,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/LagrangeOptions.cmake)
endif()

################################################################################
project(Lagrange VERSION 5.3.0)
project(Lagrange VERSION 5.4.0)

# Detects whether internal libs are available
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/recipes/internal")
Expand All @@ -52,12 +52,27 @@ endif()
# Meta target: ALL includes all optional modules and UI.
option(LAGRANGE_ALL "Build all lagrange modules" OFF)

# When building anorigami module, defaults to using Eigen with MKL-dynamic and TBB-dynamic
# Temporary workaround for Linux-related build issues.
if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux)
# Unfortunately, on CentOS 7, the pre-compiled version of libarpack.so provided by
# anorigami is somehow incompatible with our built-from-source TBB. Indeed, their
# libarpack.so is looking for libtbb.so.2, but our CMake only produces a libtbb.so.
# Until we figure this out, we have to build arpack ourselves from source on CentOS.
option(ARPACK_BUILD_FROM_SOURCE "Build arpack from source using a Fortran compiler" ON)
# Builds are super slow on Linux VM, so we keep the old TBB for now on Linux...
option(LAGRANGE_WITH_ONETBB "Build Lagrange with OneTBB 2021 rather than TBB 2020" OFF)
endif()

# When building anorigami or deformers module, enable Eigen with MKL
if(LAGRANGE_ANORIGAMI OR LAGRANGE_DEFORMERS OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
option(EIGEN_WITH_MKL "Use Eigen with MKL" ON)
endif()

# When building anorigami module, additionally defaults to MKL-dynamic and TBB-dynamic
if(LAGRANGE_ANORIGAMI OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
set(MKL_LINKING "dynamic" CACHE STRING "Linking strategy to use with MKL (static, dynamic or sdl)")
option(EIGEN_WITH_MKL "Use Eigen with MKL" ON)
option(TBB_PREFER_STATIC "Build with static TBB" OFF)
option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON)
option(TBB_PREFER_STATIC "Build with static TBB" OFF)
option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON)
endif()

# When building Arpack from source, we need to enable Fortran support in the top-level directory
Expand All @@ -66,7 +81,6 @@ if(ARPACK_BUILD_FROM_SOURCE)
endif()

# General CMake options
option(LAGRANGE_CI_BUILD "Building for continuous integration" OFF)
option(LAGRANGE_COPY_RUNTIME_DEPS "Copy runtime dependencies into executable folders" ${LAGRANGE_TOPLEVEL_PROJECT})
option(LAGRANGE_DOCUMENTATION "Build Doxygen documentation" OFF)
option(LAGRANGE_EXAMPLES "Build all examples" ${LAGRANGE_TOPLEVEL_PROJECT})
Expand All @@ -76,6 +90,7 @@ option(LAGRANGE_UNIT_TESTS "Build all unit tests"
option(LAGRANGE_USE_PCH "Enable precompiled headers" OFF)
option(LAGRANGE_WITH_ONETBB "Build Lagrange with OneTBB 2021 rather than TBB 2020" ON)
option(LAGRANGE_WITH_TRACY "Build tracy client with Lagrange" OFF)
option(LAGRANGE_LIMIT_PARALLELISM "Limit parallelism according to available cpu/memory" OFF)

# Allowlist/blocklist restricting which modules are allowed in the sub-project. This is an advanced
# option, targeted at users who wish to have explicit knowledge of which module is implicitly
Expand Down Expand Up @@ -112,20 +127,32 @@ else()
endif()
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/lagrange/")

# Lagrange folder prefix for IDE
if(LAGRANGE_TOPLEVEL_PROJECT)
set(LAGRANGE_IDE_PREFIX "")
else()
set(LAGRANGE_IDE_PREFIX "third_party/")
endif()

include(sanitizers)
include(lagrange_add_example)
include(lagrange_add_module)
include(lagrange_add_performance)
include(lagrange_add_test)
include(lagrange_global_flags)
include(lagrange_include_modules)
include(lagrange_install)
include(lagrange_warnings)
include(lagrange_limit_parallelism)
include(sanitizers)

set(CMAKE_MACOSX_RPATH 1) # Set rpath for mac

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(LAGRANGE_LIMIT_PARALLELISM)
lagrange_limit_parallelism()
endif()

find_package(Threads REQUIRED)

# Include OneTBB early to provide TBB::tbb target
Expand Down
10 changes: 5 additions & 5 deletions LagrangeOptions.cmake.sample
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
# option(LAGRANGE_ALL "Build all lagrange modules" ON)

# Optional modules in alphabetical order.
# option(LAGRANGE_FS "Build module lagrange::fs" ON)
# option(LAGRANGE_IO "Build module lagrange::io" ON)
# option(LAGRANGE_UI "Build module lagrange::ui" ON)
# option(LAGRANGE_FS "Build module lagrange::fs" ON)
# option(LAGRANGE_IO "Build module lagrange::io" ON)
# option(LAGRANGE_UI "Build module lagrange::ui" ON)

# UI
# option(LAGRANGE_UI_USE_MDL "Use Material Definition Library" ON)
Expand Down Expand Up @@ -93,7 +93,7 @@
# FetchContent Options
################################################################################

# option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist")
# option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population")
# option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist" ON)
# option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population" ON)
# option(FETCHCONTENT_QUIET "Enables QUIET option for all content population" ON)
# set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps" CACHE PATH "Directory under which to collect all populated content")
2 changes: 1 addition & 1 deletion cmake/lagrange/lagrange_add_example.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(lagrange_add_example name)
lagrange_add_executable(${name} ${ARGN})

# Folder in IDE
set_target_properties(${name} PROPERTIES FOLDER "Lagrange//Examples")
set_target_properties(${name} PROPERTIES FOLDER "${LAGRANGE_IDE_PREFIX}Lagrange//Examples")

# Output directory on disk
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples")
Expand Down
50 changes: 50 additions & 0 deletions cmake/lagrange/lagrange_add_module.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you 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 REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
function(lagrange_add_module)
# Retrieve module name
get_filename_component(module_path "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
get_filename_component(module_name "${module_path}" NAME)

# Retrieve options
set(options INTERFACE)
set(oneValueArgs "")
set(multiValueArgs "")
cmake_parse_arguments(OPTIONS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Define module
if(OPTIONS_INTERFACE)
add_library(lagrange_${module_name} INTERFACE)
set(module_scope INTERFACE)
else()
add_library(lagrange_${module_name})
set(module_scope PUBLIC)
endif()
add_library(lagrange::${module_name} ALIAS lagrange_${module_name})
message(STATUS "Lagrange: creating target 'lagrange::${module_name}'")

include(GNUInstallDirs)
target_include_directories(lagrange_${module_name} ${module_scope}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Target sources
file(GLOB_RECURSE INC_FILES "include/*.h")
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include/" PREFIX "Header Files" FILES ${INC_FILES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src/" PREFIX "Source Files" FILES ${SRC_FILES})
target_sources(lagrange_${module_name} PRIVATE ${INC_FILES} ${SRC_FILES})

# Target folder for IDE
set_target_properties(lagrange_${module_name} PROPERTIES FOLDER "${LAGRANGE_IDE_PREFIX}Lagrange")

endfunction()
2 changes: 1 addition & 1 deletion cmake/lagrange/lagrange_add_performance.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(lagrange_add_performance name)
lagrange_add_executable(${name} ${ARGN})

# Folder in IDE
set_target_properties(${name} PROPERTIES FOLDER "Lagrange//Performance")
set_target_properties(${name} PROPERTIES FOLDER "${LAGRANGE_IDE_PREFIX}Lagrange//Performance")

# Output directory on disk
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/performance")
Expand Down
2 changes: 1 addition & 1 deletion cmake/lagrange/lagrange_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function(lagrange_add_test)
include(lagrange_add_executable)
set(test_target "test_lagrange_${module_name}")
lagrange_add_executable(${test_target} ${SRC_FILES})
set_target_properties(${test_target} PROPERTIES FOLDER "Lagrange//Tests")
set_target_properties(${test_target} PROPERTIES FOLDER "${LAGRANGE_IDE_PREFIX}Lagrange//Tests")

# Dependencies
lagrange_include_modules(testing)
Expand Down
6 changes: 0 additions & 6 deletions cmake/lagrange/lagrange_include_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@ function(lagrange_include_modules)
if(NOT TARGET lagrange::${name})
message(FATAL_ERROR "Failed to create lagrange module: ${name}")
endif()

if(TARGET lagrange_${name}_)
set_target_properties(lagrange_${name}_ PROPERTIES FOLDER "Lagrange")
elseif(TARGET lagrange_${name})
set_target_properties(lagrange_${name} PROPERTIES FOLDER "Lagrange")
endif()
endforeach()
endfunction()
99 changes: 99 additions & 0 deletions cmake/lagrange/lagrange_limit_parallelism.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you 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 REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
function(lagrange_limit_parallelism)
# Query system information
cmake_host_system_information(RESULT NUMBER_OF_PHYSICAL_CORES QUERY NUMBER_OF_PHYSICAL_CORES)
cmake_host_system_information(RESULT AVAILABLE_PHYSICAL_MEMORY QUERY AVAILABLE_PHYSICAL_MEMORY)
cmake_host_system_information(RESULT AVAILABLE_VIRTUAL_MEMORY QUERY AVAILABLE_VIRTUAL_MEMORY)
cmake_host_system_information(RESULT TOTAL_VIRTUAL_MEMORY QUERY TOTAL_VIRTUAL_MEMORY)
cmake_host_system_information(RESULT TOTAL_PHYSICAL_MEMORY QUERY TOTAL_PHYSICAL_MEMORY)

# Peak memory computed "manually" for each platform (in MB)
# Use a hard coded limit of 2 parallel linking jobs
set(max_rss_linux_debug 3000)
set(max_rss_linux_release 2100)
set(max_rss_darwin_debug 729)
set(max_rss_darwin_release 395)
set(max_rss_windows_debug 2100)
set(max_rss_windows_release 1300)

# Use "release" limit only for matching single-config mode
if(GENERATOR_IS_MULTI_CONFIG OR NOT DEFINED CMAKE_BUILD_TYPE)
message(STATUS "Defaulting to debug")
set(_postfix "debug")
else()
string(TOLOWER ${CMAKE_BUILD_TYPE} _type)
if(_type STREQUAL release)
set(_postfix "release")
else()
set(_postfix "debug")
endif()
endif()

string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} _system)

# Use a 3/2 factor safety margin compared to observed memory usage
math(EXPR num_cpu_memory "${AVAILABLE_PHYSICAL_MEMORY} * 3 / 2 / ${max_rss_${_system}_${_postfix}}")

# Compute limits for link/compile steps
set(num_cpu_link 2)
set(num_cpu_compile ${NUMBER_OF_PHYSICAL_CORES})
if(num_cpu_link GREATER num_cpu_memory)
set(num_cpu_link ${num_cpu_memory})
endif()
if(num_cpu_compile GREATER num_cpu_memory)
set(num_cpu_compile ${num_cpu_memory})
endif()

if(CMAKE_SCRIPT_MODE_FILE)
# The message() command, without any mode, will print to stderr. But jenkins only allows us
# to capture stdout. To print a clean message without hyphens, we use cmake's echo command.
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${num_cpu_compile}")
else()
message(STATUS "Parallelism: Available physical memory: ${AVAILABLE_PHYSICAL_MEMORY} / ${TOTAL_PHYSICAL_MEMORY}")
message(STATUS "Parallelism: Available virtual memory: ${AVAILABLE_VIRTUAL_MEMORY} / ${TOTAL_VIRTUAL_MEMORY}")
message(STATUS "Parallelism: Number of physical cores: ${NUMBER_OF_PHYSICAL_CORES}")
message(STATUS "Parallelism: Limiting link pool to ${num_cpu_link}")
message(STATUS "Parallelism: Limiting compile pool to ${num_cpu_compile}")
endif()

# Limit parallelism based on number of physical cores + available memory.
set_property(GLOBAL PROPERTY JOB_POOLS
pool-link=${num_cpu_link}
pool-compile=${num_cpu_compile}
pool-precompile-header=${num_cpu_compile}
)
set(CMAKE_JOB_POOL_LINK "pool-link" CACHE STRING "Job pool for linking" FORCE)
set(CMAKE_JOB_POOL_COMPILE "pool-compile" CACHE STRING "Job pool for compiling" FORCE)
set(CMAKE_JOB_POOL_PRECOMPILE_HEADER "pool-precompile-header" CACHE STRING "Job pool for generating pre-compiled headers" FORCE)

# Note: We cannot set directly CMAKE_BUILD_PARALLEL_LEVEL or CTEST_PARALLEL_LEVEL from this CMake file,
# since those are environment variables [1]: they are not cached and do not affect subsequent CMake calls.
# In practice, the parallelism for Ninja should be limited by our job pools, so the only thing we need is
# to run ctest in parallel.
# [1]: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-environment-variables
endfunction()

# If this file is run in script mode, calling this function will simply echo the total number of
# cores that we desire to build/test with.
if(CMAKE_SCRIPT_MODE_FILE)
if(DEFINED CMAKE_ARGV3)
# We need to extract build type from preset
execute_process(COMMAND ${CMAKE_COMMAND} --preset ${CMAKE_ARGV3} -N OUTPUT_VARIABLE output_log COMMAND_ERROR_IS_FATAL ANY)
if(output_log MATCHES "CMAKE_BUILD_TYPE=\"([a-zA-Z]+)\"")
set(CMAKE_BUILD_TYPE ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Could not find CMAKE_BUILD_TYPE from preset")
endif()
endif()
lagrange_limit_parallelism()
endif()
24 changes: 15 additions & 9 deletions cmake/lagrange/lagrange_runtime_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ function(lagrange_get_dependencies_recursive OUTPUT_VARIABLE TARGET)

get_target_property(_IMPORTED ${TARGET} IMPORTED)
get_target_property(_TYPE ${TARGET} TYPE)
if(_IMPORTED OR (${_TYPE} STREQUAL "INTERFACE_LIBRARY"))
get_target_property(TARGET_DEPENDENCIES ${TARGET} INTERFACE_LINK_LIBRARIES)
else()
get_target_property(TARGET_DEPENDENCIES ${TARGET} LINK_LIBRARIES)
endif()

# MKL-specific list of runtime dependencies
get_property(RUNTIME_DEPENDENCIES TARGET ${TARGET} PROPERTY mkl_RUNTIME_DEPENDENCIES)
if(RUNTIME_DEPENDENCIES)
list(APPEND TARGET_DEPENDENCIES ${RUNTIME_DEPENDENCIES})
# List both public and private dependencies, regardless of target type
unset(TARGET_DEPENDENCIES)
set(properties
INTERFACE_LINK_LIBRARIES
mkl_RUNTIME_DEPENDENCIES # MKL-specific list of runtime dependencies
)
if(NOT ${_TYPE} STREQUAL "INTERFACE_LIBRARY")
list(APPEND properties LINK_LIBRARIES)
endif()
foreach(property IN ITEMS ${properties})
get_target_property(deps ${TARGET} ${property})
if(deps)
list(APPEND TARGET_DEPENDENCIES ${deps})
endif()
endforeach()
list(REMOVE_DUPLICATES TARGET_DEPENDENCIES)

set(VISITED_TARGETS ${${OUTPUT_VARIABLE}})
foreach(DEPENDENCY IN ITEMS ${TARGET_DEPENDENCIES})
Expand Down
6 changes: 6 additions & 0 deletions cmake/recipes/external/boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ${OLD_CMAKE_POSITION_INDEPENDENT_CODE})
set(CMAKE_CXX_FLAGS "${PREVIOUS_CMAKE_CXX_FLAGS}")

foreach(name IN ITEMS chrono container iostreams system thread timer)
if(TARGET Boost_${name})
set_target_properties(Boost_${name} PROPERTIES FOLDER third_party/boost)
endif()
endforeach()
2 changes: 1 addition & 1 deletion cmake/recipes/external/eigen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ else()
include(FetchContent)
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_REPOSITORY https://github.com/libigl/eigen-git-mirror.git
GIT_TAG tags/3.3.7
GIT_SHALLOW TRUE
)
Expand Down
2 changes: 2 additions & 0 deletions cmake/recipes/external/ilmbase.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ target_include_directories(IlmBase_Half PUBLIC
)

target_compile_features(IlmBase_Half PUBLIC cxx_std_14)

set_target_properties(IlmBase_Half PROPERTIES FOLDER third_party)
Loading

0 comments on commit feab1fe

Please sign in to comment.