sakra / cotire

CMake module to speed up builds.
MIT License
1.3k stars 142 forks source link

cotire and BOOST_PP error #119

Open jo71 opened 7 years ago

jo71 commented 7 years ago

I run into a problem which I wasn't able to reduce yet. I'm using boost spirit and boost.test. The error rises:

[ 62%] Building CXX precompiled header sources/...._parser_CXX_prefix.hxx.gch
In file included from /tmp/build/sources/..._parser_CXX_prefix.cxx:38:0,
                 from /tmp/build/sources/..._parser_CXX_prefix.hxx:4:
/usr/include/boost/preprocessor/iteration/detail/local.hpp:13:6: Fehler: #error BOOST_PP_ERROR: local iteration boundaries are not defined
 #    error BOOST_PP_ERROR:  local iteration boundaries are not defined
      ^~~~~
/usr/include/boost/preprocessor/iteration/detail/local.hpp:34:29: Fehler: expected constructor, destructor, or type conversion before »(« token
         BOOST_PP_LOCAL_MACRO(0)
                             ^
CMake Error at /tmp/ibis/cmake/cotire.cmake:1848 (message):
  cotire: error 1 precompiling
  /tmp/build/sources/..._parser_CXX_prefix.hxx.
Call Stack (most recent call first):
  /tmp/ibis/cmake/cotire.cmake:3521 (cotire_precompile_prefix_header)

The calc9 example from boost.spirit.x3 compiles with cotire and an intro example from boost.test also, but failed here. Maybe helpful:

$ cat /tmp/build/sources/..._parser_CXX_prefix.hxx
/* cotire.cmake 1.7.9 generated file */
/* /tmp/build/sources/..._parser_CXX_prefix.hxx */
#ifdef __cplusplus
#include "/tmp/build/sources/..._parser_CXX_prefix.cxx"
#endif

$ cat /tmp/build/...parser_CXX_prefix.cxx
/* cotire.cmake 1.7.9 generated file */
/* /tmp/build/sources/...parser_CXX_prefix.cxx */
#pragma GCC system_header
#ifdef __cplusplus
#include "/usr/include/boost/test/unit_test.hpp"
#include "/usr/include/boost/test/data/test_case.hpp"
#include "/usr/include/boost/filesystem.hpp"
#include "/usr/local/gcc-7.1.0/include/c++/7.1.0/iostream"
#include "/usr/include/boost/core/ignore_unused.hpp"
#include "/usr/include/boost/range.hpp"
#include "/usr/include/boost/variant.hpp"
#include "/usr/include/boost/fusion/include/adapt_struct.hpp"
#include "/usr/include/boost/fusion/support/pair.hpp"
#include "/usr/include/boost/fusion/include/deque.hpp"
#include "/usr/include/boost/tti/has_type.hpp"
#include "/usr/include/boost/tti/has_member_function.hpp"
#include "/usr/include/boost/fusion/include/copy.hpp"
#include "/usr/include/boost/fusion/include/is_sequence.hpp"
#include "/usr/include/boost/fusion/include/size.hpp"
#include "/usr/include/boost/fusion/include/map.hpp"
#include "/usr/include/boost/fusion/include/value_at_key.hpp"
#include "/usr/include/boost/fusion/adapted/mpl.hpp"
#include "/usr/include/boost/mpl/placeholders.hpp"
#include "/usr/include/boost/mpl/filter_view.hpp"
#include "/usr/include/boost/mpl/count_if.hpp"
#include "/usr/include/boost/fusion/include/front.hpp"
#include "/usr/include/boost/fusion/include/move.hpp"
#include "/usr/include/boost/fusion/include/back.hpp"
#include "/usr/include/boost/type_traits/extent.hpp"
#include "/usr/include/boost/cstdint.hpp"
#include "/usr/include/boost/regex/pending/unicode_iterator.hpp"
#include "/usr/local/gcc-7.1.0/include/c++/7.1.0/bitset"
#include "/usr/local/gcc-7.1.0/include/c++/7.1.0/climits"
#include "/usr/local/gcc-7.1.0/include/c++/7.1.0/cctype"
#include "/usr/local/gcc-7.1.0/include/c++/7.1.0/cwctype"
#include "/usr/include/boost/function_types/function_type.hpp"
#include "/usr/include/boost/preprocessor/iteration/local.hpp"
#include "/usr/include/boost/preprocessor/iteration/detail/local.hpp"
#include "/usr/include/boost/config/no_tr1/cmath.hpp"
#include "/usr/include/boost/math/special_functions/fpclassify.hpp"
#include "/usr/include/boost/math/special_functions/sign.hpp"
#include "/usr/include/boost/fusion/include/begin.hpp"
#include "/usr/include/boost/fusion/include/end.hpp"
#include "/usr/include/boost/fusion/include/advance.hpp"
#include "/usr/include/boost/fusion/include/empty.hpp"
#include "/usr/include/boost/fusion/include/iterator_range.hpp"
#include "/usr/include/boost/fusion/include/as_deque.hpp"
#include "/usr/include/boost/fusion/include/mpl.hpp"
#include "/usr/include/boost/mpl/copy_if.hpp"
#include "/usr/include/boost/fusion/include/at.hpp"
#include "/usr/include/boost/locale/encoding_utf.hpp"
#include "/usr/include/boost/test/output_test_stream.hpp"
#include "/usr/include/boost/test/included/unit_test.hpp"
#endif
andry81 commented 7 years ago

Boost libraries has it's own mechanism for the libraries and includes extraction: https://stackoverflow.com/questions/5306745/getting-only-necessary-headers-out-of-boost

If you take a look at the bcp sources, you can figure out how it finds the includes (https://svn.boost.org/svn/boost/trunk/tools/bcp/add_path.cpp):

 //
 // Scan for any #include MACRO includes that we don't recognise.
 //
 // Begin by declaring all of the macros that get #included that 
 // we know about and are correctly handled as special cases:
 //
 static const std::string known_macros[] = {

Seems the contire does not contain such a tricky way to detect the necessary headers. I may suggest to avoid the boost/preprocessor directory from any detection by the contire, otherwise you can include entire directory into pch header: boost/preprocessor.hpp.

jox98 commented 6 years ago

I run into the same issue.

The problem with andry81 solution are the requirements of use of Boost.Spirit and Boost.Test on my project too. Both libs make heavy use of BOOST_PP magic.

The following doesn't work:

    set_target_properties(${PROJECT_NAME} PROPERTIES
        COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH "${Boost_INCLUDE_DIRS}/preprocessor")

compiler error:

    /usr/include/boost/preprocessor/iteration/detail/local.hpp:13:6: Fehler: #error BOOST_PP_ERROR: local iteration boundaries are not defined
     #    error BOOST_PP_ERROR:  local iteration boundaries are not defined
          ^~~~~
    /usr/include/boost/preprocessor/iteration/detail/local.hpp:34:29: Fehler: expected constructor, destructor, or type conversion before »(« token
             BOOST_PP_LOCAL_MACRO(0)
                                 ^

Are there any tips how to gather the origin of the problem?

Philippe-Cote-Morneault commented 5 years ago

Hi, is there any progress on this? I'm also having similar issues with BOOST_PP. My current options are to either add boost dependencies after cotiring, or simply not using cotire at all.