From e474cb7f671d796179fa73378598959ad01bdc49 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 24 Oct 2021 15:47:17 +0200 Subject: [PATCH 01/13] Added CMake variables for optimization and architecture-specific options --- CMakeLists.txt | 58 ++++++++++++++++++++++++++++++ cmake/compiler.cmake | 2 ++ cmake/ports/bullet3/portfile.cmake | 26 +++++++++++++- cmake/ports/opus/portfile.cmake | 28 ++++++++++++++- 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8abcce4489..820ba2aa32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,64 @@ 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 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 flags") + set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + message("GCC compiler detected, adding -O3 -fPIC flags") + set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message("MSVC compiler detected, adding /O2 flag") + set(VIRCADIA_OPTIMIZE_FLAGS "/O2") + 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}) + 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} diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index 45cef27727..5108253403 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -110,3 +110,5 @@ if (APPLE) set(CMAKE_OSX_SYSROOT ${_OSX_DESIRED_SDK_PATH}/MacOSX${OSX_SDK}.sdk) endif () endif () + +message("CXXFLAGS: ${CXXFLAGS}") diff --git a/cmake/ports/bullet3/portfile.cmake b/cmake/ports/bullet3/portfile.cmake index cda39ed349..8fc34179b6 100644 --- a/cmake/ports/bullet3/portfile.cmake +++ b/cmake/ports/bullet3/portfile.cmake @@ -15,6 +15,14 @@ include(vcpkg_common_functions) +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 (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) message(WARNING "Dynamic not supported, building static") set(VCPKG_LIBRARY_LINKAGE static) @@ -30,6 +38,21 @@ vcpkg_from_github( PATCHES "bullet-git-fix-build-clang-8.patch" ) + +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() + +message("Optimization options for Bullet: ${VIRCADIA_BULLET_OPTIONS}") + vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} OPTIONS @@ -46,6 +69,7 @@ vcpkg_configure_cmake( -DBUILD_UNIT_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DINSTALL_LIBS=ON + ${VIRCADIA_BULLET_OPTIONS} ) vcpkg_install_cmake() @@ -58,4 +82,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) \ No newline at end of file +file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/bullet3 RENAME copyright) diff --git a/cmake/ports/opus/portfile.cmake b/cmake/ports/opus/portfile.cmake index e5518351f8..238f481690 100644 --- a/cmake/ports/opus/portfile.cmake +++ b/cmake/ports/opus/portfile.cmake @@ -1,5 +1,12 @@ include(vcpkg_common_functions) +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() + vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH @@ -12,7 +19,26 @@ vcpkg_from_github( HEAD_REF master) -vcpkg_configure_cmake(SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA) +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() + +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() From fc3177a23cab74880b497f6cfd134af670bfaa44 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 24 Oct 2021 18:06:45 +0200 Subject: [PATCH 02/13] Disabled optimization settings on Windows because they were breaking the build --- CMakeLists.txt | 78 +++++++++++++++--------------- cmake/ports/bullet3/portfile.cmake | 34 +++++++------ cmake/ports/opus/portfile.cmake | 32 ++++++------ 3 files changed, 77 insertions(+), 67 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 820ba2aa32..681b391110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,52 +84,54 @@ if(NOT DEFINED VIRCADIA_OPTIMIZE) 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) +if( NOT WIN32 ) + #compiler needs to be detected before building VCPKG dependencies + set(CMAKE_PLATFORM_INFO_DIR "${CMAKE_CURRENT_BINARY_DIR}") + include(CMakeDetermineCXXCompiler) -set(VIRCADIA_OPTIMIZE_FLAGS "") + 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 flags") - set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - message("GCC compiler detected, adding -O3 -fPIC flags") - set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - message("MSVC compiler detected, adding /O2 flag") - set(VIRCADIA_OPTIMIZE_FLAGS "/O2") + set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + 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 flags") + elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + message("GCC compiler detected, adding -O3 -fPIC flags") + set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + else() + message("No predefined optimization flags for compiler ${CMAKE_CXX_COMPILER_ID}") + endif() endif() -endif() -MESSAGE(STATUS "VIRCADIA_OPTIMIZE: ${VIRCADIA_OPTIMIZE}") + 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 + # 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") + #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}") 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}) if (HIFI_ANDROID) diff --git a/cmake/ports/bullet3/portfile.cmake b/cmake/ports/bullet3/portfile.cmake index 8fc34179b6..ab27c8494d 100644 --- a/cmake/ports/bullet3/portfile.cmake +++ b/cmake/ports/bullet3/portfile.cmake @@ -15,13 +15,6 @@ include(vcpkg_common_functions) -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 (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) message(WARNING "Dynamic not supported, building static") @@ -38,17 +31,28 @@ vcpkg_from_github( PATCHES "bullet-git-fix-build-clang-8.patch" ) - -if(VIRCADIA_OPTIMIZE) - set(VIRCADIA_BULLET_OPTIONS "-DCMAKE_BUILD_TYPE=Release") +if(WIN32) + set(VIRCADIA_BULLET_OPTIONS "") else() - set(VIRCADIA_BULLET_OPTIONS "-DCMAKE_BUILD_TYPE=RelWithDebInfo") -endif() + 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() -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}\" ") + 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}") diff --git a/cmake/ports/opus/portfile.cmake b/cmake/ports/opus/portfile.cmake index 238f481690..6406cf10c0 100644 --- a/cmake/ports/opus/portfile.cmake +++ b/cmake/ports/opus/portfile.cmake @@ -1,12 +1,5 @@ include(vcpkg_common_functions) -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() - vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH @@ -19,16 +12,27 @@ vcpkg_from_github( HEAD_REF master) -if(VIRCADIA_OPTIMIZE) - set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=Release") +if(WIN32) + set(VIRCADIA_BULLET_OPTIONS "") else() - set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=RelWithDebInfo") -endif() + 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() -set(VIRCADIA_OPUS_OPTIONS "${VIRCADIA_OPUS_OPTIONS}") + if(VIRCADIA_OPTIMIZE) + set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=Release") + else() + set(VIRCADIA_OPUS_OPTIONS "-DCMAKE_BUILD_TYPE=RelWithDebInfo") + endif() -if(DEFINED VIRCADIA_CPU_ARCHITECTURE) - set(VIRCADIA_OPUS_OPTIONS "${VIRCADIA_OPUS_OPTIONS} -DCMAKE_CXX_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" -DCMAKE_C_FLAGS=\"${VIRCADIA_CPU_ARCHITECTURE}\" ") + 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}") From 79386b409ea54f9ff651c3d907a2bac2fadc9af9 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 24 Oct 2021 18:39:42 +0200 Subject: [PATCH 03/13] Fixed typo in Opus portfile.cmake --- cmake/ports/opus/portfile.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ports/opus/portfile.cmake b/cmake/ports/opus/portfile.cmake index 6406cf10c0..988096ad62 100644 --- a/cmake/ports/opus/portfile.cmake +++ b/cmake/ports/opus/portfile.cmake @@ -13,7 +13,7 @@ vcpkg_from_github( master) if(WIN32) - set(VIRCADIA_BULLET_OPTIONS "") + 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) From fe29b36b443c7136c2b87119d6eacb1161689d90 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 24 Oct 2021 20:34:55 +0200 Subject: [PATCH 04/13] Fixed CMake error when there's no CXXFLAGS environment variable --- CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 681b391110..53caf10783 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,12 +79,12 @@ endif() # 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 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() - 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) @@ -130,9 +130,10 @@ if( NOT WIN32 ) set(ENV{CXXFLAGS} "$ENV{CXXFLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}") set(ENV{CFLAGS} "$ENV{CFLAGS} ${VIRCADIA_OPTIMIZE_FLAGS}") + message($ENV{CXXFLAGS}) endif() -message($ENV{CXXFLAGS}) + if (HIFI_ANDROID) execute_process( From 124f4b5e83251c055613d47049946acf5e87f4ec Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 14:55:48 +0200 Subject: [PATCH 05/13] Removed unnecessary line in CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53caf10783..20354b7a6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,6 @@ if( NOT WIN32 ) set(VIRCADIA_OPTIMIZE_FLAGS "") - set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") if(VIRCADIA_OPTIMIZE) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_env/VIRCADIA_OPTIMIZE.txt" "${VIRCADIA_OPTIMIZE}") From ac984d5e061afc58f79fdb04a0b826f77d518ff3 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 15:08:52 +0200 Subject: [PATCH 06/13] Added information about optimization variables --- BUILD.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BUILD.md b/BUILD.md index 82da773f08..68baa8558a 100644 --- a/BUILD.md +++ b/BUILD.md @@ -192,6 +192,11 @@ 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". + ### Developer Build Options * USE_GLES From a31350678f679429f3d427ff2f19f6cf5cbc80c5 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 15:15:28 +0200 Subject: [PATCH 07/13] Added CPU architecture variable info to BUILD_LINUX.md --- BUILD_LINUX.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BUILD_LINUX.md b/BUILD_LINUX.md index 1996360fed..8b058a1efb 100644 --- a/BUILD_LINUX.md +++ b/BUILD_LINUX.md @@ -171,3 +171,9 @@ 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". From 6394dc8662de8f03b605c334120a28966cd68f84 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 15:16:32 +0200 Subject: [PATCH 08/13] Update BUILD_LINUX.md --- BUILD_LINUX.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BUILD_LINUX.md b/BUILD_LINUX.md index 8b058a1efb..04d8e8b63b 100644 --- a/BUILD_LINUX.md +++ b/BUILD_LINUX.md @@ -172,8 +172,8 @@ 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 +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 +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". +For packaging and AppImage it is recommended to set it to different value, for example `-msse3`. From f2e4c4daa2679bd22185e2301f14dd514200e1f2 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 15:17:49 +0200 Subject: [PATCH 09/13] Update BUILD_OSX.md --- BUILD_OSX.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BUILD_OSX.md b/BUILD_OSX.md index ee14b3b24e..e1fb030e39 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -64,6 +64,14 @@ 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`. + ## FAQ 1. **Problem:** Running the scheme `interface.app` from Xcode causes a crash for Interface related to `libgl`. From afae963031f15fcaee65e18a6b1f5cb8a0c8bfd2 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sat, 30 Oct 2021 15:18:48 +0200 Subject: [PATCH 10/13] Update BUILD.md --- BUILD.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.md b/BUILD.md index 68baa8558a..469d934b95 100644 --- a/BUILD.md +++ b/BUILD.md @@ -195,7 +195,7 @@ The following build options can be used when running CMake ### 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". +* 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`. ### Developer Build Options From 8f286205eb2cde78230abcfefc266b4310f6ef54 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 31 Oct 2021 13:45:40 +0100 Subject: [PATCH 11/13] Added empty CPU architecture variable to Github builds to ensure compatibility --- .github/workflows/master_build.yml | 4 ++-- .github/workflows/pr_build.yml | 8 ++++---- BUILD.md | 4 +++- BUILD_LINUX.md | 2 ++ BUILD_OSX.md | 2 ++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/master_build.yml b/.github/workflows/master_build.yml index 8d9844e03c..c4be9234cc 100644 --- a/.github/workflows/master_build.yml +++ b/.github/workflows/master_build.yml @@ -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 diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index 9bd3f7fb12..3addace0b7 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -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 diff --git a/BUILD.md b/BUILD.md index 469d934b95..fd30b124eb 100644 --- a/BUILD.md +++ b/BUILD.md @@ -195,7 +195,9 @@ The following build options can be used when running CMake ### 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`. +* 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 diff --git a/BUILD_LINUX.md b/BUILD_LINUX.md index 04d8e8b63b..ae0a88a98e 100644 --- a/BUILD_LINUX.md +++ b/BUILD_LINUX.md @@ -177,3 +177,5 @@ 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. diff --git a/BUILD_OSX.md b/BUILD_OSX.md index e1fb030e39..03106b9354 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -71,6 +71,8 @@ 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 From 9221d33ed29a637f9879a2b293b96c9b37202345 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 31 Oct 2021 19:59:48 +0100 Subject: [PATCH 12/13] Fixed build flags for MacOS --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20354b7a6c..160e39ae5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,7 @@ if( NOT WIN32 ) 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 flags") + set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") message("GCC compiler detected, adding -O3 -fPIC flags") set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") From a94541d7e908d87c55d5fa338386dd3b6e707d9b Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Mon, 1 Nov 2021 13:15:45 +0100 Subject: [PATCH 13/13] Added debug flags --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 160e39ae5a..aaafe2b3fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,11 +95,11 @@ if( NOT WIN32 ) 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 flags") - set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + 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 flags") - set(VIRCADIA_OPTIMIZE_FLAGS "-O3 -fPIC") + 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()