diff --git a/ShellScripts/common/post_build.sh b/ShellScripts/common/post_build.sh index 3c9643318..1e14bc510 100755 --- a/ShellScripts/common/post_build.sh +++ b/ShellScripts/common/post_build.sh @@ -82,6 +82,9 @@ run_script() { # Copy Linux-specific wrapper script cp -fu ShellScripts/Linux/run_oolite.sh "$PROGDIR" local GNUSTEP_CONF="$GNUSTEP_FOLDER/etc/GNUstep/GNUstep.conf" + if [ ! -f "$GNUSTEP_CONF" ] && [ "$GNUSTEP_FOLDER" = "/usr" ] && [ -f "/etc/GNUstep/GNUstep.conf" ]; then + GNUSTEP_CONF="/etc/GNUstep/GNUstep.conf" + fi install -D "$GNUSTEP_CONF" "$PROGDIR/Resources/GNUstep.conf.orig" || { echo "$err_msg GNUstep config" >&2; return 1; } # If we're using GNUstep libraries that aren't in a system folder copy them diff --git a/meson.build b/meson.build index 62534cd4e..6adcd604b 100644 --- a/meson.build +++ b/meson.build @@ -15,43 +15,14 @@ project( ], ) -# ------------------------------------------------------------------------------ -# Compiler Setup & Baseline Arguments -# ------------------------------------------------------------------------------ -cc = meson.get_compiler('c') host_os = host_machine.system() -is_windows = (host_os == 'windows' or host_os == 'cygwin') - c_family = ['c', 'cpp', 'objc'] version_string = meson.project_version() add_project_arguments( '-DOO_VERSION_FULL="@0@"'.format(version_string), - '-DGNUSTEP_BASE_LIBRARY=1', language: c_family, ) -add_project_arguments( - '-fexceptions', - '-fobjc-exceptions', - language: 'objc', -) - -if cc.get_id() == 'clang' - add_project_arguments( - '-DGNUSTEP_RUNTIME=1', - '-D_NONFRAGILE_ABI=1', - '-fobjc-runtime=gnustep-2.2', - '-fblocks', - language: 'objc', - ) -else - add_project_arguments('-std=gnu99', language: ['c', 'objc']) - add_project_arguments( - '-DGNU_RUNTIME=1', - '-fobjc-runtime=gcc', - language: 'objc', - ) -endif is_debug = (get_option('optimization') == '0' or get_option('debug')) if is_debug @@ -114,20 +85,8 @@ if get_option('oo_javascript_trace') add_project_arguments('-DMOZ_TRACE_JSCALLS=1', language: c_family) endif -extra_link_args = [] -if get_option('b_lto') - if cc.get_id() == 'clang' - add_project_arguments('-flto=thin', language: c_family) - extra_link_args += [ - '-flto=thin', - '-Wl,--thinlto-cache-dir=thinlto_cache', - ] - else - add_project_arguments('-flto=auto', language: c_family) - extra_link_args += ['-flto=auto'] - endif -endif - +gnustep_folder = '' # Not needed for Windows +# dependencies, compiler/linker flags and build subdir('src') install_env_args = [ diff --git a/src/Core/Debug/meson.build b/src/Core/Debug/meson.build index 171460527..c099287a5 100644 --- a/src/Core/Debug/meson.build +++ b/src/Core/Debug/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: Debug -my_sources += files( +oolite_sources += files( 'OODebugMonitor.m', 'OODebugStandards.m', 'OODebugSupport.m', @@ -10,5 +10,5 @@ my_sources += files( 'OOTCPStreamDecoderAbstractionLayer.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/Entities/meson.build b/src/Core/Entities/meson.build index 15c77d558..5b8aa3597 100644 --- a/src/Core/Entities/meson.build +++ b/src/Core/Entities/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: Entities -my_sources += files( +oolite_sources += files( 'DockEntity.m', 'DustEntity.m', 'Entity.m', @@ -44,5 +44,5 @@ my_sources += files( 'WormholeEntity.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/Materials/meson.build b/src/Core/Materials/meson.build index cf6f130c9..a7140a8ef 100644 --- a/src/Core/Materials/meson.build +++ b/src/Core/Materials/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: Materials -my_sources += files( +oolite_sources += files( 'OOBasicMaterial.m', 'OOCombinedEmissionMapGenerator.m', 'OOConcreteTexture.m', @@ -26,5 +26,5 @@ my_sources += files( 'OOTextureLoader.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/MiniZip/meson.build b/src/Core/MiniZip/meson.build index f040cb31c..7b23573b8 100644 --- a/src/Core/MiniZip/meson.build +++ b/src/Core/MiniZip/meson.build @@ -1,9 +1,9 @@ # Generated Meson configuration for sub-module: MiniZip -my_sources += files( +oolite_sources += files( 'ioapi.c', 'unzip.c', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/OXPVerifier/meson.build b/src/Core/OXPVerifier/meson.build index f938b4872..b07550e69 100644 --- a/src/Core/OXPVerifier/meson.build +++ b/src/Core/OXPVerifier/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: OXPVerifier -my_sources += files( +oolite_sources += files( 'OOAIStateMachineVerifierStage.m', 'OOCheckDemoShipsPListVerifierStage.m', 'OOCheckEquipmentPListVerifierStage.m', @@ -16,5 +16,5 @@ my_sources += files( 'OOTextureVerifierStage.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/Scripting/meson.build b/src/Core/Scripting/meson.build index 98f759905..5d70ea8be 100644 --- a/src/Core/Scripting/meson.build +++ b/src/Core/Scripting/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: Scripting -my_sources += files( +oolite_sources += files( 'EntityOOJavaScriptExtensions.m', 'OOConstToJSString.m', 'OOJSCall.m', @@ -50,5 +50,5 @@ my_sources += files( 'OOScriptTimer.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/Tables/meson.build b/src/Core/Tables/meson.build index d0e81374c..713950276 100644 --- a/src/Core/Tables/meson.build +++ b/src/Core/Tables/meson.build @@ -1,3 +1,3 @@ # Generated Meson build file for Tables -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/Core/meson.build b/src/Core/meson.build index dcea7f361..304373e63 100644 --- a/src/Core/meson.build +++ b/src/Core/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: Core -my_sources += files( +oolite_sources += files( 'AI.m', 'AIGraphViz.m', 'CollisionRegion.m', @@ -103,7 +103,7 @@ my_sources += files( 'legacy_random.c', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') # Enter child subdirectories subdir('Debug') diff --git a/src/SDL/EXRSnapshotSupport/meson.build b/src/SDL/EXRSnapshotSupport/meson.build index 758d74b39..6d6c4122a 100644 --- a/src/SDL/EXRSnapshotSupport/meson.build +++ b/src/SDL/EXRSnapshotSupport/meson.build @@ -1,14 +1,14 @@ # Generated Meson configuration for sub-module: EXRSnapshotSupport -my_sources += files( +oolite_sources += files( 'OOSaveEXRSnapshot.cpp', ) if host_machine.system() == 'windows' - my_sources += files( + oolite_sources += files( 'miniz.c', ) endif -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/SDL/OOResourcesWin/meson.build b/src/SDL/OOResourcesWin/meson.build index e01c87867..eb653cee7 100644 --- a/src/SDL/OOResourcesWin/meson.build +++ b/src/SDL/OOResourcesWin/meson.build @@ -1,7 +1,7 @@ if host_machine.system() == 'windows' windows = import('windows') - my_sources += windows.compile_resources('OOResourcesWin.rc') + oolite_sources += windows.compile_resources('OOResourcesWin.rc') endif -my_includes += include_directories('.') +oolite_includes += include_directories('.') diff --git a/src/SDL/meson.build b/src/SDL/meson.build index f9c2ac74c..3481bf129 100644 --- a/src/SDL/meson.build +++ b/src/SDL/meson.build @@ -1,6 +1,6 @@ # Generated Meson configuration for sub-module: SDL -my_sources += files( +oolite_sources += files( 'Comparison.m', 'GameController+SDLFullScreen.m', 'MyOpenGLView.m', @@ -8,7 +8,7 @@ my_sources += files( 'main.m', ) -my_includes += include_directories('.') +oolite_includes += include_directories('.') # Enter child subdirectories subdir('EXRSnapshotSupport') diff --git a/src/meson.build b/src/meson.build index 73fa157ac..5b6fe4ed4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,8 @@ -oolite_deps = [ +oolite_sources = [] +oolite_includes = [] +oolite_override_options = [] +oolite_link_args = [] +oolite_dependencies = [ dependency('sdl3'), dependency('libpng'), dependency('openal'), @@ -9,137 +13,22 @@ oolite_deps = [ ] if get_option('espeak') - oolite_deps += [dependency('espeak-ng')] + oolite_dependencies += [dependency('espeak-ng')] add_project_arguments('-DHAVE_LIBESPEAK=1', language: c_family) endif -gnustep_folder = '' # Not needed for Windows -my_sources = [] -my_includes = [] - -if is_windows - add_project_arguments( - '-DWIN32', - '-DXP_WIN', - '-DWINVER=0x0A00', - language: c_family, - ) - extra_link_args += ['-mwindows'] - - if cc.get_id() == 'clang' and get_option('pdb') - add_project_arguments('-g', '-gcodeview', language: c_family) - extra_link_args += ['-Wl,-pdb='] - endif - - win_js_suffix = (get_option('optimization') == '0' or get_option('debug')) ? 'dbg' : '' - dep_libs = [ - 'glu32', - 'opengl32', - 'dwmapi', - 'winmm', - 'ws2_32', - 'objc', - 'gnustep-base', - 'js' + win_js_suffix, - ] - foreach lib : dep_libs - oolite_deps += [cc.find_library(lib, required: true)] - endforeach - if (cc.get_id() == 'gcc') - add_project_arguments('-DSTATIC_JS_API', language: c_family) - endif - -else - add_project_arguments('-ggdb3', '-DLINUX', '-DXP_UNIX', language: c_family) - extra_link_args += ['-ggdb3'] - - oolite_deps += [ - dependency('gl'), - dependency('glu'), - dependency('x11'), - ] - - fs = import('fs') - project_root = meson.project_source_root() - home_local = join_paths(fs.expanduser('~'), '.local') - - candidate_roots = [ - {'abs': project_root, 'rel': '..'}, - {'abs': home_local, 'rel': home_local}, - {'abs': '/usr/local', 'rel': '/usr/local'}, - {'abs': '/app', 'rel': '/app'}, - ] - js_name = is_debug ? 'jsdbg_static' : 'js_static' - js_lib = disabler() - gs_lib = disabler() - objc_lib = disabler() - js_inc = '' - gs_inc = '' - foreach root : candidate_roots - if not js_lib.found() - js_sub = (root['abs'] == project_root) ? 'build/mozilla_js' : '' - js_folder = root['abs'] / js_sub - lib_check = cc.find_library( - js_name, - dirs: [js_folder / 'lib', js_folder / 'lib64'], - required: false, - ) - if lib_check.found() - js_lib = lib_check - js_inc = root['rel'] / js_sub / 'include' - endif - endif - - if not gs_lib.found() - gs_sub = (root['abs'] == project_root) ? 'build/gnustep' : '' - gnustep_folder = root['abs'] / gs_sub - test_dirs = [gnustep_folder / 'lib', gnustep_folder / 'lib64'] - lib_check = cc.find_library( - 'gnustep-base', - dirs: test_dirs, - required: false, - ) - if lib_check.found() - gs_lib = lib_check - objc_lib = cc.find_library( - 'objc', - dirs: test_dirs, - required: true, - ) - gs_inc = root['rel'] / gs_sub / 'include' - endif - endif - - if js_lib.found() and gs_lib.found() - break - endif - endforeach - - if not js_lib.found() - error('Required dependency "@0@" was not found.'.format(js_name)) - endif - if not gs_lib.found() - error('Required dependency "gnustep-base" was not found.') - endif - - inc_dir = include_directories([js_inc, gs_inc], is_system: true) - oolite_deps += declare_dependency( - dependencies: [js_lib, gs_lib, objc_lib], - include_directories: inc_dir, - ) -endif - -# Enter child subdirectories +subdir('meson') subdir('Core') subdir('SDL') oolite_bin = executable( 'oolite', - my_sources, - include_directories: my_includes, - dependencies: oolite_deps, + oolite_sources, + include_directories: oolite_includes, + dependencies: oolite_dependencies, + override_options: oolite_override_options, + link_args: oolite_link_args, win_subsystem: 'windows', - link_args: extra_link_args, build_rpath: '$ORIGIN', install_rpath: '$ORIGIN', install: true, diff --git a/src/meson/linux/meson.build b/src/meson/linux/meson.build new file mode 100644 index 000000000..2f1ea2f30 --- /dev/null +++ b/src/meson/linux/meson.build @@ -0,0 +1,80 @@ +# Linux specific +add_project_arguments('-ggdb3', '-DLINUX', '-DXP_UNIX', language: c_family) +oolite_link_args += ['-ggdb3'] + +oolite_dependencies += [ + dependency('gl'), + dependency('glu'), + dependency('x11'), +] + +fs = import('fs') +project_root = meson.project_source_root() +shared_roots = [ + fs.expanduser('~') / '.local', + '/usr/local', + '/usr', + '/app' +] + +# ===================================================================== +# GNUSTEP BLOCK (Scan & Resolve) +# ===================================================================== +gs_search_roots = [project_root / 'build/gnustep'] + shared_roots +found_gs_dir = '' +found_gs_inc = '' + +foreach root : gs_search_roots + if found_gs_dir == '' + foreach sub_dir : ['lib', 'lib64'] + current_dir = root / sub_dir + if fs.is_file(current_dir / 'libgnustep-base.so') or fs.is_file(current_dir / 'libgnustep-base.a') + gnustep_folder = root + found_gs_dir = current_dir + found_gs_inc = root / 'include' + break + endif + endforeach + endif +endforeach + +if found_gs_dir != '' + gs_lib = cc.find_library('gnustep-base', dirs: [found_gs_dir], required: true) + objc_lib = cc.find_library('objc', dirs: [found_gs_dir], required: true) +else + error('Required dependency "gnustep-base" was not found in SEARCH_ROOTS.') +endif + +# ===================================================================== +# MOZILLA JS BLOCK (Scan & Resolve) +# ===================================================================== +js_name = is_debug ? 'jsdbg_static' : 'js_static' +js_search_roots = [project_root / 'build/mozilla_js'] + shared_roots +found_js_dir = '' +found_js_inc = '' + +foreach root : js_search_roots + if found_js_dir == '' + foreach sub_dir : ['lib', 'lib64'] + current_dir = root / sub_dir + if fs.is_file(current_dir / 'lib' + js_name + '.a') + found_js_dir = current_dir + found_js_inc = root / 'include' + break + endif + endforeach + endif +endforeach + +if found_js_dir != '' + js_lib = cc.find_library(js_name, dirs: [found_js_dir], static: true, required: true) +else + error('Required dependency "@0@" was not found in SEARCH_ROOTS.'.format(js_name)) +endif + +inc_dir = include_directories([found_gs_inc, found_js_inc], is_system: true) +oolite_dependencies += declare_dependency( + dependencies: [js_lib, gs_lib, objc_lib], + include_directories: inc_dir, +) + diff --git a/src/meson/meson.build b/src/meson/meson.build new file mode 100644 index 000000000..320aa899d --- /dev/null +++ b/src/meson/meson.build @@ -0,0 +1,51 @@ +cc = meson.get_compiler('c') +ccid = cc.get_id() + +if (host_os == 'windows' or host_os == 'cygwin') + subdir('windows') +else + subdir('linux') +endif + +if ccid == 'gcc' + oolite_override_options += 'c_std=gnu99' +endif + +if get_option('b_lto') + if ccid == 'clang' + add_project_arguments('-flto=thin', language: c_family) + oolite_link_args += [ + '-flto=thin', + '-Wl,--thinlto-cache-dir=thinlto_cache', + ] + else + add_project_arguments('-flto=auto', language: c_family) + oolite_link_args += ['-flto=auto'] + endif +endif + +add_project_arguments( + '-DGNUSTEP_BASE_LIBRARY=1', + language: c_family, +) +add_project_arguments( + '-fexceptions', + '-fobjc-exceptions', + language: 'objc', +) + +if ccid == 'clang' + add_project_arguments( + '-DGNUSTEP_RUNTIME=1', + '-D_NONFRAGILE_ABI=1', + '-fobjc-runtime=gnustep-2.2', + '-fblocks', + language: 'objc', + ) +else + add_project_arguments( + '-DGNU_RUNTIME=1', + '-fconstant-string-class=NSConstantString', + language: 'objc', + ) +endif diff --git a/src/meson/windows/meson.build b/src/meson/windows/meson.build new file mode 100644 index 000000000..558a2d56f --- /dev/null +++ b/src/meson/windows/meson.build @@ -0,0 +1,32 @@ +# Windows specific + +add_project_arguments( + '-DWIN32', + '-DXP_WIN', + '-DWINVER=0x0A00', + language: c_family, +) +oolite_link_args += ['-mwindows'] + +if ccid == 'clang' and get_option('pdb') + add_project_arguments('-g', '-gcodeview', language: c_family) + oolite_link_args += ['-Wl,-pdb='] +endif + +win_js_suffix = (get_option('optimization') == '0' or get_option('debug')) ? 'dbg' : '' +dep_libs = [ + 'glu32', + 'opengl32', + 'dwmapi', + 'winmm', + 'ws2_32', + 'objc', + 'gnustep-base', + 'js' + win_js_suffix, +] +foreach lib : dep_libs + oolite_dependencies += [cc.find_library(lib, required: true)] +endforeach +if (ccid == 'gcc') + add_project_arguments('-DSTATIC_JS_API', language: c_family) +endif