[CMake] Problem with different #include for precompiled Headers

Petr Kmoch petr.kmoch at gmail.com
Wed Mar 4 07:29:33 EST 2015


Hi Matthieu.

This has nothing to do with CMake, it's a property of MSVC. The precompiled
header must always be included in exactly the same way, no path changes. In
other words, the name of the precompiled header as specified to /Yc and /Yu
must match exactly.

Pretty much the only sane way to do that is to always include it by pure
name only and provide the appropriate include path to all source files
which use the precompiled header.

Petr

On Wed, Mar 4, 2015 at 1:10 PM, Matthieu Estrada <m.estrada at alpi.fr> wrote:

> Hello,
>
>
>
> I have a CMakeLists.txt who contains the following :
>
>
>
> project(sql_sqlite)
>
>
>
> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /D_USRDLL /DSQL_SQLITE_EXPORTS
> /D_UNICODE /DUNICODE")
>
> SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /GL /Oi /Gy
> /O2 /GR- /Gm- /OPT")
>
> SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX- /ZI /Oy- /Gm
> /EHsc /MDd /GS /Gd ")
>
>
>
>                 set_source_files_properties(../sql_sqlite/stdafx.cpp
> PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
>
>                 set_source_files_properties(../sql_sqlite/sql_sqlite.cpp
> PROPERTIES COMPILE_FLAGS "/Yustdafx.h")
>
>                 set_source_files_properties(../sql_sqlite/win32/main.cpp
> PROPERTIES COMPILE_FLAGS /Yu"../stdafx.h")
>
>
> set_source_files_properties(../../../external/sqlite/sqlite3.c PROPERTIES
> COMPILE_FLAGS "/Y-")
>
>
>
> add_library(
>
>
>
>                                sql_sqlite
>
>
>
>                                SHARED
>
>
>
>                                 ../sql_sqlite/stdafx.h
>
>                                 ../../../external/sqlite/sqlite3.h
>
>
>
>                                ../sql_sqlite/sql_sqlite.cpp
>
>                                 ../sql_sqlite/stdafx.cpp
>
>                                 ../sql_sqlite/win32/main.cpp
>
>                                 ../../../external/sqlite/sqlite3.c
>
>
>
> )
>
>
>
> I've stdafx.cpp and sql-sqlite.cpp with #include "stdafx.h" (for them
> that's ok), but main.cpp with #include "../stdafx.h" doesn't work. When I
> generate Makefile with the NMake Makefiles generator, and type « nmake »
> I’ve the following issue :
>
>
>
> « fatal error C1083: Cannot open precompiled header file: '../stdafx.pch':
> No such file or directory »
>
>
>
> Why he doesn’t find the stdafx.pch ?
>
> I’ve trying many way to resolve this problem : use backslah, slash, in
> CMakeLists.txt or my main.cpp…. Nothing works.
>
> How I can resolve this problem ? Is there a way to force it or a custom
> command special for precompiled header using relative path ?
>
> Cordials,
>
> *Estrada Matthieu*
>
> Service Informatique / Intégration
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150304/c3c32c07/attachment.html>


More information about the CMake mailing list