Skip to content

Commit

Permalink
Add LUA_TYPE build option.
Browse files Browse the repository at this point in the history
Add missing SCons.Util import.

Issue #216.
Issue #217.
  • Loading branch information
thezbyg committed Jun 1, 2023
1 parent a8bc29c commit cfcfd4c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ option(ENABLE_NLS "compile with gettext support" true)
option(USE_GTK3 "use GTK3 instead of GTK2" true)
option(DEV_BUILD "use development flags" false)
option(PREFER_VERSION_FILE "read version information from file instead of using GIT" false)
option(LUA_TYPE "Lua library type (one of \"C++\", \"patched-C++\" or \"C\")" "patched-C++")
set(LUA_TYPES C++ patched-C++ C)
set_property(CACHE LUA_TYPE PROPERTY STRINGS ${LUA_TYPES})
if(NOT LUA_TYPE IN_LIST LUA_TYPES)
message(FATAL_ERROR "LUA_TYPE must be one of ${LUA_TYPES}")
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
file(GLOB SOURCES
source/*.cpp source/*.h
Expand All @@ -25,16 +32,24 @@ include(Version)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/source/version/Version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Version.cpp" @ONLY)
list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Version.cpp")
find_package(Boost 1.58 COMPONENTS unit_test_framework REQUIRED)
find_package(PkgConfig)
find_package(PkgConfig REQUIRED)
if (PkgConfig_FOUND)
if (USE_GTK3)
pkg_check_modules(GTK3 gtk+-3.0>=3.0)
pkg_search_module(GTK3 REQUIRED gtk+-3.0>=3.0)
else()
pkg_search_module(GTK2 REQUIRED gtk+-2.0>=2.24)
pkg_search_module(GioUnix REQUIRED gio-unix-2.0>=2.24)
endif()
if (NOT LUA_TYPE STREQUAL CURRENT_LUA_TYPE)
unset(Lua_FOUND CACHE)
endif()
if (NOT LUA_TYPE STREQUAL "C")
pkg_search_module(Lua REQUIRED lua5.4-c++>=5.4 lua5-c++>=5.4 lua-c++>=5.4 lua5.3-c++>=5.3 lua5-c++>=5.3 lua-c++>=5.3 lua5.2-c++>=5.2 lua5-c++>=5.2 lua-c++>=5.2)
else()
pkg_check_modules(GTK2 gtk+-2.0>=2.24)
pkg_check_modules(GioUnix gio-unix-2.0>=2.24)
pkg_search_module(Lua REQUIRED lua5.4>=5.4 lua5>=5.4 lua>=5.4 lua5.3>=5.3 lua5>=5.3 lua>=5.3 lua5.2>=5.2 lua5>=5.2 lua>=5.2)
endif()
pkg_search_module(Lua lua5.4-c++>=5.4 lua5-c++>=5.4 lua5.3-c++>=5.3 lua5-c++>=5.3 lua-c++>=5.3 lua5.2-c++>=5.2 lua-c++>=5.2)
pkg_check_modules(Expat expat>=1.0)
set(CURRENT_LUA_TYPE ${LUA_TYPE} CACHE INTERNAL "")
pkg_search_module(Expat REQUIRED expat>=1.0)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -213,6 +228,11 @@ target_include_directories(tests PRIVATE
${Lua_INCLUDE_DIRS}
${Expat_INCLUDE_DIRS}
)
if (LUA_TYPE STREQUAL "C++")
target_compile_definitions(gpick PRIVATE LUA_SYMBOLS_MANGLED)
target_compile_definitions(gpick-lua PRIVATE LUA_SYMBOLS_MANGLED)
target_compile_definitions(tests PRIVATE LUA_SYMBOLS_MANGLED)
endif()

install(TARGETS gpick DESTINATION bin)
install(FILES share/metainfo/org.gpick.gpick.metainfo.xml DESTINATION share/metainfo)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ ENABLE\_NLS - compile with gettext support. Enabled by default.
USE\_GTK3 - use GTK3 instead of GTK2. Enabled by default.

PREFER\_VERSION\_FILE - read version information from file instead of using GIT. Disabled by default. This option enables unconditional `.version` file usage. `.version` file is included in release source archives and is a simple text file containing the following information in four lines: major/minor version, revision, commit hash and commit date.

LUA\_TYPE - select used Lua library type. Default is `patched-C++`. Can be set to one of the following values:

* `C++` - compiled with C++ compiler and API function symbols are mangled.
* `patched-C++` - compiled with C++ compiler, but API functions are defined as `extern "C"` and symbols are not mangled.
* `C` - compiled with C compiler (this is the default Lua library build type).
24 changes: 19 additions & 5 deletions SConscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# coding: utf-8
import os, string, sys, shutil, math
import os, string, sys, shutil, math, SCons.Util
from tools import *

env = GpickEnvironment(ENV = os.environ)
Expand All @@ -17,6 +17,7 @@ vars.Add(BoolVariable('PREBUILD_GRAMMAR', 'Use prebuild grammar files', False))
vars.Add(BoolVariable('USE_GTK3', 'Use GTK3 instead of GTK2', True))
vars.Add(BoolVariable('DEV_BUILD', 'Use development flags', False))
vars.Add(BoolVariable('PREFER_VERSION_FILE', 'Read version information from file instead of using GIT', False))
vars.Add(EnumVariable('LUA_TYPE', 'Lua library type', 'patched-C++', allowed_values = ('C++', 'patched-C++', 'C')))
vars.Update(env)

if env['LOCALEDIR'] == '':
Expand Down Expand Up @@ -77,7 +78,10 @@ if not env.GetOption('clean'):
libs['GIO_PC'] = {'checks':{'gio-unix-2.0': '>= 2.26.0', 'gio-2.0': '>= 2.26.0'}}
else:
libs['GTK_PC'] = {'checks':{'gtk+-3.0': '>= 3.0.0'}}
libs['LUA_PC'] = {'checks':{'lua5.4-c++': '>= 5.4', 'lua5.3-c++': '>= 5.3', 'lua-c++': '>= 5.2', 'lua5.2-c++': '>= 5.2'}}
if env['LUA_TYPE'] != 'C':
libs['LUA_PC'] = {'checks':{'lua5.4-c++': '>= 5.4', 'lua5-c++': '>= 5.4', 'lua-c++': '>= 5.4', 'lua5.3-c++': '>= 5.3', 'lua5-c++': '>= 5.3', 'lua-c++': '>= 5.3', 'lua5.2-c++': '>= 5.2', 'lua5-c++': '>= 5.2', 'lua-c++': '>= 5.2'}}
else:
libs['LUA_PC'] = {'checks':{'lua5.4': '>= 5.4', 'lua5': '>= 5.4', 'lua': '>= 5.4', 'lua5.3': '>= 5.3', 'lua5': '>= 5.3', 'lua': '>= 5.3', 'lua5.2': '>= 5.2', 'lua5': '>= 5.2', 'lua': '>= 5.2'}}
env.ConfirmLibs(conf, libs)
env.ConfirmBoost(conf, '1.71')
env = conf.Finish()
Expand Down Expand Up @@ -155,19 +159,23 @@ def buildLayout(env):
if not env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
layout_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
layout_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
if env['LUA_TYPE'] == 'C++':
layout_env.Append(CPPDEFINES = ['LUA_SYMBOLS_MANGLED'])
return layout_env.StaticObject(layout_env.Glob('source/layout/*.cpp'))

def buildGtk(env):
gtk_env = env.Clone()
if not env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
gtk_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
gtk_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
if env['LUA_TYPE'] == 'C++':
gtk_env.Append(CPPDEFINES = ['LUA_SYMBOLS_MANGLED'])
return gtk_env.StaticObject(gtk_env.Glob('source/gtk/*.cpp'))

def buildI18n(env):
i18n_env = env.Clone()
if not env.GetOption('clean'):
if i18n_env['ENABLE_NLS']:
if env['ENABLE_NLS']:
i18n_env.Append(CPPDEFINES = ['ENABLE_NLS', 'LOCALEDIR=' + i18n_env['LOCALEDIR']])
return i18n_env.StaticObject(i18n_env.Glob('source/i18n/*.cpp'))

Expand All @@ -189,15 +197,19 @@ def buildTools(env):
if not env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
tools_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
tools_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
if tools_env['ENABLE_NLS']:
if env['ENABLE_NLS']:
tools_env.Append(CPPDEFINES = ['ENABLE_NLS'])
if env['LUA_TYPE'] == 'C++':
tools_env.Append(CPPDEFINES = ['LUA_SYMBOLS_MANGLED'])
return tools_env.StaticObject(tools_env.Glob('source/tools/*.cpp'))

def buildLua(env):
lua_env = env.Clone()
if not env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
lua_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
lua_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
if env['LUA_TYPE'] == 'C++':
lua_env.Append(CPPDEFINES = ['LUA_SYMBOLS_MANGLED'])
return lua_env.StaticObject(lua_env.Glob('source/lua/*.cpp'))

def buildColorNames(env):
Expand Down Expand Up @@ -225,6 +237,8 @@ def buildGpick(env):
gpick_env.ParseConfig('pkg-config --cflags --libs $LUA_PC', None, False)
if env['ENABLE_NLS']:
gpick_env.Append(CPPDEFINES = ['ENABLE_NLS'])
if env['LUA_TYPE'] == 'C++':
gpick_env.Append(CPPDEFINES = ['LUA_SYMBOLS_MANGLED'])
gpick_env.Append(CPPDEFINES = ['GSEAL_ENABLE'])
sources = gpick_env.Glob('source/*.cpp') + gpick_env.Glob('source/transformation/*.cpp')

Expand Down Expand Up @@ -273,7 +287,7 @@ def buildGpick(env):
test_env = gpick_env.Clone()
test_env.Append(LIBS = ['boost_unit_test_framework'], CPPDEFINES = ['BOOST_TEST_DYN_LINK'])

tests = test_env.Program('tests', source = test_env.Glob('source/test/*.cpp') + [object_map['source/' + name] for name in ['Color', 'EventBus', 'lua/Script', 'lua/Ref', 'lua/Color', 'lua/ColorObject', 'ColorList', 'ColorObject', 'FileFormat', 'ErrorCode', 'Converter', 'Converters', 'InternalConverters', 'version/Version']] + dynv_objects + text_file_parser_objects + common_objects)
tests = test_env.Program('tests', source = test_env.Glob('source/test/*.cpp') + [object_map['source/' + name] for name in ['Color', 'EventBus', 'lua/Script', 'lua/Ref', 'lua/Color', 'lua/ColorObject', 'ColorList', 'ColorObject', 'FileFormat', 'ErrorCode', 'Converter', 'Converters', 'InternalConverters', 'math/BinaryTreeQuantization', 'math/OctreeColorQuantization', 'version/Version']] + dynv_objects + text_file_parser_objects + common_objects)

return executable, tests

Expand Down
4 changes: 4 additions & 0 deletions source/lua/Lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

#ifndef GPICK_LUA_LUA_H_
#define GPICK_LUA_LUA_H_
#ifndef LUA_SYMBOLS_MANGLED
extern "C" {
#endif
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#ifndef LUA_SYMBOLS_MANGLED
}
#endif
#endif /* GPICK_LUA_LUA_H_ */

0 comments on commit cfcfd4c

Please sign in to comment.