2019-03-17 20:26:52 -05:00
# 17 march 2019
2019-03-21 22:21:30 -05:00
# Here's the overall idea: the build syntax would be something like
# $ meson setup build \
# [--buildtype=debug|release] \ (core option, default debug)
# [--default_library=static|shared] \ (core option, default shared)
# [--b_sanitize=whatever]
# It turns out that I wouldn't really need any custom options; go figure.
# I'm not sure how to allow building 32-bit instead of 64-bit with meson.
# I'd also like all the outputs to appear in a folder out/ in the build folder.
# I'd also like to be able to omit the library's dependency libraries in the executables if building a shared library, as those are not required in that case; I'd need to require them in a static library.
# And for Windows, the shared library (but not shared executables) needs an additional resource file, and the static executables (but not the static library) need a *different* resource file. (Windows static libraries can't contain resources anyway; the linkers will just ignore the resource objects.)
2019-03-23 15:18:13 -05:00
# we have to specify C++ here even if we're not using C++ immediately because otherwise none of the C++ built-in options are available (sigh; TODO)
2019-03-23 20:06:19 -05:00
project ( 'libui' , [ 'c' , 'cpp' ] ,
2019-03-23 20:50:54 -05:00
meson_version : '>=0.48.0' ,
2019-03-23 15:18:13 -05:00
default_options : [
'buildtype=debug' , # build debug by default
'default_library=shared' , # build shared libraries by default
# these are forced options, but meson doesn't let me set these up separately before I call project() (TODO)
'warning_level=3' , # always max warnings
'b_pch=false' , # we don't want precompiled headers
'b_staticpic=true' , # use PIC even for static libraries
'c_std=c99' , # strict C99
2019-03-24 11:57:25 -05:00
'c_winlibs=' , # we define our own Windows libraries
2019-03-23 15:18:13 -05:00
'cpp_std=c++11' , # strict C++11
'cpp_eh=sc' , # shut the compiler up in some cases
2019-03-24 11:57:25 -05:00
'cpp_winlibs=' , # likewise as with c_winlibs
2019-03-23 15:18:13 -05:00
] ,
license : 'MIT' )
# TODO move these below the next part (I need them here for other reasons)
libui_OS = host_machine . system ( )
libui_MSVC = meson . get_compiler ( 'c' ) . get_id ( ) == 'msvc'
2019-03-23 20:06:19 -05:00
if libui_OS == 'darwin'
2019-03-23 20:50:54 -05:00
add_languages ( 'objc' ,
2019-03-23 20:06:19 -05:00
required : true )
endif
2019-03-21 22:21:30 -05:00
# TODO switch to tabs; the spaces are just so I can share this file while I'm writing it
2019-03-17 20:26:52 -05:00
libui_forced_options = {
2019-03-21 22:21:30 -05:00
'warning_level' : '3' , # always max warnings
'b_pch' : 'false' , # we don't want precompiled headers
'b_staticpic' : 'true' , # use PIC even for static libraries
'c_std' : 'c99' , # strict C99
2019-03-24 11:57:25 -05:00
'c_winlibs' : '[]' , # we define our own Windows libraries
2019-03-21 22:21:30 -05:00
'cpp_std' : 'c++11' , # strict C++11
'cpp_eh' : 'sc' , # shut the compiler up in some cases
2019-03-24 11:57:25 -05:00
'cpp_winlibs' : '[]' , # likewise as with c_winlibs
2019-03-17 20:26:52 -05:00
}
foreach name , value : libui_forced_options
2019-03-24 11:57:25 -05:00
# TODO why does meson need this guard? why aren't all options defined regardless of target?!
2019-03-24 13:11:02 -05:00
if not ( ( name == 'c_winlibs' or name == 'cpp_eh' or name == 'cpp_winlibs' ) and not libui_MSVC ) and not ( name == 'c_std' and libui_MSVC )
2019-03-23 15:18:13 -05:00
actual = '@0@' . format ( get_option ( name ) )
if actual != value
error ( 'sorry, but libui requires that option ' + name + ' has the default value ' + value )
endif
2019-03-17 20:26:52 -05:00
endif
endforeach
libui_mode = get_option ( 'default_library' )
if libui_mode == 'both'
error ( 'sorry, but libui does not support building both shared and static libraries at the same time, because Windows resource file rules differ between the two' )
endif
2019-03-25 09:46:41 -05:00
libui_is_debug = get_option ( 'buildtype' ) . startswith ( 'debug' )
2019-03-23 14:42:42 -05:00
2019-03-23 21:28:17 -05:00
if libui_OS == 'darwin'
2019-03-23 14:42:42 -05:00
# TODO see if there's a more direct way to set this
libui_macosx_version_min = '-mmacosx-version-min=10.8'
2019-03-23 15:18:13 -05:00
add_project_arguments ( libui_macosx_version_min ,
# TODO WHY IS THIS NEEDED MESON
language : [ 'c' , 'cpp' , 'objc' ] )
add_project_link_arguments ( libui_macosx_version_min ,
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-17 20:26:52 -05:00
endif
2019-03-23 14:42:42 -05:00
# TODO see if there's a more direct way to set any of these
2019-03-21 10:23:30 -05:00
if libui_MSVC
# TODO subsystem version
2019-03-21 22:21:30 -05:00
# TODO is there a -Wno-switch equivalent?
2019-03-21 10:23:30 -05:00
# TODO /sdl turns C4996 into an ERROR
# don't use /analyze; that requires us to write annotations everywhere
# TODO undecided flags from qo?
# the RTC flags are only supplied in debug builds because they are only supposed to be used by debug builds (see "This is because run-time error checks are not valid in a release (optimized) build." in https://docs.microsoft.com/cpp/build/reference/rtc-run-time-error-checks)
# /RTCc is not supplied because it's discouraged as of VS2015; see https://www.reddit.com/r/cpp/comments/46mhne/rtcc_rejects_conformant_code_with_visual_c_2015/d06auq5
# TODO add these compiler flags (assuming meson doesn't provide an alternate method for these, which I know it does for EHsc):
2019-03-23 14:42:42 -05:00
add_project_arguments (
'/wd4100' ,
2019-03-25 19:17:42 -05:00
'/bigobj' ,
2019-03-23 15:18:13 -05:00
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-23 14:42:42 -05:00
if libui_is_debug
2019-03-23 15:18:13 -05:00
add_project_arguments ( '/RTC1' , '/RTCs' , '/RTCu' ,
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-23 14:42:42 -05:00
endif
2019-03-21 10:23:30 -05:00
2019-03-23 14:42:42 -05:00
add_project_link_arguments (
'/LARGEADDRESSAWARE' ,
'/INCREMENTAL:NO' ,
2019-03-23 15:18:13 -05:00
'/MANIFEST:NO' ,
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-21 10:23:30 -05:00
else
2019-03-23 14:42:42 -05:00
add_project_arguments (
'-Wno-unused-parameter' ,
2019-03-23 15:18:13 -05:00
'-Wno-switch' ,
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-21 10:23:30 -05:00
if libui_OS == 'windows'
# don't require shipping the MinGW-w64 DLLs
2019-03-23 14:42:42 -05:00
add_project_link_arguments (
'-static' ,
'-static-libgcc' ,
2019-03-23 15:18:13 -05:00
'-static-libstdc++' ,
language : [ 'c' , 'cpp' , 'objc' ] )
2019-03-21 10:23:30 -05:00
endif
endif
2019-03-24 13:11:02 -05:00
libui_manifest_args = [ ]
if libui_mode == 'static'
add_project_arguments ( '-D_UI_STATIC' ,
language : [ 'c' , 'cpp' , 'objc' ] )
libui_manifest_args = [ '-D_UI_STATIC' ]
endif
2019-03-17 20:26:52 -05:00
libui_sources = [ ]
2019-03-23 21:28:17 -05:00
libui_deps = [ ]
libui_soversion = ''
libui_rpath = ''
2019-03-17 20:26:52 -05:00
subdir ( 'common' )
if libui_OS == 'windows'
subdir ( 'windows' )
install_headers ( 'ui_windows.h' )
elif libui_OS == 'darwin'
subdir ( 'darwin' )
install_headers ( 'ui_darwin.h' )
else
subdir ( 'unix' )
install_headers ( 'ui_unix.h' )
endif
libui_libui = library ( 'ui' , libui_sources ,
dependencies : libui_deps ,
build_rpath : libui_rpath ,
install_rpath : libui_rpath ,
2019-03-25 09:29:18 -05:00
name_prefix : 'lib' , # always call it libui, even in Windows DLLs
2019-03-17 20:26:52 -05:00
install : true ,
2019-03-21 10:23:30 -05:00
gnu_symbol_visibility : 'hidden' ,
2019-03-23 17:12:33 -05:00
c_args : [ '-Dlibui_EXPORTS' ] ,
cpp_args : [ '-Dlibui_EXPORTS' ] ,
objc_args : [ '-Dlibui_EXPORTS' ] ,
soversion : libui_soversion ,
darwin_versions : [ ] ) # TODO
2019-03-17 20:26:52 -05:00
install_headers ( 'ui.h' )
2019-03-25 19:52:49 -05:00
# TODO when the API is stable enough to be versioned, create a pkg-config file (https://mesonbuild.com/Pkgconfig-module.html) and a declare_dependency() section too
2019-03-23 17:12:33 -05:00
libui_binary_deps = [ ]
if libui_mode == 'static'
libui_binary_deps = libui_deps
endif
subdir ( 'test' )
2019-03-24 16:26:15 -05:00
subdir ( 'examples' )