From 08b73b8a770c66cafa4978f205f6db6cd4bf3e39 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 01:48:16 +0100 Subject: [PATCH 01/16] cmake: Move check_and_add_flag to a separate file Also make it add flags to both C and C++ when appropriate --- CMakeLists.txt | 15 +++++++-------- CMakeTests/CheckAndAddFlag.cmake | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 CMakeTests/CheckAndAddFlag.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b55c77e304..d9fea02207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,13 @@ endif() # TODO: Add DSPSpy option(DSPTOOL "Build dsptool" OFF) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests) +list(APPEND CMAKE_MODULE_PATH + ${CMAKE_SOURCE_DIR}/CMakeTests +) + +# Support functions +include(CheckAndAddFlag) + # Libraries to link set(LIBS) @@ -198,13 +204,6 @@ else() message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.") endif() -include(CheckCXXCompilerFlag) -macro(check_and_add_flag var flag) - CHECK_CXX_COMPILER_FLAG(${flag} FLAG_${var}) - if(FLAG_${var}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") - endif() -endmacro() # Enforce minimum GCC version if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) diff --git a/CMakeTests/CheckAndAddFlag.cmake b/CMakeTests/CheckAndAddFlag.cmake new file mode 100644 index 0000000000..34ab8e60b1 --- /dev/null +++ b/CMakeTests/CheckAndAddFlag.cmake @@ -0,0 +1,14 @@ +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +macro(check_and_add_flag var flag) + check_c_compiler_flag(${flag} FLAG_C_${var}) + if(FLAG_C_${var}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") + endif() + + check_cxx_compiler_flag(${flag} FLAG_CXX_${var}) + if(FLAG_CXX_${var}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") + endif() +endmacro() From a2e40a11d7dcef0c70f518f99a875a06e21de84a Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 03:50:39 +0100 Subject: [PATCH 02/16] Fix typo MinSizeRe -> MinSizeRel --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9fea02207..cfc383cc8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,7 +338,7 @@ find_package(Threads) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING - "Build type (Release/Debug/RelWithDebInfo/MinSizeRe)" FORCE) + "Build type (Release/Debug/RelWithDebInfo/MinSizeRel)" FORCE) endif(NOT CMAKE_BUILD_TYPE) From b9127cd2e0e541bf8f1be7a57c8a84fdf27c6d08 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 03:51:17 +0100 Subject: [PATCH 03/16] cmake: Regroup definitions for 64bit file offsets --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfc383cc8b..899336b697 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,15 +94,6 @@ else() add_definitions(-DDATA_DIR="${datadir}/") endif() -# Set file offset size to 64 bits. -# -# On modern Unixes, this is typically already the case. The lone exception is -# glibc, which may default to 32 bits. glibc allows this to be configured -# by setting _FILE_OFFSET_BITS. -if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - add_definitions(-D_FILE_OFFSET_BITS=64) -endif() - if(CMAKE_SYSROOT) # If we should use a sysroot, tell pkg-config to search for packages in there, not on the host set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig") @@ -414,7 +405,15 @@ if(ENABLE_HEADLESS) add_definitions(-DUSE_HEADLESS) endif() -add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) +# Set file offset size to 64 bits. +# +# On modern Unixes, this is typically already the case. The lone exception is +# glibc, which may default to 32 bits. glibc allows this to be configured +# by setting _FILE_OFFSET_BITS. +if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") + add_definitions(-D_FILE_OFFSET_BITS=64) + add_definitions(-D_LARGEFILE_SOURCE) +endif() ######################################## # Dependency checking From ec84c26975fa58f7b2f3344cb3ad8be3f5c634f9 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 18 Jan 2017 21:25:00 +0100 Subject: [PATCH 04/16] cmake: Remove unused variable --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 899336b697..b78aad139c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,7 +335,6 @@ endif(NOT CMAKE_BUILD_TYPE) if(CMAKE_BUILD_TYPE STREQUAL Debug) add_definitions(-D_DEBUG -ggdb) - set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging") option(ENABLE_GPROF "Enable gprof profiling (must be using Debug build)" OFF) if(ENABLE_GPROF) From 8f355962cefdd1cfa85ca47990f603cf437f06be Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:23:06 +0100 Subject: [PATCH 05/16] cmake: Move include higher up in the file --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b78aad139c..59c4474894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ list(APPEND CMAKE_MODULE_PATH # Support functions include(CheckAndAddFlag) +include(CheckCCompilerFlag) # Libraries to link set(LIBS) @@ -161,7 +162,6 @@ else() add_definitions(-D_ARCH_32=1) endif() -include(CheckCCompilerFlag) if(ENABLE_GENERIC) message(STATUS "Warning! Building generic build!") set(_M_GENERIC 1) From ff4ef0874509f125250894c2c0fdf8122684293b Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:33:36 +0100 Subject: [PATCH 06/16] cmake: Readd fomit-frame-pointer on macOS Make it also properly set on Release for multi-configuration generators --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59c4474894..c6769ad889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,6 +221,11 @@ if(NOT MSVC) check_and_add_flag(INIT_SELF -Winit-self) check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations) check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations) + + check_c_compiler_flag(-fomit-frame-pointer FLAG_C_FOMIT_FRAME_POINTER) + if(FLAG_C_FOMIT_FRAME_POINTER) + add_compile_options($<$:-fomit-frame-pointer>) + endif() endif(NOT MSVC) # gcc uses some optimizations which might break stuff without this flag @@ -343,10 +348,6 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug) endif() endif(CMAKE_BUILD_TYPE STREQUAL Debug) -if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE) - add_definitions(-fomit-frame-pointer) -endif() - if(FASTLOG) add_definitions(-DDEBUGFAST) endif() From c48617008d2bbb27733cbea041db93fdca267490 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:33:36 +0100 Subject: [PATCH 07/16] cmake: Regroup compilation flags together --- CMakeLists.txt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6769ad889..fb684b024d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,21 +222,19 @@ if(NOT MSVC) check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations) check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations) + # gcc uses some optimizations which might break stuff without this flag + check_and_add_flag(NO_STRICT_ALIASING -fno-strict-aliasing) + check_and_add_flag(NO_EXCEPTIONS -fno-exceptions) + + check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden) + check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden) + check_c_compiler_flag(-fomit-frame-pointer FLAG_C_FOMIT_FRAME_POINTER) if(FLAG_C_FOMIT_FRAME_POINTER) add_compile_options($<$:-fomit-frame-pointer>) endif() endif(NOT MSVC) -# gcc uses some optimizations which might break stuff without this flag -add_definitions(-fno-strict-aliasing -fno-exceptions) - -check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden) - -if(UNIX AND NOT APPLE) - check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden) -endif() - if(ENABLE_LTO) check_and_add_flag(LTO -flto) if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) From 3e28ebc31e435f08fdedb4d7badf071c5bc17a2a Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:44:56 +0100 Subject: [PATCH 08/16] cmake: Fix arch detection Windows arch is set to AMD64, and we don't really want ix86 either --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb684b024d..170f896664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,12 +166,7 @@ if(ENABLE_GENERIC) message(STATUS "Warning! Building generic build!") set(_M_GENERIC 1) add_definitions(-D_M_GENERIC=1) -elseif(_ARCH_64 AND ( - ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR - ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR - ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR - APPLE -)) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") set(_M_X86 1) set(_M_X86_64 1) add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2) From 925297d528dcf9e5690d158f8e0e02088c155864 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:49:47 +0100 Subject: [PATCH 09/16] cmake: Simplify setting arch flags on macOS --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 170f896664..f734fce96a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,12 +255,8 @@ if(APPLE) endif() # Specify target CPUs. - set(TARGET_FLAGS "${TARGET_FLAGS} -mssse3") - set(TARGET_FLAGS "${TARGET_FLAGS} -march=core2") - # Target flags apply to both C and C++ compilation. - # CMake passes these to the compiler on the link command line as well. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS}") + check_and_add_flag(HAVE_MSSSE3 -mssse3) + check_and_add_flag(HAVE_ARCH_CORE2 -march=core2) # Linker flags. # Drop unreachable code and data. From fafb103c52cf9d48f2397554fd2369ab397951bf Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:51:09 +0100 Subject: [PATCH 10/16] cmake: Move LTO settings lower in the file --- CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f734fce96a..e9dbcb9aa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,14 +230,6 @@ if(NOT MSVC) endif() endif(NOT MSVC) -if(ENABLE_LTO) - check_and_add_flag(LTO -flto) - if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) - set(CMAKE_AR gcc-ar) - set(CMAKE_RANLIB gcc-ranlib) - endif() -endif() - if(APPLE) # This doesn't play well with the packaging script that doesn't understand @rpath set(CMAKE_MACOSX_RPATH OFF) @@ -292,6 +284,14 @@ if(APPLE) ) endif() +if(ENABLE_LTO) + check_and_add_flag(LTO -flto) + if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) + set(CMAKE_AR gcc-ar) + set(CMAKE_RANLIB gcc-ranlib) + endif() +endif() + if(WIN32) add_definitions(-D_SECURE_SCL=0) add_definitions(-D_CRT_SECURE_NO_WARNINGS) From 5129ba12896134e28ac120d66a97d889134d92ee Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 05:51:14 +0100 Subject: [PATCH 11/16] cmake: Add section with Windows defines --- CMakeLists.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9dbcb9aa6..d7fbe57ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,7 +230,21 @@ if(NOT MSVC) endif() endif(NOT MSVC) -if(APPLE) +if(CMAKE_SYSTEM_NAME MATCHES "Windows") + # Only MSBuild needs this, other generators will compile one file at a time + if(CMAKE_GENERATOR MATCHES "Visual Studio") + add_compile_options("/MP") + endif() + + add_definitions(-DNOMINMAX) + add_definitions(-DUNICODE) + add_definitions(-D_UNICODE) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-D_WIN32_WINNT=0x0602) + add_definitions(-D_SECURE_SCL=0) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") # This doesn't play well with the packaging script that doesn't understand @rpath set(CMAKE_MACOSX_RPATH OFF) @@ -292,12 +306,6 @@ if(ENABLE_LTO) endif() endif() -if(WIN32) - add_definitions(-D_SECURE_SCL=0) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) -endif(WIN32) - # Add an option to build relocatable binaries on Linux # The Sys folder will need to be copied to the Binaries folder. if(UNIX) From aac17b06d1e9d0aa4fc2a330b596057635abab65 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 06:02:01 +0100 Subject: [PATCH 12/16] cmake: Split compile definitions and options --- CMakeLists.txt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7fbe57ad1..a060d75a04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,9 @@ if(ENABLE_GENERIC) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") set(_M_X86 1) set(_M_X86_64 1) - add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2) + add_definitions(-D_M_X86=1) + add_definitions(-D_M_X86_64=1) + check_and_add_flag(HAVE_SSE2 -msse2) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) CHECK_C_COMPILER_FLAG("-no-pie" NO_PIE_UPSTREAM) @@ -184,8 +186,10 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") set(_M_ARM 1) set(_M_ARM_64 1) - add_definitions(-D_M_ARM=1 -D_M_ARM_64=1) - add_definitions(-march=armv8-a+crc) + add_definitions(-D_M_ARM=1) + add_definitions(-D_M_ARM_64=1) + # CRC instruction set is used in the CRC32 hash function + check_and_add_flag(HAVE_ARCH_ARMV8 -march=armv8-a+crc) else() message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.") endif() @@ -196,10 +200,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_L message(FATAL_ERROR "Dolphin requires at least GCC 5.0 (found ${CMAKE_CXX_COMPILER_VERSION})") endif() -# Enabling all warnings in MSVC spams too much if(NOT MSVC) - add_definitions(-Wall) add_definitions(-D_DEFAULT_SOURCE) + check_and_add_flag(HAVE_WALL -Wall) # TODO: would like these but they produce overwhelming amounts of warnings #check_and_add_flag(EXTRA -Wextra) #check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers) @@ -311,7 +314,7 @@ endif() if(UNIX) option(LINUX_LOCAL_DEV "Enable relocatable binary" OFF) if(LINUX_LOCAL_DEV) - add_definitions('-DLINUX_LOCAL_DEV') + add_definitions(-DLINUX_LOCAL_DEV) endif(LINUX_LOCAL_DEV) endif(UNIX) @@ -335,15 +338,19 @@ if(NOT CMAKE_BUILD_TYPE) endif(NOT CMAKE_BUILD_TYPE) -if(CMAKE_BUILD_TYPE STREQUAL Debug) - add_definitions(-D_DEBUG -ggdb) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-D_DEBUG) + check_and_add_flag(GGDB -ggdb) option(ENABLE_GPROF "Enable gprof profiling (must be using Debug build)" OFF) if(ENABLE_GPROF) - add_definitions(-pg) + check_and_add_flag(HAVE_PG -pg) + if(NOT FLAG_C_HAVE_PG) + message(FATAL_ERROR "Compiler option -pg is not supported") + endif() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") endif() -endif(CMAKE_BUILD_TYPE STREQUAL Debug) +endif() if(FASTLOG) add_definitions(-DDEBUGFAST) From d2cb5e640769f87a6dfa94fa6715d481f278f5e5 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 06:03:44 +0100 Subject: [PATCH 13/16] cmake: Small random cleanups --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a060d75a04..9eee79e814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie") endif() endif() -elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") set(_M_ARM 1) set(_M_ARM_64 1) add_definitions(-D_M_ARM=1) @@ -191,7 +191,7 @@ elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") # CRC instruction set is used in the CRC32 hash function check_and_add_flag(HAVE_ARCH_ARMV8 -march=armv8-a+crc) else() - message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.") + message(FATAL_ERROR "You're building on an unsupported platform '${CMAKE_SYSTEM_PROCESSOR}'. Enable generic build if you really want a JIT-less binary.") endif() @@ -260,7 +260,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") # path entirely as was done in a previous version of this file. This is # still kinda evil, since it defeats the user's path settings... # See http://www.cmake.org/cmake/help/v3.0/command/find_program.html - set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr") + list(APPEND CMAKE_PREFIX_PATH "/usr") endif() # Specify target CPUs. @@ -323,7 +323,7 @@ endif(UNIX) # All commands and submodule commands also need to see these # changes, so just setting them in the project scope via # include_directories and link_directories is not sufficient -if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD") +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD|NetBSD") set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/local") set(CMAKE_REQUIRED_INCLUDES "/usr/local/include") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib") From 1dda078c619fb5a6a49d8d6cf755b3c4c11402d8 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 06:06:25 +0100 Subject: [PATCH 14/16] cmake: Compile on Windows with C++ Exceptions --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eee79e814..4f9da6bb3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,7 +200,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_L message(FATAL_ERROR "Dolphin requires at least GCC 5.0 (found ${CMAKE_CXX_COMPILER_VERSION})") endif() -if(NOT MSVC) +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + check_and_add_flag(EXCEPTIONS /EHsc) +else() add_definitions(-D_DEFAULT_SOURCE) check_and_add_flag(HAVE_WALL -Wall) # TODO: would like these but they produce overwhelming amounts of warnings @@ -231,7 +233,7 @@ if(NOT MSVC) if(FLAG_C_FOMIT_FRAME_POINTER) add_compile_options($<$:-fomit-frame-pointer>) endif() -endif(NOT MSVC) +endif() if(CMAKE_SYSTEM_NAME MATCHES "Windows") # Only MSBuild needs this, other generators will compile one file at a time From 221f991f1ea7661daa8c8e8589a2e07650f8394c Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 06:07:01 +0100 Subject: [PATCH 15/16] cmake: Move section to disable PIE with the other compiler flags --- CMakeLists.txt | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f9da6bb3d..b68e9ddedc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,17 +172,6 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") add_definitions(-D_M_X86=1) add_definitions(-D_M_X86_64=1) check_and_add_flag(HAVE_SSE2 -msse2) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") - if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) - CHECK_C_COMPILER_FLAG("-no-pie" NO_PIE_UPSTREAM) - if(NO_PIE_UPSTREAM) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") - endif() - CHECK_C_COMPILER_FLAG("-nopie" NO_PIE_PATCHED) - if(NO_PIE_PATCHED) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie") - endif() - endif() elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") set(_M_ARM 1) set(_M_ARM_64 1) @@ -233,6 +222,19 @@ else() if(FLAG_C_FOMIT_FRAME_POINTER) add_compile_options($<$:-fomit-frame-pointer>) endif() + + if(NOT ANDROID AND _M_X86_64) + # PIE is required on Android, but not supported with the x86_64 jit currently + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") + check_c_compiler_flag("-no-pie" NO_PIE_UPSTREAM) + if(NO_PIE_UPSTREAM) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") + endif() + check_c_compiler_flag("-nopie" NO_PIE_PATCHED) + if(NO_PIE_PATCHED) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie") + endif() + endif() endif() if(CMAKE_SYSTEM_NAME MATCHES "Windows") From 2fd034789ec92f81e9385247c37398207bd40af4 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 06:08:19 +0100 Subject: [PATCH 16/16] cmake: Move /MP flag to MSVC compile flag section --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b68e9ddedc..d38ca95386 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,11 @@ endif() if(CMAKE_C_COMPILER_ID MATCHES "MSVC") check_and_add_flag(EXCEPTIONS /EHsc) + + # Only MSBuild needs this, other generators will compile one file at a time + if(CMAKE_GENERATOR MATCHES "Visual Studio") + add_compile_options("/MP") + endif() else() add_definitions(-D_DEFAULT_SOURCE) check_and_add_flag(HAVE_WALL -Wall) @@ -238,11 +243,6 @@ else() endif() if(CMAKE_SYSTEM_NAME MATCHES "Windows") - # Only MSBuild needs this, other generators will compile one file at a time - if(CMAKE_GENERATOR MATCHES "Visual Studio") - add_compile_options("/MP") - endif() - add_definitions(-DNOMINMAX) add_definitions(-DUNICODE) add_definitions(-D_UNICODE)