Skip to content

Commit 4a151f4

Browse files
committed
[cmake] Try to make it work again
1 parent 49e62e4 commit 4a151f4

File tree

8 files changed

+366
-239
lines changed

8 files changed

+366
-239
lines changed

CMakeLists.txt

+155-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818
################################################################################
1919

20-
cmake_minimum_required(VERSION 2.8.12)
20+
cmake_minimum_required(VERSION 3.15)
2121

2222
# In-source builds are not possible and so disabled.
2323
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
@@ -84,6 +84,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir})
8484
if (MSVC OR XCODE)
8585
set(output_dir ${output_dir}/$<CONFIG>)
8686
set(boot_dir ${boot_dir}/$<CONFIG>)
87+
elseif (MINGW)
88+
set(output_dir ${CMAKE_BINARY_DIR})
8789
endif()
8890

8991
if (MSVC AND DEFAULT_CONFIGURATION)
@@ -98,7 +100,7 @@ if (XCODE)
98100
string(TOUPPER ${conf} conf2)
99101
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${conf2} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${conf}/bin)
100102
endforeach()
101-
elseif (UNIX)
103+
elseif (UNIX OR MINGW)
102104
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${output_dir}/bin)
103105
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir}/bin)
104106
endif()
@@ -147,8 +149,8 @@ endif()
147149

148150
include(Configure)
149151

150-
if (FREEBSD)
151-
# temporary
152+
if (FREEBSD OR MINGW)
153+
# Build-time temporary installation path
152154
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
153155
endif()
154156

@@ -159,10 +161,33 @@ set(FB_SERVICE_NAME "gds_db")
159161
set(FB_SERVICE_PORT 3050)
160162

161163
if (WIN32)
162-
set(FB_PREFIX "c:\\\\Program Files\\\\Firebird\\\\")
164+
if (MSVC)
165+
set(FB_PREFIX "c:\\\\Program Files\\\\Firebird\\\\")
166+
else()
167+
set(FB_PREFIX ${CMAKE_INSTALL_PREFIX})
168+
endif()
163169
set(FB_IPC_NAME "FIREBIRD")
164170
endif()
165171

172+
if (MINGW)
173+
set(FB_BINDIR "${FB_PREFIX}/bin")
174+
set(FB_SBINDIR "${FB_PREFIX}/bin")
175+
set(FB_INCDIR "${FB_PREFIX}/include")
176+
set(FB_LIBDIR "${FB_PREFIX}/lib")
177+
set(FB_CONFDIR "${FB_PREFIX}/etc/firebird")
178+
set(FB_GUARDDIR "${FB_PREFIX}/etc/firebird")
179+
set(FB_LOGDIR "${FB_PREFIX}/etc/firebird")
180+
set(FB_MSGDIR "${FB_PREFIX}/etc/firebird")
181+
set(FB_SECDBDIR "${FB_PREFIX}/etc/firebird")
182+
set(FB_DOCDIR "${FB_PREFIX}/share/firebird/doc")
183+
set(FB_INTLDIR "${FB_PREFIX}/share/firebird/intl")
184+
set(FB_MISCDIR "${FB_PREFIX}/share/firebird/misc")
185+
set(FB_PLUGDIR "${FB_PREFIX}/share/firebird/plugins")
186+
set(FB_SAMPLEDBDIR "${FB_PREFIX}/share/firebird/examples/empbuild")
187+
set(FB_SAMPLEDIR "${FB_PREFIX}/share/firebird/examples")
188+
set(FB_TZDATADIR "${FB_PREFIX}/share/firebird/tzdata")
189+
endif()
190+
166191
set(AUTOCONFIG_SRC ${CMAKE_SOURCE_DIR}/src/include/gen/autoconfig.h.in)
167192
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/src/include/gen/autoconfig.h)
168193
configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
@@ -173,7 +198,9 @@ configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
173198
#
174199
################################################################################
175200

176-
add_definitions(-DDEV_BUILD)
201+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
202+
add_definitions(-DDEV_BUILD)
203+
endif()
177204

178205
if (WIN32)
179206
set(OS_DIR win32)
@@ -192,20 +219,71 @@ if (WIN32)
192219
endif()
193220
endif(MSVC)
194221

195-
set(LIB_Ws2_32 Ws2_32)
222+
set(LIB_ws2_32 ws2_32)
196223
set(LIB_comctl32 comctl32)
197224
set(LIB_mpr mpr)
198225
set(LIB_version version)
199226
endif(WIN32)
200227

