aboutsummaryrefslogtreecommitdiff
path: root/cmake/Modules/FindGettextLib.cmake
blob: c6f731e04e3b6f866508bbb1ca90be5eae8d7806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Package finder for gettext libs and include files

SET(CUSTOM_GETTEXT_PATH "${PROJECT_SOURCE_DIR}/../../gettext"
	CACHE FILEPATH "path to custom gettext")

# by default
SET(GETTEXT_FOUND FALSE)

FIND_PATH(GETTEXT_INCLUDE_DIR
	NAMES libintl.h
	PATHS "${CUSTOM_GETTEXT_PATH}/include"
	DOC "gettext include directory")

FIND_PROGRAM(GETTEXT_MSGFMT
	NAMES msgfmt
	PATHS "${CUSTOM_GETTEXT_PATH}/bin"
	DOC "path to msgfmt")

if(APPLE)
	FIND_LIBRARY(GETTEXT_LIBRARY
		NAMES libintl.a
		PATHS "${CUSTOM_GETTEXT_PATH}/lib"
		DOC "gettext *intl*.lib")

	FIND_LIBRARY(ICONV_LIBRARY
		NAMES libiconv.dylib
		PATHS "/usr/lib"
		DOC "iconv lib")
endif(APPLE)

# modern Linux, as well as Mac, seem to not need require special linking
# they do not because gettext is part of glibc
# TODO check the requirements on other BSDs and older Linux
IF (WIN32)
	IF(MSVC)
		SET(GETTEXT_LIB_NAMES
			libintl.lib intl.lib libintl3.lib intl3.lib)
	ELSE()
		SET(GETTEXT_LIB_NAMES
			libintl.dll.a intl.dll.a libintl3.dll.a intl3.dll.a)
	ENDIF()
	FIND_LIBRARY(GETTEXT_LIBRARY
		NAMES ${GETTEXT_LIB_NAMES}
		PATHS "${CUSTOM_GETTEXT_PATH}/lib"
		DOC "gettext *intl*.lib")
	FIND_FILE(GETTEXT_DLL
		NAMES libintl.dll intl.dll libintl3.dll intl3.dll
		PATHS "${CUSTOM_GETTEXT_PATH}/bin" "${CUSTOM_GETTEXT_PATH}/lib" 
		DOC "gettext *intl*.dll")
	FIND_FILE(GETTEXT_ICONV_DLL
		NAMES libiconv2.dll
		PATHS "${CUSTOM_GETTEXT_PATH}/bin" "${CUSTOM_GETTEXT_PATH}/lib"
		DOC "gettext *iconv*.lib")
ENDIF(WIN32)

IF(GETTEXT_INCLUDE_DIR AND GETTEXT_MSGFMT)
	IF (WIN32)
		# in the Win32 case check also for the extra linking requirements
		IF(GETTEXT_LIBRARY AND GETTEXT_DLL AND GETTEXT_ICONV_DLL)
			SET(GETTEXT_FOUND TRUE)
		ENDIF()
	ELSE(WIN32)
		# *BSD variants require special linkage as they don't use glibc
		IF(${CMAKE_SYSTEM_NAME} MATCHES "BSD")
			SET(GETTEXT_LIBRARY "intl")
		ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "BSD")
		SET(GETTEXT_FOUND TRUE)
	ENDIF(WIN32)
ENDIF()

IF(GETTEXT_FOUND)
	SET(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po)
	SET(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale/<locale>/LC_MESSAGES)
	SET(GETTEXT_MO_DEST_PATH ${LOCALEDIR}/<locale>/LC_MESSAGES)
	FILE(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*")
	LIST(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES minetest.pot)
	MACRO(SET_MO_PATHS _buildvar _destvar _locale)
		STRING(REPLACE "<locale>" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH})
		STRING(REPLACE "<locale>" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH})
	ENDMACRO(SET_MO_PATHS)
ELSE()
	SET(GETTEXT_INCLUDE_DIR "")
	SET(GETTEXT_LIBRARY "")
ENDIF()
>0 then -- This **might** have happened on a semi-regular basis with huge mods, -- resulting in negative statistics (perhaps midnight time jumps or ntp corrections?). core.log("warning", format( "Time travel of %s::%s by %dµs.", modname, instrument_name, time_diff )) end -- Throwing these away is better, than having them mess with the overall result. return end local mod_data = logged_data[modname] if mod_data == nil then mod_data = {} logged_data[modname] = mod_data end mod_data[instrument_name] = (mod_data[instrument_name] or 0) + time_diff -- Update logged time since last sample. logged_time = logged_time + time_diff end --- -- Return a requested statistic. -- Initialize if necessary. -- local function get_statistic(stats_table, name) local statistic = stats_table[name] if statistic == nil then statistic = setmetatable({ samples = 0, time_min = huge, time_max = 0, time_all = 0, part_min = 100, part_max = 0, part_all = 0, }, _stat_mt) stats_table[name] = statistic end return statistic end --- -- Update a statistic table -- local function update_statistic(stats_table, time) stats_table.samples = stats_table.samples + 1 -- Update absolute time (µs) spend by the subject stats_table.time_min = min(stats_table.time_min, time) stats_table.time_max = max(stats_table.time_max, time) stats_table.time_all = stats_table.time_all + time -- Update relative time (%) of this sample spend by the subject local current_part = (time/logged_time) * 100 stats_table.part_min = min(stats_table.part_min, current_part) stats_table.part_max = max(stats_table.part_max, current_part) stats_table.part_all = stats_table.part_all + current_part end --- -- Sample all logged measurements each server step. -- Like any globalstep function, this should not be too heavy, -- but does not add to the instrumentation overhead. -- local function sample(dtime) -- Rare, but happens and is currently of no informational value. if logged_time == 0 then return end for modname, instruments in pairs(logged_data) do local mod_stats = get_statistic(profile.stats, modname) if mod_stats.instruments == nil then -- Current statistics for each instrumentation component mod_stats.instruments = {} end local mod_time = 0 for instrument_name, time in pairs(instruments) do if time > 0 then mod_time = mod_time + time local instrument_stats = get_statistic(mod_stats.instruments, instrument_name) -- Update time of this sample spend by the instrumented function. update_statistic(instrument_stats, time) -- Reset logged data for the next sample. instruments[instrument_name] = 0 end end -- Update time of this sample spend by this mod. update_statistic(mod_stats, mod_time) end -- Update the total time spend over all mods. stats_total.time_min = min(stats_total.time_min, logged_time) stats_total.time_max = max(stats_total.time_max, logged_time) stats_total.time_all = stats_total.time_all + logged_time stats_total.samples = stats_total.samples + 1 logged_time = 0 end --- -- Setup empty profile and register the sampling function -- function sampler.init() sampler.reset() if core.settings:get_bool("instrument.profiler") then core.register_globalstep(function() if logged_time == 0 then return end return profiler.empty_instrument() end) core.register_globalstep(profiler.instrument { func = sample, mod = "*profiler*", class = "Sampler (update stats)", label = false, }) else core.register_globalstep(sample) end end return sampler