diff --git a/AI/BattleAI/CMakeLists.txt b/AI/BattleAI/CMakeLists.txt index 589bf5694..63ddc505c 100644 --- a/AI/BattleAI/CMakeLists.txt +++ b/AI/BattleAI/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.6) include_directories(${Boost_INCLUDE_DIRS} ${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib) set(battleAI_SRCS + StdInc.cpp BattleAI.cpp main.cpp ) @@ -11,9 +12,8 @@ set(battleAI_SRCS add_library(BattleAI SHARED ${battleAI_SRCS}) target_link_libraries(BattleAI vcmi) -if(COMMAND cotire) - cotire(BattleAI) -endif() +set_target_properties(BattleAI PROPERTIES ${PCH_PROPERTIES}) +cotire(BattleAI) if (NOT APPLE) # Already inside vcmiclient bundle install(TARGETS BattleAI DESTINATION ${AI_LIB_DIR}) diff --git a/AI/StupidAI/CMakeLists.txt b/AI/StupidAI/CMakeLists.txt index b7d74d663..b8751ef80 100644 --- a/AI/StupidAI/CMakeLists.txt +++ b/AI/StupidAI/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.6) include_directories(${Boost_INCLUDE_DIRS} ${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib) set(stupidAI_SRCS + StdInc.cpp StupidAI.cpp main.cpp ) @@ -11,9 +12,8 @@ set(stupidAI_SRCS add_library(StupidAI SHARED ${stupidAI_SRCS}) target_link_libraries(StupidAI vcmi) -if(COMMAND cotire) - cotire(StupidAI) -endif() +set_target_properties(StupidAI PROPERTIES ${PCH_PROPERTIES}) +cotire(StupidAI) if (NOT APPLE) # Already inside vcmiclient bundle install(TARGETS StupidAI DESTINATION ${AI_LIB_DIR}) diff --git a/AI/VCAI/CMakeLists.txt b/AI/VCAI/CMakeLists.txt index 89f8fa3d3..71154ec60 100644 --- a/AI/VCAI/CMakeLists.txt +++ b/AI/VCAI/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.6) include_directories(${Boost_INCLUDE_DIRS} ${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/lib ${CMAKE_HOME_DIRECTORY}/AI/FuzzyLite) set(VCAI_SRCS + StdInc.cpp VCAI.cpp Goals.cpp AIUtility.cpp @@ -11,16 +12,11 @@ set(VCAI_SRCS Fuzzy.cpp ) -set(VCAI_HEADERS - StdInc.h -) - -add_library(VCAI SHARED ${VCAI_SRCS} ${VCAI_HEADERS}) +add_library(VCAI SHARED ${VCAI_SRCS}) target_link_libraries(VCAI FuzzyLite_lib vcmi) -if(COMMAND cotire) - cotire(VCAI) -endif() +set_target_properties(VCAI PROPERTIES ${PCH_PROPERTIES}) +cotire(VCAI) if (NOT APPLE) # Already inside vcmiclient bundle install(TARGETS VCAI DESTINATION ${AI_LIB_DIR}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a592cd26..59e26cb16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF) option(ENABLE_EDITOR "Enable compilation of map editor" OFF) option(ENABLE_LAUNCHER "Enable compilation of launcher" ON) option(ENABLE_TEST "Enable compilation of unit tests" OFF) -option(ENABLE_PCH "Enable precompiled headers" OFF) +option(ENABLE_PCH "Enable compilation using precompiled headers" OFF) ############################################ # Building section # @@ -59,10 +59,7 @@ find_package(SDL_image REQUIRED) find_package(SDL_mixer REQUIRED) find_package(SDL_ttf REQUIRED) find_package(ZLIB REQUIRED) - -if(ENABLE_PCH) - include(cotire) -endif() +include(cotire) if (ENABLE_EDITOR OR ENABLE_LAUNCHER) # Widgets finds its own dependencies (QtGui and QtCore). @@ -145,6 +142,13 @@ add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/vcmi") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +# precompiled header configuration +SET(PCH_PROPERTIES + COTIRE_ENABLE_PRECOMPILED_HEADER ${ENABLE_PCH} + COTIRE_ADD_UNITY_BUILD FALSE + COTIRE_CXX_PREFIX_HEADER_INIT "StdInc.h" +) + if (ENABLE_ERM) add_subdirectory(scripting/erm) endif() diff --git a/Global.h b/Global.h index 07dceab7e..ceb882436 100644 --- a/Global.h +++ b/Global.h @@ -90,7 +90,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size."); #include #define BOOST_FILESYSTEM_VERSION 3 -#if ( BOOST_VERSION>105000 && !defined(BOOST_THREAD_VERSION)) +#if BOOST_VERSION > 105000 #define BOOST_THREAD_VERSION 3 #endif #define BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE 1 @@ -527,8 +527,12 @@ namespace vstd template auto minElementByFun(const ForwardRange& rng, ValueFunction vf) -> decltype(std::begin(rng)) { - typedef decltype(*std::begin(rng)) ElemType; - return boost::min_element(rng, [&] (ElemType lhs, ElemType rhs) -> bool + /* Clang crashes when instantiating this function template and having PCH compilation enabled. + * There is a bug report here: http://llvm.org/bugs/show_bug.cgi?id=18744 + * Current bugfix is to don't use a typedef for decltype(*std::begin(rng)) and to use decltype + * directly for both function parameters. + */ + return boost::min_element(rng, [&] (decltype(*std::begin(rng)) lhs, decltype(*std::begin(rng)) rhs) -> bool { return vf(lhs) < vf(rhs); }); @@ -538,8 +542,12 @@ namespace vstd template auto maxElementByFun(const ForwardRange& rng, ValueFunction vf) -> decltype(std::begin(rng)) { - typedef decltype(*std::begin(rng)) ElemType; - return boost::max_element(rng, [&] (ElemType lhs, ElemType rhs) -> bool + /* Clang crashes when instantiating this function template and having PCH compilation enabled. + * There is a bug report here: http://llvm.org/bugs/show_bug.cgi?id=18744 + * Current bugfix is to don't use a typedef for decltype(*std::begin(rng)) and to use decltype + * directly for both function parameters. + */ + return boost::max_element(rng, [&] (decltype(*std::begin(rng)) lhs, decltype(*std::begin(rng)) rhs) -> bool { return vf(lhs) < vf(rhs); }); diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 53581633d..fda92d8a5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLMIXER_INCLUD include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}) set(client_SRCS + StdInc.cpp ../CCallback.cpp battle/CBattleInterface.cpp @@ -108,11 +109,9 @@ endif() target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${RT_LIB} ${DL_LIB}) -set_property(DIRECTORY PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${FFMPEG_INCLUDE_DIRS}" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}") +set_target_properties(vcmiclient PROPERTIES ${PCH_PROPERTIES}) +cotire(vcmiclient) -if(COMMAND cotire) - cotire(vcmiclient) -endif() install(TARGETS vcmiclient DESTINATION ${BIN_DIR}) diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 5ce1e0cf1..99ca27031 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories(${Qt5Widgets_INCLUDE_DIRS}) set(maped_SRCS + StdInc.cpp Editor.cpp Main.cpp ) @@ -38,6 +39,8 @@ add_executable(vcmieditor ${maped_SRCS} ${maped_FORMS_OUT}) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore target_link_libraries(vcmieditor vcmi ${Qt5Widgets_LIBRARIES}) + +set_target_properties(vcmieditor PROPERTIES ${PCH_PROPERTIES}) cotire(vcmieditor) if (NOT APPLE) # Already inside bundle diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 6464f9f58..ecad516ce 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -17,6 +17,7 @@ set(launcher_settingsview_SRCS ) set(launcher_SRCS + StdInc.cpp ${launcher_modmanager_SRCS} ${launcher_settingsview_SRCS} main.cpp @@ -53,9 +54,8 @@ add_executable(vcmilauncher ${launcher_SRCS} ${launcher_UI_HEADERS}) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore target_link_libraries(vcmilauncher vcmi ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) -if(COMMAND cotire) - cotire(vcmilauncher) -endif() +set_target_properties(vcmilauncher PROPERTIES ${PCH_PROPERTIES}) +cotire(vcmilauncher) if (NOT APPLE) # Already inside bundle install(TARGETS vcmilauncher DESTINATION ${BIN_DIR}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c9e313184..343d06719 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIRECTORY} ${ include_directories(${Boost_INCLUDE_DIRS} ${SDL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) set(lib_SRCS + StdInc.cpp RegisterTypes.cpp IGameCallback.cpp CGameState.cpp @@ -106,9 +107,8 @@ add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS}) set_target_properties(vcmi PROPERTIES XCODE_ATTRIBUTE_LD_DYLIB_INSTALL_NAME "@executable_path/libvcmi.dylib") target_link_libraries(vcmi minizip ${Boost_LIBRARIES} ${SDL_LIBRARY} ${ZLIB_LIBRARIES} ${RT_LIB} ${DL_LIB}) -if(COMMAND cotire) - cotire(vcmi) -endif() +set_target_properties(vcmi PROPERTIES ${PCH_PROPERTIES}) +cotire(vcmi) if (NOT APPLE) # Already inside vcmiclient bundle install(TARGETS vcmi DESTINATION ${LIB_DIR}) diff --git a/lib/ResourceSet.h b/lib/ResourceSet.h index 98f629ede..34ea08dbb 100644 --- a/lib/ResourceSet.h +++ b/lib/ResourceSet.h @@ -151,6 +151,8 @@ namespace Res }; }; + + using ::operator<<; } typedef Res::ResourceSet TResources; diff --git a/scripting/erm/CMakeLists.txt b/scripting/erm/CMakeLists.txt index 8c214b63b..2e96b5270 100644 --- a/scripting/erm/CMakeLists.txt +++ b/scripting/erm/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 2.6) include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIRECTORY}) set(lib_SRCS + StdInc.cpp ERMParser.cpp ERMInterpreter.cpp ERMScriptModule.cpp @@ -11,6 +12,8 @@ set(lib_SRCS add_library(vcmiERM SHARED ${lib_SRCS}) target_link_libraries(vcmiERM ${Boost_LIBRARIES}) + +set_target_properties(vcmiERM PROPERTIES ${PCH_PROPERTIES}) cotire(vcmiERM) install(TARGETS vcmiERM DESTINATION ${SCRIPTING_LIB_DIR}) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 5aa4e1707..d478e96ab 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_ include_directories(${Boost_INCLUDE_DIRS}) set(server_SRCS + StdInc.cpp CGameHandler.cpp CVCMIServer.cpp CQuery.cpp @@ -19,9 +20,9 @@ endif() target_link_libraries(vcmiserver vcmi ${Boost_LIBRARIES} ${RT_LIB} ${DL_LIB}) -if(COMMAND cotire) - cotire(vcmiserver) -endif() +set_target_properties(vcmiserver PROPERTIES ${PCH_PROPERTIES}) +cotire(vcmiserver) + if (NOT APPLE) # Already inside vcmiclient bundle install(TARGETS vcmiserver DESTINATION ${BIN_DIR}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e81a26f0f..70ef021f4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,11 +14,8 @@ add_executable(vcmitest ${test_SRCS}) target_link_libraries(vcmitest vcmi ${Boost_LIBRARIES} ${RT_LIB} ${DL_LIB}) add_test(vcmitest vcmitest) -set_property(DIRECTORY PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${Boost_INCLUDE_DIRS}/boost/test" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}") - -if(COMMAND cotire) - cotire(vcmitest) -endif() +set_target_properties(vcmitest PROPERTIES ${PCH_PROPERTIES}) +cotire(vcmitest) # Files to copy to the build directory add_custom_target(vcmitestFiles ALL)