201228
if (MINGW)
202-
# clear unix-style prefixes
229+
# Clear unix-style prefixes
203230
set(CMAKE_SHARED_LIBRARY_PREFIX)
204231
set(CMAKE_SHARED_MODULE_PREFIX)
205232
set(CMAKE_STATIC_LIBRARY_PREFIX)
206233

207-
add_definitions(-D_WIN32_WINNT=0x0600)
234+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
235+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
236+
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DDEBUG")
237+
else()
238+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
239+
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DNDEBUG")
240+
endif()
241+
242+
add_definitions(-DMINGW_HAS_SECURE_API -DTTMATH_NOASM)
243+
244+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shift-count-overflow")
208245
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4 -std=c++17")
246+
247+
# Suppress myriad of warnings
248+
set(cxx_flags "")
249+
list(APPEND cxx_flags
250+
-Wundef
251+
-Wno-format
252+
-Wno-deprecated-declarations
253+
-Wno-ignored-attributes
254+
-Wno-invalid-offsetof
255+
-Wno-long-long
256+
-Wno-non-virtual-dtor
257+
-Wno-parentheses
258+
-Wno-shift-count-overflow
259+
-Wno-sign-compare
260+
-Wno-switch
261+
-Wno-unused-variable
262+
-Wno-write-strings
263+
)
264+
if (CLANG)
265+
list(APPEND cxx_flags
266+
-Wno-varargs
267+
-Wno-constant-conversion
268+
-Wno-inconsistent-missing-override
269+
-Wno-tautological-constant-out-of-range-compare
270+
-Wno-c++11-narrowing
271+
)
272+
else()
273+
list(APPEND cxx_flags
274+
-Wno-class-memaccess
275+
-Wno-overflow
276+
-Wno-return-local-addr
277+
-Wno-stringop-overflow
278+
-Wno-stringop-overread
279+
-Wno-narrowing
280+
)
281+
endif()
282+
string(REPLACE ";" " " cxx_flags "${cxx_flags}")
283+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_flags}")
284+
285+
set(LIB_iconv iconv)
286+
set(LIB_re2 re2)
209287
endif()
210288

211289
if (UNIX)
@@ -214,8 +292,12 @@ if (UNIX)
214292
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
215293
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -msse4 -std=c++17")
216294

295+
set(FB_INTERNAL_TOMMATH ON)
296+
set(FB_INTERNAL_EDITLINE ON)
297+
298+
set(LIB_re2 re2)
217299
if (NOT CMAKE_CROSSCOMPILING)
218-
set(LIB_readline readline)
300+
set(LIB_editline editline)
219301
endif()
220302
if (NOT FREEBSD)
221303
set(LIB_dl dl)
@@ -251,7 +333,7 @@ endif()
251333
#
252334
################################################################################
253335

254-
if (WIN32)
336+
if (MSVC)
255337
# icu
256338
if (NOT ICU_EXTRACT)
257339
message(STATUS "Extracting pre-built ICU")
@@ -324,29 +406,50 @@ if (NOT CMAKE_CROSSCOMPILING)
324406
create_boot_commands()
325407
create_master_commands()
326408

327-
endif() # if (NOT CMAKE_CROSSCOMPILING)
409+
endif() # (NOT CMAKE_CROSSCOMPILING)
328410

329411
crosscompile_prebuild_steps()
330412

331-
include_directories("extern/libtommath")
332-
include_directories("extern/libtomcrypt/src/headers")
413+
if (FB_INTERNAL_TOMMATH)
414+
include_directories("extern/libtommath")
415+
include_directories("extern/libtomcrypt/src/headers")
416+
set(LIB_tommath libtommath)
417+
set(LIB_tomcrypt libtomcrypt)
418+
else()
419+
set(LIB_tommath tommath)
420+
set(LIB_tomcrypt tomcrypt)
421+
endif()
422+
423+
if (UNIX)
424+
if (FB_INTERNAL_EDITLINE)
425+
include_directories("extern/editline")
426+
endif()
427+
endif()
428+
333429
include_directories("extern/decNumber")
334-
include_directories("extern/icu/include")
335-
include_directories("extern/zlib")
430+
include_directories("extern/libcds")
431+
include_directories("extern/re2")
432+
433+
if (MSVC OR ANDROID)
434+
include_directories("extern/icu/include")
435+
include_directories("extern/zlib")
436+
endif()
336437

337438
include_directories("src/include")
338439
include_directories("src/include/gen")
339440
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/include")
340441
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/include/gen")
341442

443+
444+
if (FB_INTERNAL_TOMMATH)
342445
########################################
343446
# LIBRARY libtommath
344447
########################################
345448

