diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/CMakeLists.txt | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ffe7955b..afedb7371 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,7 +220,9 @@ find_package(Gettext) option(USE_RUN_CC_PL "Use run-cc.pl for building" OFF) # Use the following directories as includes -include_directories(${Anope_SOURCE_DIR}/include ${Anope_BINARY_DIR}/include ${Anope_BINARY_DIR}/language) +# Note that it is important the binary include directory comes before the +# source include directory so the precompiled headers work correctly. +include_directories(${Anope_BINARY_DIR}/include ${Anope_SOURCE_DIR}/include ${Anope_BINARY_DIR}/language) # If using Windows, always add the _WIN32 define if(WIN32) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index c484334c1..8b292aea2 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,5 +16,26 @@ if(NOT WIN32) add_to_cpack_ignored_files("version.h$" TRUE) endif(NOT WIN32) +set(PCH_SOURCES_GCH "") +if(CMAKE_COMPILER_IS_GNUCXX) + string(REPLACE " " ";" PCH_CXXFLAGS ${CXXFLAGS}) + + set(PCH_SOURCES "module.h;modules.h;services.h") + foreach(PCH_SOURCE ${PCH_SOURCES}) + set(PCH_EXTRAFLAGS "") + if(DEBUG_BUILD) + set(PCH_EXTRAFLAGS "-g") + endif(DEBUG_BUILD) + if(PCH_SOURCE STREQUAL "module.h") + set(PCH_EXTRAFLAGS ${PCH_EXTRAFLAGS} -fPIC) + endif(PCH_SOURCE STREQUAL "module.h") + + set(PCH_SOURCES_GCH "${PCH_SOURCES_GCH};${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch") + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch + COMMAND ${CMAKE_CXX_COMPILER} ARGS ${PCH_CXXFLAGS} ${PCH_EXTRAFLAGS} -I${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${PCH_SOURCE} -o ${CMAKE_CURRENT_BINARY_DIR}/${PCH_SOURCE}.gch VERBATIM + ) + endforeach(PCH_SOURCE ${PCH_SOURCES}) +endif(CMAKE_COMPILER_IS_GNUCXX) + # Add a custom target to the above file -add_custom_target(headers DEPENDS version ${CMAKE_CURRENT_BINARY_DIR}/version.h) +add_custom_target(headers DEPENDS version ${CMAKE_CURRENT_BINARY_DIR}/version.h ${PCH_SOURCES_GCH}) |