conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.22k stars 979 forks source link

[question] Manage precompiled headers #7756

Open thegwydd opened 4 years ago

thegwydd commented 4 years ago

Hello people,

I'm converting a C++ project from cmake only to conan + cmake. The old project was "cmake driven" where we were calling conan from within cmake to get dependencies but internal project dependencies (application and internal libraries) were build using cmake only.

Now we want to move "conan driven" where we create packages for each of our libraries and use cmake to only build single projects.

In the old project we were using a lot cmake funcion target_precompile_headers in this way:

target_precompile_headers(${ProjectId} PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/${HEADERS}> ...)

to let the consumers to generate precompiled headers with dependency headers too. How can we do the same thing in a "conan driven" build?

memsharded commented 4 years ago

Hi @thegwydd

Great to know that you are giving Conan a try and adopting it in your project.

Regarding your question, the thing is that Conan does not handle or define the build, and things like precompile headers is still the responsibility of the build system. So it seems that what you were doing in your previous project, you can still do the same.

If it is the headers that will live in other packages the ones that you want to precompile, then you get the information of the folders in the generated files. If you are using the cmake Conan generator, you will get a conanbuildinfo.cmake that you include in your CMakeLists.txt, that contains variables like CONAN_INCLUDE_DIRS that contains all the paths to all headers.

Is this what you mean? Does this help? Please let us know.

thegwydd commented 3 years ago

Well, the problem is better explained with this example:

I have LibA and in its cmakelists.txt there is: set(HEADERS ...list of all project includes...) target_precompile_headers(LibA PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/${HEADERS})

I have LibB and in its cmakelists.txt there is: set(HEADERS ...list of all project includes...) target_link_libraries(LibB LibA) target_precompile_headers(LibB PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/${HEADERS})

I have LibC and in its cmakelists.txt there is: set(HEADERS ...list of all project includes...) target_link_libraries(LibC LibB LibA) target_precompile_headers(LibC PUBLIC $<$:${CMAKE_CURRENT_SOURCE_DIR}/${HEADERS})

Using cmake only, when creating LibC project cmake generates a cmake_pch.hxx file containing all #includes of LibC, LibB and LibA headers.

When using conan we see that cmake generates a cmake_pch.hxx file containing only LibC headers because. I guess it happens because using conan we don't use cmake to get dependencies and that dependencies are not processed in the same way as before

@memsharded How can I make cmake to generate a cmake_pch.hxx containing all of the includes of exposed by dependencies via target_precompile_headers?