mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-05 23:42:58 +02:00
Merge pull request #1424 from ksuprynowicz/new_compiler_flags
Increase performance on macOS and Linux with CMake variables for optimization and architecture-specific options.
This commit is contained in:
commit
db08a6322b
9 changed files with 154 additions and 8 deletions
4
.github/workflows/master_build.yml
vendored
4
.github/workflows/master_build.yml
vendored
|
@ -56,7 +56,7 @@ jobs:
|
|||
echo "PYTHON_EXEC=python3" >> $GITHUB_ENV
|
||||
echo "INSTALLER_EXT=tgz" >> $GITHUB_ENV
|
||||
echo "CMAKE_BUILD_EXTRA=-- -j3" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
fi
|
||||
# Mac build variables
|
||||
if [ "${{ matrix.os }}" = "macOS-10.15" ]; then
|
||||
|
@ -64,7 +64,7 @@ jobs:
|
|||
echo "ZIP_COMMAND=zip" >> $GITHUB_ENV
|
||||
echo "ZIP_ARGS=-r" >> $GITHUB_ENV
|
||||
echo "INSTALLER_EXT=dmg" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
echo "::set-output name=symbols_archive::${BUILD_NUMBER}-${{ matrix.build_type }}-mac-symbols.zip"
|
||||
echo "APP_TARGET_NAME=Vircadia" >> $GITHUB_ENV
|
||||
fi
|
||||
|
|
8
.github/workflows/pr_build.yml
vendored
8
.github/workflows/pr_build.yml
vendored
|
@ -75,9 +75,9 @@ jobs:
|
|||
echo "VCPKG_FORCE_SYSTEM_BINARIES=true" >> $GITHUB_ENV
|
||||
fi
|
||||
if [ "${{ matrix.build_type }}" = "full" ]; then
|
||||
echo "CMAKE_EXTRA=-DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CMAKE_EXTRA=-DCLIENT_ONLY=1 -DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DCLIENT_ONLY=1 -DBUILD_TOOLS:BOOLEAN=FALSE -DHIFI_PYTHON_EXEC:FILEPATH=$(which python3)" >> $GITHUB_ENV
|
||||
fi
|
||||
fi
|
||||
# Mac build variables
|
||||
|
@ -85,9 +85,9 @@ jobs:
|
|||
echo "PYTHON_EXEC=python3" >> $GITHUB_ENV
|
||||
echo "INSTALLER_EXT=dmg" >> $GITHUB_ENV
|
||||
if [ "${{ matrix.build_type }}" = "full" ]; then
|
||||
echo "CMAKE_EXTRA=-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CMAKE_EXTRA=-DCLIENT_ONLY=1 -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
echo "CMAKE_EXTRA=-DVIRCADIA_CPU_ARCHITECTURE= -DCLIENT_ONLY=1 -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -G Xcode" >> $GITHUB_ENV
|
||||
fi
|
||||
echo "APP_TARGET_NAME=Vircadia" >> $GITHUB_ENV
|
||||
fi
|
||||
|
|
7
BUILD.md
7
BUILD.md
|
@ -192,6 +192,13 @@ The following build options can be used when running CMake
|
|||
* CLIENT_ONLY // Will package only the Interface
|
||||
* SERVER_ONLY // Will package only the Server
|
||||
|
||||
### Optimization build options
|
||||
|
||||
* VIRCADIA_OPTIMIZE - This variable defaults to 1 if not set and enables compiler optimization flags on Linux and MacOS. Setting it to 0 will result in unoptimized build.
|
||||
* VIRCADIA_CPU_ARCHITECTURE - This variable contains architecture specific compiler flags which are used if `VIRCADIA_OPTIMIZE` is true. If it is not set, it defaults to `-march=native -mtune=native`, which helps yield more performance for locally used build, but for packaging it needs to be set to different value for portability, for example `-msse3`. Setting `VIRCADIA_CPU_ARCHITECTURE` to empty string will use default compiler settings and yield
|
||||
maximum compatibility.
|
||||
|
||||
|
||||
### Developer Build Options
|
||||
|
||||
* USE_GLES
|
||||
|
|
|
@ -171,3 +171,11 @@ If your goal is to set up a development environment, it is desirable to set the
|
|||
directory that vcpkg builds into with the `HIFI_VCPKG_BASE` environment variable.
|
||||
For example, you might set `HIFI_VCPKG_BASE` to `/home/$USER/vcpkg`.
|
||||
By default, vcpkg will build in the system `/tmp` directory.
|
||||
|
||||
If build is intended for packaging or creation of AppImage, `VIRCADIA_CPU_ARCHITECTURE`
|
||||
CMake variable needs to be set to architecture specific value.
|
||||
It defaults to `-march=native -mtune=native`, which yields builds optimized for particular
|
||||
machine, but builds will not work on machines lacking same CPU instructions.
|
||||
For packaging and AppImage it is recommended to set it to different value, for example `-msse3`.
|
||||
Setting `VIRCADIA_CPU_ARCHITECTURE` to empty string will use default compiler settings and yield
|
||||
maximum compatibility.
|
||||
|
|
10
BUILD_OSX.md
10
BUILD_OSX.md
|
@ -64,6 +64,16 @@ You can append `-j4` to assign more threads to build with. The number indicates
|
|||
|
||||
To package the installation, you can simply run `make package` afterwards.
|
||||
|
||||
## Notes
|
||||
|
||||
If build is intended for packaging or creation of AppImage, `VIRCADIA_CPU_ARCHITECTURE`
|
||||
CMake variable needs to be set to architecture specific value.
|
||||
It defaults to `-march=native -mtune=native`, which yields builds optimized for particular
|
||||
machine, but builds will not work on machines lacking same CPU instructions.
|
||||
For packaging and AppImage it is recommended to set it to different value, for example `-msse3`.
|
||||
Setting `VIRCADIA_CPU_ARCHITECTURE` to empty string will use default compiler settings and yield
|
||||
maximum compatibility.
|
||||
|
||||
## FAQ
|
||||
|
||||
1. **Problem:** Running the scheme `interface.app` from Xcode causes a crash for Interface related to `libgl`.
|
||||
|
|
|
@ -74,6 +74,67 @@ if ((NOT "${RELEASE_TYPE}" STREQUAL "PRODUCTION") AND (NOT "${RELEASE_TYPE}" STR
|
|||
set(RELEASE_TYPE "DEV")
|
||||
endif()
|
||||
|
||||
# VIRCADIA_OPTIMIZE
|
||||
# Variable determining vircadia optimization. If not set, it defaults to true.
|
||||
# It's used to determine build flags for main codebase and for VCPKG dependencies.
|
||||
# Should be set to false to get completely unoptimized build for easier line-by-line debugging
|
||||
|
||||
if( NOT WIN32 )
|
||||
if(NOT DEFINED VIRCADIA_OPTIMIZE)
|
||||
message("Enabling code optimization for Vircadia and compiled dependencies")
|
||||
set(VIRCADIA_OPTIMIZE true CACHE BOOL "Enable code optimization for Vircadia and compiled dependencies")
|
||||
endif()
|
||||
|
||||
#compiler needs to be detected before building VCPKG dependencies
|
||||
set(CMAKE_PLATFORM_INFO_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include(CMakeDetermineCXXCompiler)
|
||||
|
||||
set(VIRCADIA_OPTIMIZE_FLAGS "")
|
||||
|
||||
if(VIRCADIA_OPTIMIZE)
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_env/VIRCADIA_OPTIMIZE.txt" "${VIRCADIA_OPTIMIZE}")
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message("Clang compiler detected, adding -O3 -fPIC -g flags")
|
||||
set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC -g")
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message("GCC compiler detected, adding -O3 -fPIC -ggdb flags")
|
||||
set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC -ggdb")
|
||||
else()
|
||||
message("No predefined optimization flags for compiler ${CMAKE_CXX_COMPILER_ID}")
|
||||
endif()
|
||||
endif()
|
||||
MESSAGE(STATUS "VIRCADIA_OPTIMIZE: ${VIRCADIA_OPTIMIZE}")
|
||||
|
||||
# VIRCADIA_CPU_ARCHITECTURE
|
||||
# Variable determining CPU architecture for which Vircadia will be built.
|
||||
# If defined, it's appended to CXXFLAGS and CFLAGS for both Vircadia and VCPKG dependencies
|
||||
|
||||
#Assume -march=native for compilers that allow it if architecture is not specified
|
||||
if(NOT DEFINED VIRCADIA_CPU_ARCHITECTURE)
|
||||
if(VIRCADIA_OPTIMIZE AND ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU") ) )
|
||||
message("Optimization is enabled, but architecture is not specified. Assuming native build")
|
||||
set(VIRCADIA_CPU_ARCHITECTURE "-march=native -mtune=native" CACHE STRING "Specify architecture dependent compiler flags here")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED VIRCADIA_CPU_ARCHITECTURE)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_env/VIRCADIA_CPU_ARCHITECTURE.txt" "${VIRCADIA_CPU_ARCHITECTURE}")
|
||||
set(VIRCADIA_OPTIMIZE_FLAGS "${VIRCADIA_OPTIMIZE_FLAGS} ${VIRCADIA_CPU_ARCHITECTURE}")
|
||||
message("Adding CPU architecture flags: ${VIRCADIA_CPU_ARCHITECTURE}")
|
||||
MESSAGE(STATUS "VIRCADIA_CPU_ARCHITECTURE: ${VIRCADIA_CPU_ARCHITECTURE}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}")
|
||||
|
||||
set(ENV{CXXFLAGS} "$ENV{CXXFLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}")
|
||||
set(ENV{CFLAGS} "$ENV{CFLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}")
|
||||
message($ENV{CXXFLAGS})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if (HIFI_ANDROID)
|
||||
execute_process(
|
||||
COMMAND ${HIFI_PYTHON_EXEC} ${CMAKE_CURRENT_SOURCE_DIR}/prebuild.py --release-type ${RELEASE_TYPE} --android ${HIFI_ANDROID_APP} --build-root ${CMAKE_BINARY_DIR}
|
||||
|
|
|
@ -110,3 +110,5 @@ if (APPLE)
|
|||
set(CMAKE_OSX_SYSROOT ${_OSX_DESIRED_SDK_PATH}/MacOSX${OSX_SDK}.sdk)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
message("CXXFLAGS: ${CXXFLAGS}")
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
include(vcpkg_common_functions)
|
||||
|
||||
|
||||
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
||||
message(WARNING "Dynamic not supported, building static")
|
||||
set(VCPKG_LIBRARY_LINKAGE static)
|
||||
|
@ -30,6 +31,32 @@ vcpkg_from_github(
|
|||
PATCHES "bullet-git-fix-build-clang-8.patch"
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(VIRCADIA_BULLET_OPTIONS "")
|
||||
else()
|
||||
if(EXISTS "${VCPKG_ROOT_DIR}/_env/VIRCADIA_OPTIMIZE.txt")
|
||||
file(READ "${VCPKG_ROOT_DIR}/_env/VIRCADIA_OPTIMIZE.txt" VIRCADIA_OPTIMIZE)
|
||||
endif()
|
||||
if(EXISTS "${VCPKG_ROOT_DIR}/_env/VIRCADIA_CPU_ARCHITECTURE.txt")
|
||||
file(READ "${VCPKG_ROOT_DIR}/_env/VIRCADIA_CPU_ARCHITECTURE.txt" VIRCADIA_CPU_ARCHITECTURE)
|
||||
endif()
|
||||
|
||||
|
||||
if(VIRCADIA_OPTIMIZE)
|
||||
set(VIRCADIA_BULLET_OPTIONS "-DCMAKE_BUILD_TYPE=Release")
|
||||
else()
|
||||
set(VIRCADIA_BULLET_OPTIONS "-DCMAKE_BUILD_TYPE=RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
set(VIRCADIA_BULLET_OPTIONS "${VIRCADIA_BULLET_OPTIONS}")
|
||||
|
||||
if(DEFINED VIRCADIA_CPU_ARCHITECTURE)
|
||||
set(VIRCADIA_BULLET_OPTIONS "${VIRCADIA_BULLET_OPTIONS} -DCMAKE_CXX_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" -DCMAKE_C_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message("Optimization options for Bullet: ${VIRCADIA_BULLET_OPTIONS}")
|
||||
|
||||
vcpkg_configure_cmake(
|
||||
SOURCE_PATH ${SOURCE_PATH}
|
||||
OPTIONS
|
||||
|
@ -46,6 +73,7 @@ vcpkg_configure_cmake(
|
|||
-DBUILD_UNIT_TESTS=OFF
|
||||
-DBUILD_SHARED_LIBS=ON
|
||||
-DINSTALL_LIBS=ON
|
||||
${VIRCADIA_BULLET_OPTIONS}
|
||||
)
|
||||
|
||||
vcpkg_install_cmake()
|
||||
|
@ -58,4 +86,4 @@ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/include/bullet/BulletInverseDynamics
|
|||
vcpkg_copy_pdbs()
|
||||
|
||||
# Handle copyright
|
||||
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/bullet3 RENAME copyright)
|
||||
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/bullet3 RENAME copyright)
|
||||
|
|
|
@ -12,7 +12,37 @@ vcpkg_from_github(
|
|||
HEAD_REF
|
||||
master)
|
||||
|
||||
vcpkg_configure_cmake(SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA)
|
||||
if(WIN32)
|
||||
set(VIRCADIA_OPUS_OPTIONS "")
|
||||
else()
|
||||
if(EXISTS "${VCPKG_ROOT_DIR}/_env/VIRCADIA_OPTIMIZE.txt")
|
||||
file(READ "${VCPKG_ROOT_DIR}/_env/VIRCADIA_OPTIMIZE.txt" VIRCADIA_OPTIMIZE)
|
||||
endif()
|
||||
if(EXISTS "${VCPKG_ROOT_DIR}/_env/VIRCADIA_CPU_ARCHITECTURE.txt")
|
||||
file(READ "${VCPKG_ROOT_DIR}/_env/VIRCADIA_CPU_ARCHITECTURE.txt" VIRCADIA_CPU_ARCHITECTURE)
|
||||
endif()
|
||||
|
||||
if(VIRCADIA_OPTIMIZE)
|
||||
set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=Release")
|
||||
else()
|
||||
set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
set(VIRCADIA_OPUS_OPTIONS "${VIRCADIA_OPUS_OPTIONS}")
|
||||
|
||||
if(DEFINED VIRCADIA_CPU_ARCHITECTURE)
|
||||
set(VIRCADIA_OPUS_OPTIONS "${VIRCADIA_OPUS_OPTIONS} -DCMAKE_CXX_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" -DCMAKE_C_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message("Optimization options for Opus: ${VIRCADIA_OPUS_OPTIONS}")
|
||||
|
||||
vcpkg_configure_cmake(
|
||||
SOURCE_PATH ${SOURCE_PATH}
|
||||
PREFER_NINJA
|
||||
OPTIONS ${VIRCADIA_OPUS_OPTIONS}
|
||||
)
|
||||
|
||||
vcpkg_install_cmake()
|
||||
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/Opus)
|
||||
vcpkg_copy_pdbs()
|
||||
|
|
Loading…
Reference in a new issue