rpcs3/buildfiles/cmake/ConfigureCompiler.cmake

123 lines
4.1 KiB
CMake
Raw Normal View History

# Check and configure compiler options for RPCS3
2019-06-23 05:54:42 +00:00
if(MSVC)
add_compile_options(/Zc:throwingNew- /constexpr:steps16777216)
add_compile_definitions(
_CRT_SECURE_NO_DEPRECATE=1 _CRT_NON_CONFORMING_SWPRINTFS=1 _SCL_SECURE_NO_WARNINGS=1
NOMINMAX _ENABLE_EXTENDED_ALIGNED_STORAGE=1 _HAS_EXCEPTIONS=0)
add_link_options(/DYNAMICBASE:NO /BASE:0x10000 /FIXED)
#TODO: Some of these could be cleaned up
add_compile_options(/wd4805) # Comparing boolean and int
add_compile_options(/wd4804) # Using integer operators with booleans
add_compile_options(/wd4200) # Zero-sized array in struct/union
add_link_options(/ignore:4281) # Undesirable base address 0x10000
# MSVC 2017 uses iterator as base class internally, causing a lot of warning spam
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING=1)
2019-06-23 05:54:42 +00:00
# Increase stack limit to 8 MB
add_link_options(/STACK:8388608,1048576)
2019-06-23 05:54:42 +00:00
else()
# Some distros have the compilers set to use PIE by default, but RPCS3 doesn't work with PIE, so we need to disable it.
check_cxx_compiler_flag("-no-pie" HAS_NO_PIE)
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
check_cxx_compiler_flag("-msse -msse2 -mcx16" COMPILER_X86)
if (APPLE)
check_cxx_compiler_flag("-march=armv8.4-a" COMPILER_ARM)
else()
check_cxx_compiler_flag("-march=armv8.1-a" COMPILER_ARM)
endif()
2019-05-10 17:24:14 +00:00
add_compile_options(-Wall)
add_compile_options(-fno-exceptions)
2021-02-08 15:47:03 +00:00
add_compile_options(-fstack-protector)
if (COMPILER_X86)
add_compile_options(-msse -msse2 -mcx16)
endif()
if (COMPILER_ARM)
if (APPLE)
add_compile_options(-march=armv8.4-a)
else()
add_compile_options(-march=armv8.1-a)
endif()
endif()
2019-12-04 20:56:19 +00:00
add_compile_options(-Werror=old-style-cast)
add_compile_options(-Werror=sign-compare)
add_compile_options(-Werror=reorder)
add_compile_options(-Werror=return-type)
add_compile_options(-Werror=overloaded-virtual)
add_compile_options(-Werror=missing-noreturn)
2021-03-05 19:05:37 +00:00
add_compile_options(-Wunused-parameter)
add_compile_options(-Wignored-qualifiers)
2021-03-21 15:02:21 +00:00
add_compile_options(-Wredundant-move)
add_compile_options(-Wcast-qual)
add_compile_options(-Wdeprecated-copy)
2021-03-13 20:01:37 +00:00
add_compile_options(-Wtautological-compare)
#add_compile_options(-Wshadow)
#add_compile_options(-Wconversion)
#add_compile_options(-Wpadded)
add_compile_options(-Wempty-body)
2021-03-23 19:32:50 +00:00
add_compile_options(-Wredundant-decls)
2021-04-19 08:11:24 +00:00
#add_compile_options(-Weffc++)
add_compile_options(-Wstrict-aliasing=1)
2021-03-01 12:03:00 +00:00
#add_compile_options(-Wnull-dereference)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Werror=inconsistent-missing-override)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Werror=suggest-override)
add_compile_options(-Wclobbered)
# add_compile_options(-Wcast-function-type)
2021-03-13 15:03:08 +00:00
add_compile_options(-Wduplicated-branches)
2021-03-13 15:46:59 +00:00
add_compile_options(-Wduplicated-cond)
endif()
2019-06-23 05:54:42 +00:00
#TODO Clean the code so these are removed
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-fconstexpr-steps=16777216)
2019-06-23 05:54:42 +00:00
add_compile_options(-Wno-unused-lambda-capture)
add_compile_options(-Wno-unused-private-field)
add_compile_options(-Wno-delete-non-virtual-dtor)
add_compile_options(-Wno-unused-command-line-argument)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2019-06-23 05:54:42 +00:00
add_compile_options(-Wno-class-memaccess)
endif()
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
2019-06-23 05:54:42 +00:00
if(USE_NATIVE_INSTRUCTIONS AND COMPILER_SUPPORTS_MARCH_NATIVE)
add_compile_options(-march=native)
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
endif()
2019-06-23 05:54:42 +00:00
if(NOT APPLE AND NOT WIN32)
# This hides our LLVM from mesa's LLVM, otherwise we get some unresolvable conflicts.
add_link_options(-Wl,--exclude-libs,ALL)
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
2019-06-23 05:54:42 +00:00
if(HAS_NO_PIE)
add_link_options(-no-pie)
2019-06-23 05:54:42 +00:00
endif()
elseif(APPLE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-stdlib=libc++)
endif()
if (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
add_link_options(-Wl,-image_base,0x10000 -Wl,-pagezero_size,0x10000)
add_link_options(-Wl,-no_pie)
endif()
2019-06-23 05:54:42 +00:00
elseif(WIN32)
add_compile_definitions(__STDC_FORMAT_MACROS=1)
2019-06-23 05:54:42 +00:00
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
# Workaround for mingw64 (MSYS2)
add_link_options(-Wl,--allow-multiple-definition)
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
# Increase stack limit to 8 MB
add_link_options(-Wl,--stack -Wl,8388608)
add_link_options(-Wl,--image-base,0x10000)
CMake: Refactor CMake build (#5032) * CMake: Refactor build to multiple libraries - Refactor CMake build system by creating separate libraries for different components - Create interface libraries for most dependencies and add 3rdparty::* ALIAS targets for ease of use and use them to try specifying correct dependencies for each target - Prefer 3rdparty:: ALIAS when linking dependencies - Exclude xxHash subdirectory from ALL build target - Add USE_SYSTEM_ZLIB option to select between using included ZLib and the ZLib in CMake search path * Add cstring include to Log.cpp * CMake: Add 3rdparty::glew interface target * Add Visual Studio CMakeSettings.json to gitignore * CMake: Move building and finding LLVM to 3rdparty/llvm.cmake script - LLVM is now built under 3rdparty/ directory in the binary directory * CMake: Move finding Qt5 to 3rdparty/qt5.cmake script - Script has to be included in rpcs3/CMakeLists.txt because it defines Qt5::moc target which isn't available in that folder if it is included in 3rdparty directory - Set AUTOMOC and AUTOUIC properties for targets requiring them (rpcs3 and rpcs3_ui) instead of setting CMAKE_AUTOMOC and CMAKE_AUTOUIC so those properties are not defined for all targets under rpcs3 dir * CMake: Remove redundant code from rpcs3/CMakeLists.txt * CMake: Add BUILD_LLVM_SUBMODULE option instead of hardcoded check - Add BUILD_LLVM_SUBMODULE option (defaults to ON) to allow controlling usage of the LLVM submodule. - Move option definitions to root CMakeLists * CMake: Remove separate Emu subtargets - Based on discussion in pull request #5032, I decided to combine subtargets under Emu folder back to a single rpcs3_emu target * CMake: Remove utilities, loader and crypto targets: merge them to Emu - Removed separate targets and merged them into rpcs3_emu target as recommended in pull request (#5032) conversations. Separating targets probably later in a separate pull request * Fix relative includes in pad_thread.cpp * Fix Travis-CI cloning all submodules needlessly
2018-09-18 10:07:33 +00:00
endif()
endif()