CMake: Move PCSX2 compile flags to separate target

Makes it easier to split compilation across multiple targets
This commit is contained in:
TellowKrinkle 2021-09-01 22:15:02 -05:00 committed by Kojin
parent a09a6db24d
commit 7ede817241
1 changed files with 31 additions and 31 deletions

View File

@ -1,10 +1,14 @@
include(macros/GlibCompileResourcesSupport) include(macros/GlibCompileResourcesSupport)
add_executable(PCSX2) # All flags, libraries, etc, that are shared between PCSX2 compilation files
add_library(PCSX2_FLAGS INTERFACE)
target_compile_features(PCSX2 PRIVATE cxx_std_17) add_executable(PCSX2)
target_compile_definitions(PCSX2 PUBLIC "${PCSX2_DEFS}") target_link_libraries(PCSX2 PRIVATE PCSX2_FLAGS)
target_compile_options(PCSX2 PRIVATE "${PCSX2_WARNINGS}")
target_compile_features(PCSX2_FLAGS INTERFACE cxx_std_17)
target_compile_definitions(PCSX2_FLAGS INTERFACE "${PCSX2_DEFS}")
target_compile_options(PCSX2_FLAGS INTERFACE "${PCSX2_WARNINGS}")
if (PACKAGE_MODE) if (PACKAGE_MODE)
install(TARGETS PCSX2 DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS PCSX2 DESTINATION ${CMAKE_INSTALL_BINDIR})
@ -25,10 +29,8 @@ if(NOT TOP_CMAKE_WAS_SOURCED)
It is advice to delete all wrongly generated cmake stuff => CMakeFiles & CMakeCache.txt") It is advice to delete all wrongly generated cmake stuff => CMakeFiles & CMakeCache.txt")
endif() endif()
if(MSVC) if(NOT MSVC)
set(CommonFlags) target_compile_options(PCSX2_FLAGS INTERFACE
else()
set(CommonFlags
-fno-strict-aliasing -fno-strict-aliasing
-Wstrict-aliasing # Allow to track strict aliasing issue. -Wstrict-aliasing # Allow to track strict aliasing issue.
-Wno-parentheses -Wno-parentheses
@ -40,34 +42,32 @@ endif()
if(GCC_VERSION VERSION_EQUAL "8.0" OR GCC_VERSION VERSION_GREATER "8.0") if(GCC_VERSION VERSION_EQUAL "8.0" OR GCC_VERSION VERSION_GREATER "8.0")
# gs is pretty bad at this # gs is pretty bad at this
list(APPEND CommonFlags -Wno-packed-not-aligned -Wno-class-memaccess) target_compile_options(PCSX2_FLAGS INTERFACE -Wno-packed-not-aligned -Wno-class-memaccess)
endif() endif()
target_compile_options(PCSX2 PRIVATE ${CommonFlags})
if ("${PGO}" STREQUAL "generate") if ("${PGO}" STREQUAL "generate")
target_compile_options(PCSX2 PRIVATE -fprofile-generate) target_compile_options(PCSX2_FLAGS INTERFACE -fprofile-generate)
elseif("${PGO}" STREQUAL "use") elseif("${PGO}" STREQUAL "use")
target_compile_options(PCSX2 PRIVATE -fprofile-use) target_compile_options(PCSX2_FLAGS INTERFACE -fprofile-use)
endif() endif()
if(TARGET PkgConfig::PORTAUDIO) if(TARGET PkgConfig::PORTAUDIO)
target_compile_definitions(PCSX2 PRIVATE SPU2X_PORTAUDIO) target_compile_definitions(PCSX2_FLAGS INTERFACE SPU2X_PORTAUDIO)
target_link_libraries(PCSX2 PRIVATE PkgConfig::PORTAUDIO) target_link_libraries(PCSX2_FLAGS INTERFACE PkgConfig::PORTAUDIO)
endif() endif()
if(TARGET PulseAudio::PulseAudio) if(TARGET PulseAudio::PulseAudio)
target_compile_definitions(PCSX2 PRIVATE SPU2X_PULSEAUDIO) target_compile_definitions(PCSX2_FLAGS INTERFACE SPU2X_PULSEAUDIO)
target_link_libraries(PCSX2 PRIVATE PulseAudio::PulseAudio) target_link_libraries(PCSX2_FLAGS INTERFACE PulseAudio::PulseAudio)
endif() endif()
if(XDG_STD) if(XDG_STD)
target_compile_definitions(PCSX2 PRIVATE XDG_STD) target_compile_definitions(PCSX2_FLAGS INTERFACE XDG_STD)
endif() endif()
if(TARGET SDL::SDL) if(TARGET SDL::SDL)
target_compile_definitions(PCSX2 PRIVATE SDL_BUILD) target_compile_definitions(PCSX2_FLAGS INTERFACE SDL_BUILD)
target_link_libraries(PCSX2 PRIVATE SDL::SDL) target_link_libraries(PCSX2_FLAGS INTERFACE SDL::SDL)
endif() endif()
if(WIN32) if(WIN32)
@ -83,7 +83,7 @@ if(WIN32)
windows/wxResources.rc windows/wxResources.rc
windows/PCSX2.manifest windows/PCSX2.manifest
) )
target_compile_definitions(PCSX2 PRIVATE target_compile_definitions(PCSX2_FLAGS INTERFACE
_M_SSE=0x401 # TODO: Multiple ISA _M_SSE=0x401 # TODO: Multiple ISA
DIRECTINPUT_VERSION=0x0800 DIRECTINPUT_VERSION=0x0800
WINVER=0x0603 WINVER=0x0603
@ -92,7 +92,7 @@ if(WIN32)
LZMA_API_STATIC LZMA_API_STATIC
WIL_SUPPRESS_EXCEPTIONS WIL_SUPPRESS_EXCEPTIONS
) )
target_include_directories(PCSX2 PRIVATE target_include_directories(PCSX2_FLAGS INTERFACE
../3rdparty # GL headers ../3rdparty # GL headers
) )
set_target_properties(PCSX2 PROPERTIES WIN32_EXECUTABLE TRUE) set_target_properties(PCSX2 PROPERTIES WIN32_EXECUTABLE TRUE)
@ -536,7 +536,7 @@ else(WIN32)
# PAD resources pre-compilation # PAD resources pre-compilation
set(PADImgHeader "${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/ImgHeader") set(PADImgHeader "${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/ImgHeader")
set(PADImg "${CMAKE_SOURCE_DIR}/pcsx2/PAD/Linux/Img") set(PADImg "${CMAKE_SOURCE_DIR}/pcsx2/PAD/Linux/Img")
target_include_directories(PCSX2 PRIVATE "${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/") target_include_directories(PCSX2_FLAGS INTERFACE "${CMAKE_BINARY_DIR}/pcsx2/PAD/Linux/")
file(MAKE_DIRECTORY ${PADImgHeader}) file(MAKE_DIRECTORY ${PADImgHeader})
@ -905,7 +905,7 @@ else(WIN32)
GS/res/glsl/tfx_vgs.glsl) GS/res/glsl/tfx_vgs.glsl)
set(GSBin "${CMAKE_BINARY_DIR}/pcsx2/GS") set(GSBin "${CMAKE_BINARY_DIR}/pcsx2/GS")
target_include_directories(PCSX2 PRIVATE "${GSBin}") target_include_directories(PCSX2_FLAGS INTERFACE "${GSBin}")
file(MAKE_DIRECTORY "${GSBin}") file(MAKE_DIRECTORY "${GSBin}")
add_custom_command( add_custom_command(
@ -1407,7 +1407,7 @@ if(Linux)
${pcsx2LinuxHeaders} ${pcsx2LinuxHeaders}
) )
target_link_libraries(PCSX2 PRIVATE target_link_libraries(PCSX2_FLAGS INTERFACE
PkgConfig::AIO PkgConfig::AIO
PkgConfig::EGL PkgConfig::EGL
PkgConfig::LIBUDEV PkgConfig::LIBUDEV
@ -1417,7 +1417,7 @@ if(Linux)
ALSA::ALSA ALSA::ALSA
) )
elseif(UNIX AND NOT APPLE) elseif(UNIX AND NOT APPLE)
target_link_libraries(PCSX2 PRIVATE X11::X11) target_link_libraries(PCSX2_FLAGS INTERFACE X11::X11)
endif() endif()
# Windows # Windows
@ -1446,7 +1446,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBS
${pcsx2LinuxHeaders}) ${pcsx2LinuxHeaders})
endif() endif()
target_link_libraries(PCSX2 PRIVATE target_link_libraries(PCSX2_FLAGS INTERFACE
common common
fmt::fmt fmt::fmt
yaml-cpp yaml-cpp
@ -1462,7 +1462,7 @@ target_link_libraries(PCSX2 PRIVATE
) )
if(WIN32) if(WIN32)
target_link_libraries(PCSX2 PRIVATE target_link_libraries(PCSX2_FLAGS INTERFACE
baseclasses baseclasses
pthreads4w pthreads4w
WIL::WIL WIL::WIL
@ -1483,7 +1483,7 @@ if(WIN32)
comsuppw.lib comsuppw.lib
) )
else() else()
target_link_libraries(PCSX2 PRIVATE target_link_libraries(PCSX2_FLAGS INTERFACE
GTK::gtk GTK::gtk
HarfBuzz::HarfBuzz HarfBuzz::HarfBuzz
OpenGL::GL OpenGL::GL
@ -1519,7 +1519,7 @@ foreach(res_file IN ITEMS
endforeach() endforeach()
# additonal include directories # additonal include directories
target_include_directories(PCSX2 PRIVATE target_include_directories(PCSX2_FLAGS INTERFACE
. .
x86 x86
${CMAKE_BINARY_DIR}/pcsx2 ${CMAKE_BINARY_DIR}/pcsx2
@ -1530,7 +1530,7 @@ target_include_directories(PCSX2 PRIVATE
if(COMMAND target_precompile_headers) if(COMMAND target_precompile_headers)
message("Using precompiled headers.") message("Using precompiled headers.")
target_precompile_headers(PCSX2 PRIVATE PrecompiledHeader.h) target_precompile_headers(PCSX2_FLAGS INTERFACE PrecompiledHeader.h)
endif() endif()
if (APPLE) if (APPLE)