346449
file(GLOB libtommath_src "extern/libtommath/*.c" "extern/libtommath/*.h")
347450

348-
add_library (libtommath ${libtommath_src})
349-
project_group (libtommath Extern)
451+
add_library (libtommath ${libtommath_src})
452+
project_group (libtommath Extern)
350453

351454

352455
########################################
@@ -362,6 +465,8 @@ add_library (libtomcrypt ${libtomcrypt_src})
362465
target_compile_definitions (libtomcrypt PRIVATE LTC_NO_ROLC LTC_SOURCE)
363466
project_group (libtomcrypt Extern)
364467

468+
endif() # (FB_INTERNAL_TOMMATH)
469+
365470

366471
########################################
367472
# LIBRARY decNumber
@@ -375,6 +480,30 @@ add_library (decNumber ${decNumber_src})
375480
project_group (decNumber Extern)
376481

377482

483+
if (FB_INTERNAL_EDITLINE)
484+
########################################
485+
# LIBRARY editline
486+
########################################
487+
488+
file(GLOB editline_src "extern/editline/src/*.c" "extern/editline/src/*.h")
489+
490+
add_library (editline ${editline_src})
491+
project_group (editline Extern)
492+
493+
endif() # (FB_INTERNAL_EDITLINE)
494+
495+
496+
########################################
497+
# LIBRARY libcds
498+
########################################
499+
500+
file(GLOB_RECURSE libcds_src "extern/libcds/src/*.cpp")
501+
502+
add_library (libcds ${libcds_src})
503+
target_compile_definitions (libcds PUBLIC CDS_BUILD_STATIC_LIB)
504+
project_group (libcds Extern)
505+
506+
378507
########################################
379508
# EXECUTABLE btyacc
380509
########################################
@@ -383,25 +512,27 @@ file(GLOB btyacc_src "extern/btyacc/*.c" "extern/btyacc/*.h")
383512

384513
if (NOT CMAKE_CROSSCOMPILING)
385514

386-
add_executable (btyacc ${btyacc_src})
387-
project_group (btyacc Extern)
388-
set_output_directory (btyacc . CURRENT_DIR)
515+
add_executable (btyacc ${btyacc_src})
516+
set_output_directory (btyacc src CURRENT_DIR)
517+
project_group (btyacc Extern)
389518

390-
endif() # if (NOT CMAKE_CROSSCOMPILING)
519+
endif() # (NOT CMAKE_CROSSCOMPILING)
391520

392521
########################################
393522
# EXECUTABLE cloop
394523
########################################
395524

396525
file(GLOB cloop_src "extern/cloop/src/cloop/*.cpp" "extern/cloop/src/cloop/*.h")
397526

398-
add_executable (cloop ${cloop_src})
399-
project_group (cloop Extern)
527+
add_executable (cloop ${cloop_src})
528+
set_output_directory (cloop src CURRENT_DIR)
529+
project_group (cloop Extern)
400530

401531
########################################
402532
# subdirectories
403533
########################################
404534

535+
add_subdirectory("extern/re2")
405536
add_subdirectory("examples")
406537
add_subdirectory("src")
407538

builds/cmake/BuildFunctions.cmake

+6-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ function(epp_process type files)
114114
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
115115
COMMAND ${CMAKE_COMMAND} -E copy_if_different metadata.fdb ${dir}/yachts.lnk
116116
COMMAND ${CMAKE_COMMAND} -E copy_if_different security.fdb ${dir}/security.fdb
117-
COMMAND ${CMAKE_COMMAND} -E copy_if_different msg.fdb ${dir}/msg.fdb
118117
COMMAND ${ARGN} -b ${dir}/ ${in} ${out}
119118
)
120119
endif()
@@ -263,8 +262,12 @@ function(create_command command type out)
263262
set(dir ${boot_dir})
264263
endif()
265264

266-
set_win32(env "PATH=${dir}\;%PATH%")
267-
set_unix (env "PATH=${dir}/bin:$PATH")
265+
if (MSVC)
266+
set_win32(env "PATH=${dir}\;%PATH%")
267+
elseif (MINGW)
268+
set_win32(env "PATH=${dir}/bin\;%PATH%")
269+
endif()
270+
set_unix(env "PATH=${dir}/bin:$PATH")
268271
set(env "${env}"
269272
FIREBIRD=${dir}
270273
)
@@ -316,7 +319,6 @@ function(create_boot_commands)
316319
boot_gbak
317320
boot_gfix
318321
build_msg
319-
codes
320322
gpre_boot
321323
)
322324
foreach(cmd ${cmd_list})

0 commit comments

Comments
 (0)