cotire icon indicating copy to clipboard operation
cotire copied to clipboard

Compile flags not correctly extracted from target

Open fschoenm opened this issue 6 years ago • 2 comments

I have a library that uses SSE4.1 and is included as a dependency in my application. I use modern CMake with targets and try to improve build speed with cotire. The library has exported its compile flags with target_compile_options(lib PUBLIC -msse4.1) and the dependency between both targets is set with target_link_libraries(app lib).

The problem is, when using the precompiled headers in the application, the compiler complains that the -msse4.1 flag has not been set when creating them. For single files however, the compile option is set correctly. Here is the relevant build output:

[ 75%] Generating CXX prefix header app/cotire/app_CXX_prefix.hxx
/usr/bin/cmake -DCOTIRE_BUILD_TYPE:STRING= -DCOTIRE_VERBOSE:BOOL=1 -P /home/fschoenm/devel/cotire-bug/cotire.cmake combine /home/fschoenm/devel/cotire-bug/build/app/app_CXX_cotire.cmake /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.cxx
#ifdef __cplusplus
#include "/home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.cxx"
#endif

[ 83%] Building CXX precompiled header app/cotire/app_CXX_prefix.hxx.gch
cd /home/fschoenm/devel/cotire-bug/app && /usr/bin/cmake -DCOTIRE_BUILD_TYPE:STRING= -DCOTIRE_VERBOSE:BOOL=1 -P /home/fschoenm/devel/cotire-bug/cotire.cmake precompile /home/fschoenm/devel/cotire-bug/build/app/app_CXX_cotire.cmake /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx.gch app.cpp
-- execute_process: /usr/bin/c++;-x;c++-header;-c;/home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx;-o;/home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx.gch
cd /home/fschoenm/devel/cotire-bug/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/fschoenm/devel/cotire-bug /home/fschoenm/devel/cotire-bug/app /home/fschoenm/devel/cotire-bug/build /home/fschoenm/devel/cotire-bug/build/app /home/fschoenm/devel/cotire-bug/build/app/CMakeFiles/app.dir/DependInfo.cmake --color=
Dependee "/home/fschoenm/devel/cotire-bug/build/app/CMakeFiles/app.dir/DependInfo.cmake" is newer than depender "/home/fschoenm/devel/cotire-bug/build/app/CMakeFiles/app.dir/depend.internal".
Dependee "/home/fschoenm/devel/cotire-bug/build/app/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/fschoenm/devel/cotire-bug/build/app/CMakeFiles/app.dir/depend.internal".
Scanning dependencies of target app
make[2]: Leaving directory '/home/fschoenm/devel/cotire-bug/build'
make -f app/CMakeFiles/app.dir/build.make app/CMakeFiles/app.dir/build
make[2]: Entering directory '/home/fschoenm/devel/cotire-bug/build'
[ 91%] Building CXX object app/CMakeFiles/app.dir/app.cpp.o
cd /home/fschoenm/devel/cotire-bug/build/app && /usr/bin/c++    -Winvalid-pch -include /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx -msse4.1 -o CMakeFiles/app.dir/app.cpp.o -c /home/fschoenm/devel/cotire-bug/app/app.cpp
cc1plus: warning: /home/fschoenm/devel/cotire-bug/build/app/cotire/app_CXX_prefix.hxx.gch: created and used with differing settings of '-mno-sse4'

It seems as if the compile flags for the precompiled header are not correctly extracted from the target (in this case app).

I attached a small sample project that shows the behavior. Call CMake with the following arguments to force generation of precompiled headers: cmake -D COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES=1 ..

cotire-bug.tar.gz

fschoenm avatar Jul 17 '18 10:07 fschoenm

Seeing something similar, #159

JasonDictos avatar Aug 03 '18 05:08 JasonDictos

Hit this issue too, in my case caused by including OpenCV and PointCloudLibrary

tonygrue avatar May 08 '19 07:05 tonygrue