diff --git a/.gitignore b/.gitignore index 3613d8c..6aa646c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .deps +*.gch *.lo *.loT *.la diff --git a/config.m4 b/config.m4 index c31b47f..658aa89 100644 --- a/config.m4 +++ b/config.m4 @@ -4,18 +4,54 @@ PHP_ARG_ENABLE(arma, for armadillo support, PHP_ARG_ENABLE(arma-operators, for operator overloading support in armadillo, [ --enable-arma-operators Enable operator overloading for armadillo ], no, no) +PHP_ARG_ENABLE(arma-pch, build PCH header of armadillo, +[ --enable-arma-pch Enable building PCH header of armadillo ], no, no) + if test "$PHP_ARMA" != "no"; then PHP_REQUIRE_CXX() - EXTRA_CXXFLAGS="-std=c++17" + # If enabled, try building pre-compiled header for armadillo. + if test "$PHP_ARMA_PCH" != "no"; then + CXX_INCLEDE_PATHS=($(echo | $CXX -xc++ -E -v - 2>&1 | grep -p '^ /')) + PHP_INCLUDES=`php-config --includes` + PCH_FILE='./build/armadillo.gch' + # Note that '-D' option is valid when compiling PCH header, but not when using it. + CXX_TMP_COMPILE_FLAGS="-std=c++17 -x c++-header $PHP_INCLUDES -DARMA_DONT_PRINT_ERRORS" + if test -z "$PHP_DEBUG"; then + CXX_TMP_COMPILE_FLAGS+=' -O2' + else + CXX_TMP_COMPILE_FLAGS+=' -g -O0' + fi + fi + for TEMP_INCLUDE_DIR in "$CXX_INCLEDE_PATHS"; do + ARMADILLO_HEADER_FILE=$TEMP_INCLUDE_DIR/armadillo + if test -f "$ARMADILLO_HEADER_FILE"; then + $CXX $CXX_TMP_COMPILE_FLAGS $TEMP_INCLUDE_DIR/armadillo -o $PCH_FILE + break + fi + done + + # Include PCH file if valid. + EXTRA_CXXFLAGS="-std=c++17 -DARMA_DONT_PRINT_ERRORS" CLANG_TEST_STR=`$CXX --version | grep clang` - if test -n "$CLANG_TEST_STR"; then - EXTRA_CXXFLAGS+=" -Wno-undefined-var-template -Wno-deprecated-declarations" + if test -f "$PCH_FILE"; then + if test -n "$CLANG_TEST_STR"; then + EXTRA_CXXFLAGS+=" -include-pch $PCH_FILE" + # Define this only for clang, in gcc we still need the include directive. + AC_DEFINE(PHP_ARMA_ENABLE_PCH, 1, [ Defined if using pre-compiled armadillo header. ]) + else + EXTRA_CXXFLAGS+=' -I./build' + fi fi + # Disable some clang warnings we don't care. + if test -n "$CLANG_TEST_STR"; then + EXTRA_CXXFLAGS+=' -Wno-undefined-var-template -Wno-deprecated-declarations' + fi + + # Enable/disable operator overloading support. OPERATORS_SRC="src/operators.cc" ARMA_SRC=`ls -1d src/*.cc | grep -v $OPERATORS_SRC` - if test "$PHP_ARMA_OPERATORS" != "no"; then AC_DEFINE(PHP_ARMA_OPERATORS, 1, [ Defined if operator overloading is enabled for armadillo. ]) ARMA_SRC+=" $OPERATORS_SRC" diff --git a/src/operators.cc b/src/operators.cc index 8a81d02..6e0af45 100644 --- a/src/operators.cc +++ b/src/operators.cc @@ -4,7 +4,6 @@ // @Author CismonX // -#include "php_arma.hh" #include "operators.hh" #include "complex.hh" #include "base.hh" diff --git a/src/php_arma.hh b/src/php_arma.hh index a176550..02c966d 100644 --- a/src/php_arma.hh +++ b/src/php_arma.hh @@ -14,7 +14,9 @@ #include #include +#ifndef PHP_ARMA_ENABLE_PCH #include +#endif #define PHP_ARMA_VERSION "0.0.1" @@ -22,8 +24,6 @@ #define ZEND_ACC_CTOR 0 #endif -#define ARMA_DONT_PRINT_ERRORS - /// Helper macros for method entry. #define PHP_ARMA_START_ME(cls, ...) \