Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cotire does not generate _pch target for executable build from a single source file #163

Open
leinkemmer opened this issue Aug 29, 2018 · 3 comments

Comments

@leinkemmer
Copy link

I have a target

add_executable(example main.cpp)
cotire(example)

for which cotire does not generate the example_pch target.

$ make help | grep pch
$

As long as there are at least two source files everything works as expected (even if the main.cpp file is just repeated).

add_executable(example main.cpp main.cpp)
cotire(example)

$ make help | grep pch
... all_pch
... example_pch

I assume this is not the desired behavior?

A example of this (based on cotire-1.8.0) can be created easily:

$ git diff
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 92df233..f063c39 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,6 @@
 # cotire example project
 
-add_executable(example main.cpp example.cpp log.cpp log.h example.h)
+add_executable(example main.cpp)
 
 # enable warnings
 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
diff --git a/src/main.cpp b/src/main.cpp
index 2ea1af6..dee8bec 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,11 +2,6 @@
 
 #include <string>
 
-#include "example.h"
-#include "log.h"
-
 int main()
 {
-	std::string msg = example::get_message();
-	logging::info(msg);
 }
@romanc
Copy link

romanc commented Sep 3, 2018

cotire has a minimal number of target source files. The default is 2, but there is a cmake variable to change it. Have a look at the manual.

@leinkemmer
Copy link
Author

Thank you, this is very helpful!
Is there a particular reason why this is done or rather why using precompiled headers with a single cpp file is considered 'advanced usage'. I am just wondering if I am missing something here.

@romanc
Copy link

romanc commented Sep 5, 2018

While pre-compiled headers can also speedup the compilation of single cpp (for example, if the header files are large), the technique is mostly used to create a shared pre-compiled header for multiple translation units (ie multiple source files). In case of only one source file, you generate more overhead to create the pre-compiled header than you gain from using it. If you are interested, read up on pre-compiled headers and how cotire works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants