-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathCMakeLists.txt
193 lines (175 loc) · 7.64 KB
/
CMakeLists.txt
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
cmake_minimum_required(VERSION 3.12)
project(tilibs C CXX)
############################
# CMake support for tilibs #
############################
#
# This aims to provide a much simpler way to build and install libti* on
# computers that have decent and recent OS and toolchains.
# As a bonus, it provides better support for CMake-oriented IDE (e.g. CLion).
#
# Features:
# - builds and installs both shared and static libraries
# - installs the public headers of each library
# - creates and installs i18n .mo files (when libs/tools are present)
# - configures and installs the .pc files for pkg-config
#
# Caveats:
# - no support for the ROM dumpers subdirectories
# - not all the autotools/configure options are available
# - no updatepot/updatepo targets are available, but simply executing intltool-update does the job...
# - probably doesn't work very well with ancient toolchains or on uncommon OSes
#
# Notes:
# - this has been succesfully tested on recent macOS, Linux, and Windows (with vcpkg).
# - The TRY_STATIC_LIBS CMake option will try to build the libs (both shared and static) using as many static
# dependent libraries as possible.
# Let's note however that there is currently not much advantage in building that way, using shared libs is preferred,
# but at least you have the choice to do whatever you want should you ever really need a static build (may be useful on Windows)
#
# In the future...:
# - TODO: add support to build the ROM dumpers (will end up just launching the external tools...)
# - WISH: do not hardcode the (auto-generated...) potfiles_* target names
# - WISH: better expose each lib's generated install target (NTS: look at cmake's components feature?)
# - WISH: provide Find* CMake modules for the libs themselves?
#
# In case there was an env-var override...
if(DEFINED ENV{CMAKE_INSTALL_PREFIX_OVERRIDE})
set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX_OVERRIDE}")
endif()
# Be sure to have the expected install prefix format
if(CMAKE_INSTALL_PREFIX)
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "CMAKE_INSTALL_PREFIX" FORCE)
message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
endif()
# Our modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.cmake)
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/.cmake/*.cmake")
foreach(file ${files})
include(${file})
endforeach()
set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
message(STATUS "Detected system: ${CMAKE_SYSTEM_NAME} - host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR} - CXX_COMPILER: ${CMAKE_CXX_COMPILER_ID}")
if(CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
message(STATUS "IPO/LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO/LTO not supported: <${error}>")
endif()
else()
message("IPO/LTO not enabled because this is not a release build")
endif()
option(TRY_STATIC_LIBS "Build using as many static libs as possible" OFF)
if (VCPKG_TARGET_TRIPLET MATCHES "-static")
if(NOT TRY_STATIC_LIBS)
message(WARNING "Setting TRY_STATIC_LIBS to ON anyway due to static vcpkg target")
set(TRY_STATIC_LIBS ON)
endif()
endif()
if(TRY_STATIC_LIBS)
message("Will try to build as statically as possible...")
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
# When we link statically, we don't want the dllimport stuff, so let's workaround that here
add_compile_definitions(TICALCS_EXPORTS TIFILES_EXPORTS TICONV_EXPORTS TICABLES_EXPORTS)
endif()
include(GNUInstallDirs)
include(CheckSymbolExists)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# sane defaults + hardening
set(GLOBAL_COMPILE_FLAGS "-W -Wall -Wextra -Wno-unused-parameter -Werror=shadow -Werror=write-strings -Wredundant-decls -Werror=date-time -Werror=return-type -Werror=pointer-arith")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLOBAL_COMPILE_FLAGS}")
# useful flags for debugging
set(GLOBAL_DEBUG_FLAGS "-fno-omit-frame-pointer -fsanitize=address,bounds -fsanitize-undefined-trap-on-error")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
# only for clang/gcc
add_compile_definitions(HAVE_FVISIBILITY=1)
endif()
if(APPLE)
add_compile_definitions(__MACOSX__)
elseif(UNIX)
add_compile_definitions(__LINUX__)
set(LINUX TRUE)
elseif(MINGW)
add_compile_definitions(__MINGW32__)
elseif(WIN32)
add_compile_definitions(__WIN32__)
add_compile_definitions(HAVE_CONFIG_H)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
include_directories(${CMAKE_SOURCE_DIR}/win32_config)
endif()
# i18n support checking
include(FindGettext)
include(FindIntl)
if(Intl_FOUND AND GETTEXT_FOUND)
set(ENABLE_NLS 1)
include_directories(${Intl_INCLUDE_DIR})
add_compile_definitions(ENABLE_NLS=1)
if(TRY_STATIC_LIBS)
# needed by __nl_find_msg in libintl.a(dcigettext.o)...
find_package(Iconv REQUIRED)
if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN)
include_directories(${Iconv_INCLUDE_DIRS})
if(Iconv_LIBRARY_DIRS)
link_directories(${Iconv_LIBRARY_DIRS})
endif()
link_libraries(${Iconv_LIBRARIES})
endif()
else()
link_directories(${Intl_LIBRARY_DIRS})
link_libraries(${Intl_LIBRARIES})
endif()
else()
message(WARNING "The Intl and GetText libs are needed for translations - Only English will be available")
endif()
set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
# Global defines
add_compile_definitions(LOCALEDIR="${LOCALEDIR}")
check_symbol_exists(ctime_r "time.h" HAVE_CTIME_R)
check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
check_symbol_exists(asctime_r "time.h" HAVE_ASCTIME_R)
if(HAVE_CTIME_R)
add_compile_definitions(HAVE_CTIME_R=1)
endif()
if(HAVE_LOCALTIME_R)
add_compile_definitions(HAVE_LOCALTIME_R=1)
endif()
if(HAVE_ASCTIME_R)
add_compile_definitions(HAVE_ASCTIME_R=1)
endif()
# For libs finding
find_package(PkgConfig)
# Set manually when installed with Homebrew, see https://github.com/Homebrew/legacy-homebrew/issues/45891
# Note: we can't do the same for libiconv because it exports libiconv_* symbols and not iconv_*, so we fallback on the non-static system lib...
if(APPLE)
set(BREW_LIB_PATHS "/opt/homebrew/lib" "/usr/local/opt" "/usr/local/lib")
foreach(LIB_DIR ${BREW_LIB_PATHS})
if(EXISTS "${LIB_DIR}/libarchive/lib/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "${LIB_DIR}/libarchive/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
break()
endif()
endforeach()
endif()
add_subdirectory(libticonv/trunk)
add_subdirectory(libtifiles/trunk)
add_subdirectory(libticables/trunk)
add_subdirectory(libticalcs/trunk)
add_custom_target(check
DEPENDS ticonv_check tifiles2_check ticables2_check ticalcs2_check
COMMENT "Run all torture tests"
EXCLUDE_FROM_ALL
)