From de1773affb7552d1b62b7adcd3a2a04d718feafe Mon Sep 17 00:00:00 2001 From: comex Date: Thu, 17 Oct 2013 00:06:34 -0400 Subject: [PATCH] Basic precompiled header support for Linux/OS X. Shaves 20-30% off full rebuild time on my system. --- CMakeLists.txt | 2 + Source/CMakeLists.txt | 47 ++++++++++++++++ Source/Core/AudioCommon/CMakeLists.txt | 3 +- Source/Core/Common/CMakeLists.txt | 3 +- Source/Core/Core/CMakeLists.txt | 3 +- Source/Core/DiscIO/CMakeLists.txt | 3 +- Source/Core/InputCommon/CMakeLists.txt | 2 +- Source/Core/VideoBackends/OGL/CMakeLists.txt | 3 +- .../VideoBackends/Software/CMakeLists.txt | 3 +- Source/Core/VideoCommon/CMakeLists.txt | 3 +- Source/pch.h | 55 +++++++++++++++++++ 11 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 Source/pch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cc9f87065a..aeb8f1fcb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option(USE_GLES "Enables GLES2 And EGL, disables OGL" OFF) option(USE_GLES3 "Enables GLES3 and EGL" OFF) option(USE_UPNP "Enables UPnP port mapping support" ON) option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF) +option(ENABLE_PCH "Use PCH to speed up compilation" OFF) option(FASTLOG "Enable all logs" OFF) option(OPROFILING "Enable profiling" OFF) @@ -817,3 +818,4 @@ list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}") # CPack must be included after the CPACK_* variables are set in order for those # variables to take effect. Include(CPack) + diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 6c962873a7..7c667ba551 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -1,3 +1,47 @@ +set(CMAKE_FAKELANG_CREATE_STATIC_LIBRARY "touch ") +if(ENABLE_PCH) + # This is actually a .h file, but trick cmake into compiling it as a source file + set(pch_out_filename "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/pch.dir/pch.h") + set(pch_lib_filename "${CMAKE_CURRENT_BINARY_DIR}/libpch.a") + set(pch_src_filename "${CMAKE_CURRENT_SOURCE_DIR}/pch.h") + + if(APPLE) + set(type objective-c++-header) + else() + set(type c++-header) + endif() + + set_source_files_properties( + pch.h PROPERTIES + COMPILE_FLAGS "-x ${type}" + HEADER_FILE_ONLY 0 + LANGUAGE CXX) + + add_library(pch STATIC pch.h) + + add_custom_command( + TARGET pch + PRE_LINK + COMMAND ln -fs "${pch_out_filename}.o" "${pch_out_filename}.gch" + COMMAND ln -fs "${pch_out_filename}.o" "${pch_out_filename}.pch" + COMMAND cp "${pch_src_filename}" "${pch_out_filename}") + + set_target_properties( + pch PROPERTIES + LINKER_LANGUAGE FAKELANG) +endif(ENABLE_PCH) +macro(add_dolphin_library lib srcs libs) + add_library(${lib} STATIC ${srcs}) + target_link_libraries(${lib} ${libs}) + if(ENABLE_PCH) + add_dependencies(${lib} pch) + set_source_files_properties( + ${srcs} PROPERTIES + COMPILE_FLAGS "-include ${pch_out_filename}" + OBJECT_DEPENDS "${pch_lib_filename}") + endif(ENABLE_PCH) +endmacro(add_dolphin_library) + add_subdirectory(Core) if (DSPTOOL) @@ -8,4 +52,7 @@ if (UNITTESTS) add_subdirectory(UnitTests) endif() + + + # TODO: Add DSPSpy and TestSuite. Preferrably make them option()s and cpack components diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index 939956460d..314be71322 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -40,5 +40,4 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(SRCS ${SRCS} Src/CoreAudioSoundStream.cpp) endif() -add_library(audiocommon STATIC ${SRCS}) -target_link_libraries(audiocommon ${LIBS}) +add_dolphin_library(audiocommon "${SRCS}" "${LIBS}") diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 0302ee78c8..ce76f003da 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -51,5 +51,4 @@ endif(WIN32) enable_precompiled_headers(Src/stdafx.h Src/stdafx.cpp SRCS) -add_library(common STATIC ${SRCS}) -target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT}) +add_dolphin_library(common "${SRCS}" "${CMAKE_THREAD_LIBS_INIT}") diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 49cd34b372..07a6fc2aca 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -269,5 +269,4 @@ if(GDBSTUB) set(SRCS ${SRCS} Src/PowerPC/GDBStub.cpp) endif(GDBSTUB) -add_library(core STATIC ${SRCS}) -target_link_libraries(core ${LIBS}) +add_dolphin_library(core "${SRCS}" "${LIBS}") diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index 01e15a374f..f64f263e11 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -21,5 +21,4 @@ set(SRCS Src/BannerLoader.cpp Src/VolumeWiiCrypted.cpp Src/WiiWad.cpp) -add_library(discio STATIC ${SRCS}) -target_link_libraries(discio common) +add_dolphin_library(discio "${SRCS}" "") diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 76871e5b3b..f99351ffe2 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -32,4 +32,4 @@ elseif(ANDROID) Src/ControllerInterface/Android/Android.cpp) endif() -add_library(inputcommon ${SRCS}) +add_dolphin_library(inputcommon "${SRCS}" "") diff --git a/Source/Core/VideoBackends/OGL/CMakeLists.txt b/Source/Core/VideoBackends/OGL/CMakeLists.txt index 3e1d2aaa60..f8ccb85052 100644 --- a/Source/Core/VideoBackends/OGL/CMakeLists.txt +++ b/Source/Core/VideoBackends/OGL/CMakeLists.txt @@ -45,5 +45,4 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR set(LIBS ${LIBS} usbhid) endif() -add_library(videoogl STATIC ${SRCS}) -target_link_libraries(videoogl ${LIBS}) +add_dolphin_library(videoogl "${SRCS}" "${LIBS}") diff --git a/Source/Core/VideoBackends/Software/CMakeLists.txt b/Source/Core/VideoBackends/Software/CMakeLists.txt index fd13be7f2e..2ba8e6c0c7 100644 --- a/Source/Core/VideoBackends/Software/CMakeLists.txt +++ b/Source/Core/VideoBackends/Software/CMakeLists.txt @@ -49,5 +49,4 @@ if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")) set(LIBS ${LIBS} clrun) endif() -add_library(videosoftware STATIC ${SRCS}) -target_link_libraries(videosoftware ${LIBS}) +add_dolphin_library(videosoftware "${SRCS}" "${LIBS}") diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt index 8503377779..594624592c 100644 --- a/Source/Core/VideoCommon/CMakeLists.txt +++ b/Source/Core/VideoCommon/CMakeLists.txt @@ -61,8 +61,7 @@ if(LIBAV_FOUND OR WIN32) set(SRCS ${SRCS} Src/AVIDump.cpp) endif() -add_library(videocommon STATIC ${SRCS}) -target_link_libraries(videocommon ${LIBS}) +add_dolphin_library(videocommon "${SRCS}" "${LIBS}") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(LIBAV_FOUND) diff --git a/Source/pch.h b/Source/pch.h new file mode 100644 index 0000000000..6a49c2b1f0 --- /dev/null +++ b/Source/pch.h @@ -0,0 +1,55 @@ +#include "Common.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include