Skip to content

Commit

Permalink
Improve precompiled header compatibility with (s)ccache
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Oct 4, 2024
1 parent b1102c2 commit feec714
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ autom4te.cache
*.pyc
*.dSYM
*.gch
*.pch
*.swp
*~.nib
*.pbxuser
Expand Down
19 changes: 14 additions & 5 deletions build/cxx_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@
end

let(:test_cxx_flags) do
['-include test/cxx/TestSupport.h'] + basic_test_cxx_flags
# Some flags are necessary to make precompiled headers play well with ccache (and possibly also sccache):
# https://ccache.dev/manual/4.8.2.html#_precompiled_headers
if PlatformInfo.cxx_is_gcc?
['-include test/cxx/TestSupport.h', '-fpch-preprocess']
elsif PlatformInfo.cxx_is_clang?
["-include-pch test/cxx/TestSupport.h.#{PlatformInfo.precompiled_header_extension}", '-Xclang', '-fno-pch-timestamp']
else
['-include test/cxx/TestSupport.h']
end + basic_test_cxx_flags
end

let(:test_cxx_ldflags) do
Expand All @@ -182,7 +190,7 @@
lambda { {
:include_paths => test_cxx_include_paths,
:flags => test_cxx_flags,
:deps => 'test/cxx/TestSupport.h.gch'
:deps => "test/cxx/TestSupport.h.#{PlatformInfo.precompiled_header_extension}"
} }
)
end
Expand Down Expand Up @@ -280,14 +288,15 @@
end
end

file('test/cxx/TestSupport.h.gch' => generate_compilation_task_dependencies('test/cxx/TestSupport.h')) do
file("test/cxx/TestSupport.h.#{PlatformInfo.precompiled_header_extension}" => generate_compilation_task_dependencies('test/cxx/TestSupport.h')) do
compile_cxx(
'test/cxx/TestSupport.h.gch',
"test/cxx/TestSupport.h.#{PlatformInfo.precompiled_header_extension}",
'test/cxx/TestSupport.h',
:include_paths => test_cxx_include_paths,
:flags => [
"-x c++-header",
PlatformInfo.cxx_is_clang? ? "-Xclang -emit-pch" : nil,
basic_test_cxx_flags
].flatten
].compact.flatten
)
end
2 changes: 1 addition & 1 deletion build/test_basics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
desc "Clean all compiled test files"
task 'test:clean' do
sh("rm -rf #{TEST_OUTPUT_DIR}")
sh("rm -f test/cxx/*.gch")
sh("rm -f test/cxx/*.#{PlatformInfo.precompiled_header_extension} test/cxx/*.gch test/cxx/*.pch")
end

task :clean => 'test:clean'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,14 @@ def self.export_dynamic_flags
end
end

def self.precompiled_header_extension
if cxx_is_gcc?
'gch'
else
'pch'
end
end


def self.make
return string_env('MAKE', find_command('make'))
Expand Down

0 comments on commit feec714

Please sign in to comment.