Reputation: 3078
If I'm using the clang compiler in CMake, I would like to prepend the option -cc1
to it for every possible invocation (better: only for a certain target)
I tried using
set(CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER} -cc1")
But this wraps the invocation in quotes; consequently this doesn't get recognized as a valid command in my shell.
If I use
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} -cc1)
then I get a semicolon between the clang invocation and the -cc1
option. This also doesn't work.
How do I get CMake to change /path/to/clang
into /path/to/clang -cc1
?
Upvotes: 1
Views: 1773
Reputation: 3078
One workaround for clang-specific needs is to use the -Xclang
compiler option, which forces the clang driver to pass the option that follows it to clang -cc1
.
For example:
target_compile_options(${target} PUBLIC "-Xclang -include-pch ${output}")
Upvotes: 2
Reputation: 44
See: cmake CFLAGS CXXFLAGS modification
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -cc1")
For a single target:
target_compile_options(target -cc1)
Upvotes: 0