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
This commit is contained in:
Lassi Hämäläinen 2018-09-18 13:07:33 +03:00 committed by Ivan
parent e37da61a1c
commit 7aef811ff7
18 changed files with 780 additions and 495 deletions

View file

@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.8.2)
# Check and configure compiler options for RPCS3
if(CMAKE_COMPILER_IS_GNUCXX)
@ -25,3 +24,65 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-stdlib=libc++)
endif()
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-pch -fexceptions")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
endif()
# This hides our LLVM from mesa's LLVM, otherwise we get some unresolvable conflicts.
if(NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--exclude-libs,ALL")
endif()
if(WIN32)
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
# Workaround for mingw64 (MSYS2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS=1")
endif()
add_compile_options(-msse -msse2 -mcx16)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# This fixes 'some' of the st11range issues. See issue #2516
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-image_base,0x10000 -Wl,-pagezero_size,0x10000")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -image-base=0x10000")
endif()
endif()
# Some distros have the compilers set to use PIE by default, but RPCS3 doesn't work with PIE, so we need to disable it.
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_pie")
else()
CHECK_CXX_COMPILER_FLAG("-no-pie" HAS_NO_PIE)
CHECK_CXX_COMPILER_FLAG("-nopie" HAS_NOPIE)
if(HAS_NO_PIE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
elseif(HAS_NOPIE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie")
endif()
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:throwingNew /D _CRT_SECURE_NO_DEPRECATE=1 /D _CRT_NON_CONFORMING_SWPRINTFS=1 /D _SCL_SECURE_NO_WARNINGS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D _ENABLE_EXTENDED_ALIGNED_STORAGE=1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /DYNAMICBASE:NO /BASE:0x10000 /FIXED")
endif()
if(USE_NATIVE_INSTRUCTIONS)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
add_compile_options(-march=native)
endif()
endif()