Skip to content

Commit

Permalink
Allow building without PCHs on Linux
Browse files Browse the repository at this point in the history
It seems that Aegisub used to be able to be built without precompiled
headers, but this broke with the meson port since there the PCHs are
needed to include acconf.h. (On the old build system(s), the feature
flags were passed directly as defines to the compiler on Visual Studio,
and acconf.h was forcibly included via -include acconf.h with autoconf.)

Some distributions (gentoo in particular) disable PCHs by default for
meson due to various bugs, and PCHs can also be quite a headache with
language servers (I ended up running an sed one-liner after every
configure to replace -include-pch in my compile_commands.json with the
respective -include).

Since meson doesn't seem to be able to forcibly include headers for
every source file, just pass the config as a set of preprocessor
defines when b_pch is disabled. If it's enabled, stick to acconf.h to
not bloat the compiler command lines too much.

For now this only works on Linux, Windows will need extra work due to
windows.h being annoying, but there isn't as much of a need to build
without PCHs there anyway.

The added includes were mostly taken from #241
and #223.

Co-authored-by: Ștefan Talpalaru <stefantalpalaru@yahoo.com>
Co-authored-by: Nick Sarnie <sarnex@gentoo.org>
  • Loading branch information
3 people authored Jan 21, 2025
1 parent 08c084e commit 0f268ed
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ jobs:
name: Ubuntu 22 Debug,
os: ubuntu-22.04,
buildtype: debugoptimized,
args: ''
args: -Db_pch=false
}
- {
name: Ubuntu 22 Release,
os: ubuntu-22.04,
buildtype: release,
args: ''
args: -Db_pch=false
}
- {
name: Ubuntu 24 Debug,
os: ubuntu-24.04,
buildtype: debugoptimized,
args: ''
args: -Db_pch=false
}
- {
name: Ubuntu 24 Release,
os: ubuntu-24.04,
buildtype: release,
args: ''
args: -Db_pch=false
}
- {
name: macOS Debug,
Expand Down
1 change: 1 addition & 0 deletions libaegisub/ass/uuencode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <libaegisub/ass/uuencode.h>

#include <algorithm>
#include <cstring>

// Despite being called uuencoding by ass_specs.doc, the format is actually
// somewhat different from real uuencoding. Each 3-byte chunk is split into 4
Expand Down
1 change: 1 addition & 0 deletions libaegisub/audio/provider_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "libaegisub/fs.h"

#include <cstring>
#include <random>

/*
Expand Down
1 change: 1 addition & 0 deletions libaegisub/common/cajun/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Author: Terry Caton

#include "libaegisub/cajun/reader.h"

#include <algorithm>
#include <boost/interprocess/streams/bufferstream.hpp>
#include <cassert>

Expand Down
1 change: 1 addition & 0 deletions libaegisub/common/calltip_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "libaegisub/ass/dialogue_parser.h"

#include <algorithm>
#include <cstring>

namespace {
struct proto_lit {
Expand Down
2 changes: 2 additions & 0 deletions libaegisub/common/mru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "libaegisub/option.h"
#include "libaegisub/option_value.h"

#include <algorithm>

namespace {
std::string_view mru_names[] = {
"Audio",
Expand Down
1 change: 1 addition & 0 deletions libaegisub/common/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "libaegisub/log.h"
#include "libaegisub/option_value.h"

#include <algorithm>
#include <boost/interprocess/streams/bufferstream.hpp>
#include <cassert>
#include <memory>
Expand Down
1 change: 1 addition & 0 deletions libaegisub/common/thesaurus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "libaegisub/line_iterator.h"
#include "libaegisub/split.h"

#include <algorithm>
#include <boost/interprocess/streams/bufferstream.hpp>

namespace agi {
Expand Down
1 change: 1 addition & 0 deletions libaegisub/include/libaegisub/lua/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <libaegisub/type_name.h>

#include <cstdlib>
#include <cstring>
#include <lua.hpp>

namespace agi::lua {
Expand Down
2 changes: 2 additions & 0 deletions libaegisub/lua/modules/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <unicode/unistr.h>

#include <cstring>

namespace {
char *wrap(void (*fn)(icu::UnicodeString&), const char *str, char **err) {
auto ustr = icu::UnicodeString::fromUTF8(str);
Expand Down
4 changes: 3 additions & 1 deletion libaegisub/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ libaegisub_c_pch = ['include/lagi_pre_c.h']

libaegisub_inc = include_directories('include')

libaegisub = static_library('aegisub', libaegisub_src, acconf,
libaegisub = static_library('aegisub', libaegisub_src, aegisub_order_dep,
c_args: aegisub_defines,
cpp_args: aegisub_defines,
include_directories: [libaegisub_inc, deps_inc],
cpp_pch: libaegisub_cpp_pch,
c_pch: libaegisub_c_pch,
Expand Down
22 changes: 20 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,23 @@ elif cc.has_header_symbol('malloc.h', 'alloca', prefix: '#include <stdlib.h>')
conf.set('HAVE_MALLOC_H', true)
endif

acconf = configure_file(output: 'acconf.h', configuration: conf)
aegisub_order_dep = []
aegisub_defines = []

if get_option('b_pch')
# Write the feature flags into a configure_file to not bloat the compiler args too much
aegisub_order_dep += configure_file(output: 'acconf.h', configuration: conf)
else
# Manually pass the feature flags as compiler args
foreach key : conf.keys()
aegisub_defines += '-D@0@=@1@'.format(key, conf.get(key))
endforeach

if host_machine.system() == 'windows'
# This is also part of all the PCHs
aegisub_defines += '-DWIN32_LEAN_AND_MEAN'
endif
endif

subdir('automation')
subdir('libaegisub')
Expand All @@ -387,7 +403,9 @@ subdir('tests')
aegisub_cpp_pch = ['src/include/agi_pre.h']
aegisub_c_pch = ['src/include/agi_pre_c.h']

aegisub = executable('aegisub', aegisub_src, version_h, acconf, resrc,
aegisub = executable('aegisub', aegisub_src, version_h, resrc, aegisub_order_dep,
c_args: aegisub_defines,
cpp_args: aegisub_defines,
link_with: [libresrc, libaegisub],
include_directories: [libaegisub_inc, libresrc_inc, version_inc, deps_inc, include_directories('src')],
cpp_pch: aegisub_cpp_pch,
Expand Down
1 change: 0 additions & 1 deletion src/MatroskaParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#define EVCBUG
#endif

#include "acconf.h"
#include "MatroskaParser.h"

#ifdef HAVE_ALLOCA_H
Expand Down
1 change: 1 addition & 0 deletions src/ass_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#include <memory>
#include <string>

class AssAttachment;
class AssFile;
Expand Down
1 change: 1 addition & 0 deletions src/ass_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <libaegisub/format.h>
#include <libaegisub/split.h>

#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <wx/intl.h>

Expand Down
3 changes: 3 additions & 0 deletions src/audio_timing_dialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
#include "selection_controller.h"
#include "utils.h"

#include <list>

#include <libaegisub/ass/time.h>

#include <boost/range/algorithm.hpp>

#include <wx/pen.h>

namespace {
Expand Down
2 changes: 2 additions & 0 deletions src/base_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <memory>
#include <string>
#include <vector>
#include <wx/brush.h>
#include <wx/scrolbar.h>
#include <wx/window.h>

namespace agi {
Expand Down
1 change: 1 addition & 0 deletions src/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <map>
#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions src/dialog_colorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <libaegisub/scoped_ptr.h>

#include <algorithm>
#include <memory>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions src/frame_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/sysopt.h>
#include <wx/toolbar.h>

enum {
ID_APP_TIMER_STATUSCLEAR = 12002
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include "aegisublocale.h"

#include <vector>

#ifndef wxUSE_EXCEPTIONS
#error wxWidgets is compiled without exceptions support. Aegisub requires exceptions support in wxWidgets to run safely.
#endif
Expand Down
1 change: 1 addition & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/dc.h>
#include <wx/event.h>
#include <wx/listctrl.h>
#include <wx/msgdlg.h>
Expand Down
1 change: 1 addition & 0 deletions src/spline_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "spline_curve.h"
#include "utils.h"

#include <algorithm>
#include <limits>

SplineCurve::SplineCurve(Vector2D p1) : p1(p1), type(POINT) { }
Expand Down
1 change: 1 addition & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#ifdef __UNIX__
#include <unistd.h>
#endif
#include <algorithm>
#include <map>
#include <unicode/locid.h>
#include <unicode/unistr.h>
Expand Down
1 change: 1 addition & 0 deletions src/video_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// Aegisub Project http://www.aegisub.org/

#include <stddef.h>
#include <vector>

class wxImage;
Expand Down

0 comments on commit 0f268ed

Please sign in to comment.