summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt100
1 files changed, 12 insertions, 88 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32cfa8580..6a417017c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,90 +104,18 @@ endif()
104message(STATUS "Target architecture: ${ARCHITECTURE}") 104message(STATUS "Target architecture: ${ARCHITECTURE}")
105 105
106 106
107# Configure compilation flags 107# Configure C++ standard
108# =========================== 108# ===========================
109 109
110set(CMAKE_CXX_STANDARD 17) 110set(CMAKE_CXX_STANDARD 17)
111set(CMAKE_CXX_STANDARD_REQUIRED ON) 111set(CMAKE_CXX_STANDARD_REQUIRED ON)
112 112
113if (NOT MSVC)
114 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
115 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
116
117 if (MINGW)
118 add_definitions(-DMINGW_HAS_SECURE_API)
119
120 if (MINGW_STATIC_BUILD)
121 add_definitions(-DQT_STATICPLUGIN)
122 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
123 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
124 endif()
125 endif()
126else()
127 # Silence "deprecation" warnings
128 add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D_SCL_SECURE_NO_WARNINGS)
129 # Avoid windows.h junk
130 add_definitions(/DNOMINMAX)
131 # Avoid windows.h from including some usually unused libs like winsocks.h, since this might cause some redefinition errors.
132 add_definitions(/DWIN32_LEAN_AND_MEAN)
133
134 set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)
135
136 # Tweak optimization settings
137 # As far as I can tell, there's no way to override the CMake defaults while leaving user
138 # changes intact, so we'll just clobber everything and say sorry.
139 message(STATUS "Cache compiler flags ignored, please edit CMakeLists.txt to change the flags.")
140
141 # /W3 - Level 3 warnings
142 # /MP - Multi-threaded compilation
143 # /Zi - Output debugging information
144 # /Zo - enhanced debug info for optimized builds
145 # /permissive- - enables stricter C++ standards conformance checks
146 set(CMAKE_C_FLAGS "/W3 /MP /Zi /Zo /permissive-" CACHE STRING "" FORCE)
147 # /EHsc - C++-only exception handling semantics
148 # /Zc:throwingNew - let codegen assume `operator new` will never return null
149 # /Zc:inline - let codegen omit inline functions in object files
150 set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /EHsc /std:c++latest /Zc:throwingNew,inline" CACHE STRING "" FORCE)
151
152 # /MDd - Multi-threaded Debug Runtime DLL
153 set(CMAKE_C_FLAGS_DEBUG "/Od /MDd" CACHE STRING "" FORCE)
154 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "" FORCE)
155
156 # /O2 - Optimization level 2
157 # /GS- - No stack buffer overflow checks
158 # /MD - Multi-threaded runtime DLL
159 set(CMAKE_C_FLAGS_RELEASE "/O2 /GS- /MD" CACHE STRING "" FORCE)
160 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
161
162 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
163 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
164endif()
165
166# Fix GCC C++17 and Boost.ICL incompatibility (needed to build dynarmic)
167# See https://bugzilla.redhat.com/show_bug.cgi?id=1485641#c1
168if (CMAKE_COMPILER_IS_GNUCC)
169 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-new-ttp-matching")
170endif()
171
172# Set file offset size to 64 bits.
173#
174# On modern Unixes, this is typically already the case. The lone exception is
175# glibc, which may default to 32 bits. glibc allows this to be configured
176# by setting _FILE_OFFSET_BITS.
177if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
178 add_definitions(-D_FILE_OFFSET_BITS=64)
179endif()
180
181# CMake seems to only define _DEBUG on Windows
182set_property(DIRECTORY APPEND PROPERTY
183 COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG> $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
184
185# System imported libraries 113# System imported libraries
186# ====================== 114# ======================
187 115
188find_package(Boost 1.63.0 QUIET) 116find_package(Boost 1.66.0 QUIET)
189if (NOT Boost_FOUND) 117if (NOT Boost_FOUND)
190 message(STATUS "Boost 1.63.0 or newer not found, falling back to externals") 118 message(STATUS "Boost 1.66.0 or newer not found, falling back to externals")
191 119
192 set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/externals/boost") 120 set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/externals/boost")
193 set(Boost_NO_SYSTEM_PATHS OFF) 121 set(Boost_NO_SYSTEM_PATHS OFF)
@@ -332,25 +260,21 @@ endif()
332# Platform-specific library requirements 260# Platform-specific library requirements
333# ====================================== 261# ======================================
334 262
335IF (APPLE) 263if (APPLE)
336 find_library(COCOA_LIBRARY Cocoa) # Umbrella framework for everything GUI-related 264 # Umbrella framework for everything GUI-related
265 find_library(COCOA_LIBRARY Cocoa)
337 set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY}) 266 set(PLATFORM_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
338 267elseif (WIN32)
339 if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
340 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
341 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
342 endif()
343ELSEIF (WIN32)
344 # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista) 268 # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista)
345 add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600) 269 add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600)
346 set(PLATFORM_LIBRARIES winmm ws2_32) 270 set(PLATFORM_LIBRARIES winmm ws2_32)
347 IF (MINGW) 271 if (MINGW)
348 # PSAPI is the Process Status API 272 # PSAPI is the Process Status API
349 set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version) 273 set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version)
350 ENDIF (MINGW) 274 endif()
351ELSEIF (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$") 275elseif (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU|SunOS)$")
352 set(PLATFORM_LIBRARIES rt) 276 set(PLATFORM_LIBRARIES rt)
353ENDIF (APPLE) 277endif()
354 278
355# Setup a custom clang-format target (if clang-format can be found) that will run 279# Setup a custom clang-format target (if clang-format can be found) that will run
356# against all the src files. This should be used before making a pull request. 280# against all the src files. This should be used before making a pull request.
@@ -385,7 +309,7 @@ if (CLANG_FORMAT)
385 set(CCOMMENT "Running clang format against all the .h and .cpp files in src/") 309 set(CCOMMENT "Running clang format against all the .h and .cpp files in src/")
386 if (WIN32) 310 if (WIN32)
387 add_custom_target(clang-format 311 add_custom_target(clang-format
388 COMMAND powershell.exe -Command "Get-ChildItem ${SRCS}/* -Include *.cpp,*.h -Recurse | Foreach {${CLANG_FORMAT} -i $_.fullname}" 312 COMMAND powershell.exe -Command "Get-ChildItem '${SRCS}/*' -Include *.cpp,*.h -Recurse | Foreach {&'${CLANG_FORMAT}' -i $_.fullname}"
389 COMMENT ${CCOMMENT}) 313 COMMENT ${CCOMMENT})
390 elseif(MINGW) 314 elseif(MINGW)
391 add_custom_target(clang-format 315 add_custom_target(clang-format