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. 
2323if  (${CMAKE_SOURCE_DIR}  STREQUAL  ${CMAKE_BINARY_DIR} )
@@ -84,6 +84,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir})
8484if  (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} )
8789endif ()
8890
8991if  (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)
104106endif ()
@@ -147,8 +149,8 @@ endif()
147149
148150include (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} )
153155endif ()
154156
@@ -159,21 +161,55 @@ set(FB_SERVICE_NAME "gds_db")
159161set (FB_SERVICE_PORT 3050)
160162
161163if  (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" )
164170endif ()
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+ 
166191set (AUTOCONFIG_SRC ${CMAKE_SOURCE_DIR} /src/include /gen/autoconfig.h.in)
167192set (AUTOCONFIG ${CMAKE_BINARY_DIR} /src/include /gen/autoconfig.h)
168193configure_file (${AUTOCONFIG_SRC}  ${AUTOCONFIG}  @ONLY)
169194
195+ if  (MINGW)
196+     # Set the final installation path 
197+     set (FB_PREFIX ${FB_INSTALL_PREFIX} )
198+ 
199+     set (FBCONFIG_SRC ${CMAKE_SOURCE_DIR} /builds/install /arch-specific/mingw/fb_config.in)
200+     set (FBCONFIG ${CMAKE_BINARY_DIR} /fb_config)
201+     configure_file (${FBCONFIG_SRC}  ${FBCONFIG}  @ONLY)
202+ endif ()
203+ 
170204################################################################################ 
171205# 
172206# compiler & linker settings 
173207# 
174208################################################################################ 
175209
176- add_definitions (-DDEV_BUILD)
210+ if  ("${CMAKE_BUILD_TYPE} "  STREQUAL  "Debug" )
211+     add_definitions (-DDEV_BUILD)
212+ endif ()
177213
178214if  (WIN32 )
179215    set (OS_DIR win32 )
@@ -192,20 +228,71 @@ if (WIN32)
192228        endif ()
193229    endif (MSVC )
194230
195-     set (LIB_Ws2_32 Ws2_32 )
231+     set (LIB_ws2_32 ws2_32 )
196232    set (LIB_comctl32 comctl32)
197233    set (LIB_mpr mpr)
198234    set (LIB_version version )
199235endif (WIN32 )
200236
201237if  (MINGW)
202-     # clear  unix-style prefixes 
238+     # Clear  unix-style prefixes 
203239    set (CMAKE_SHARED_LIBRARY_PREFIX )
204240    set (CMAKE_SHARED_MODULE_PREFIX )
205241    set (CMAKE_STATIC_LIBRARY_PREFIX )
206242
207-     add_definitions (-D_WIN32_WINNT=0x0600)
243+     if  ("${CMAKE_BUILD_TYPE} "  STREQUAL  "Debug" )
244+         set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  -ggdb" )
245+         set (CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS}  -DDEBUG" )
246+     else ()
247+         set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  -O3" )
248+         set (CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS}  -DNDEBUG" )
249+     endif ()
250+ 
251+     add_definitions (-DWIN_NT -DMINGW -DMINGW_HAS_SECURE_API -DTTMATH_NOASM)
252+ 
253+     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wno-shift-count-overflow" )
208254    set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  -msse4 -std=c++17" )
255+ 
256+     # Suppress myriad of warnings     
257+     set (cxx_flags  "" )
258+     list (APPEND  cxx_flags 
259+         -Wundef
260+         -Wno-format
261+         -Wno-deprecated-declarations
262+         -Wno-ignored-attributes
263+         -Wno-invalid-offsetof
264+         -Wno-long-long
265+         -Wno-non-virtual-dtor
266+         -Wno-parentheses
267+         -Wno-shift-count-overflow
268+         -Wno-sign-compare
269+         -Wno-switch
270+         -Wno-unused-variable 
271+         -Wno-write-strings 
272+     )
273+     if  (CLANG)
274+         list (APPEND  cxx_flags 
275+             -Wno-varargs
276+             -Wno-constant-conversion
277+             -Wno-inconsistent-missing-override
278+             -Wno-tautological-constant-out-of-range-compare
279+             -Wno-c++11-narrowing
280+         )
281+     else ()
282+         list (APPEND  cxx_flags 
283+             -Wno-class-memaccess
284+             -Wno-overflow
285+             -Wno-return-local-addr
286+             -Wno-stringop-overflow
287+             -Wno-stringop-overread
288+             -Wno-narrowing
289+         )
290+     endif ()
291+     string (REPLACE ";"  " "  cxx_flags  "${cxx_flags} " )
292+     set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  ${cxx_flags} " )
293+ 
294+     set (LIB_iconv iconv)
295+     set (LIB_re2 re2)
209296endif ()
210297
211298if  (UNIX )
@@ -214,8 +301,12 @@ if (UNIX)
214301    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -fPIC" )
215302    set (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  -fPIC -msse4 -std=c++17" )
216303
304+     set (FB_INTERNAL_TOMMATH ON )
305+     set (FB_INTERNAL_EDITLINE ON )
306+ 
307+     set (LIB_re2 re2)
217308    if  (NOT  CMAKE_CROSSCOMPILING )
218-         set (LIB_readline readline )
309+         set (LIB_editline editline )
219310    endif ()
220311    if  (NOT  FREEBSD)
221312        set (LIB_dl dl)
@@ -251,7 +342,7 @@ endif()
251342# 
252343################################################################################ 
253344
254- if  (WIN32 )
345+ if  (MSVC )
255346    # icu 
256347    if  (NOT  ICU_EXTRACT)
257348        message (STATUS  "Extracting pre-built ICU" )
@@ -324,29 +415,50 @@ if (NOT CMAKE_CROSSCOMPILING)
324415create_boot_commands()
325416create_master_commands()
326417
327- endif () # if  (NOT CMAKE_CROSSCOMPILING) 
418+ endif () # (NOT CMAKE_CROSSCOMPILING) 
328419
329420crosscompile_prebuild_steps()
330421
331- include_directories ("extern/libtommath" )
332- include_directories ("extern/libtomcrypt/src/headers" )
422+ if  (FB_INTERNAL_TOMMATH)
423+     include_directories ("extern/libtommath" )
424+     include_directories ("extern/libtomcrypt/src/headers" )
425+     set (LIB_tommath libtommath)
426+     set (LIB_tomcrypt libtomcrypt)
427+ else ()
428+     set (LIB_tommath tommath)
429+     set (LIB_tomcrypt tomcrypt)
430+ endif ()
431+ 
432+ if  (UNIX )
433+     if  (FB_INTERNAL_EDITLINE)
434+         include_directories ("extern/editline" )
435+     endif ()
436+ endif ()
437+ 
333438include_directories ("extern/decNumber" )
334- include_directories ("extern/icu/include" )
335- include_directories ("extern/zlib" )
439+ include_directories ("extern/libcds" )
440+ include_directories ("extern/re2" )
441+ 
442+ if  (MSVC  OR  ANDROID)
443+     include_directories ("extern/icu/include" )
444+     include_directories ("extern/zlib" )
445+ endif ()
336446
337447include_directories ("src/include" )
338448include_directories ("src/include/gen" )
339449include_directories ("${CMAKE_CURRENT_BINARY_DIR} /src/include" )
340450include_directories ("${CMAKE_CURRENT_BINARY_DIR} /src/include/gen" )
341451
452+ 
453+ if  (FB_INTERNAL_TOMMATH)
342454######################################## 
343455# LIBRARY libtommath 
344456######################################## 
345457
346458file (GLOB libtommath_src "extern/libtommath/*.c"  "extern/libtommath/*.h" )
347459
348- add_library              (libtommath ${libtommath_src} )
349- project_group           (libtommath Extern)
460+ add_library                   (libtommath ${libtommath_src} )
461+ project_group                (libtommath Extern)
350462
351463
352464######################################## 
@@ -362,6 +474,8 @@ add_library                 (libtomcrypt ${libtomcrypt_src})
362474target_compile_definitions   (libtomcrypt PRIVATE  LTC_NO_ROLC LTC_SOURCE)
363475project_group               (libtomcrypt Extern)
364476
477+ endif () # (FB_INTERNAL_TOMMATH) 
478+ 
365479
366480######################################## 
367481# LIBRARY decNumber 
@@ -375,6 +489,30 @@ add_library                 (decNumber ${decNumber_src})
375489project_group               (decNumber Extern)
376490
377491
492+ if  (FB_INTERNAL_EDITLINE)
493+ ######################################## 
494+ # LIBRARY editline 
495+ ######################################## 
496+ 
497+ file (GLOB editline_src "extern/editline/src/*.c"  "extern/editline/src/*.h" )
498+ 
499+ add_library                  (editline ${editline_src} )
500+ project_group               (editline Extern)
501+ 
502+ endif () # (FB_INTERNAL_EDITLINE) 
503+ 
504+ 
505+ ######################################## 
506+ # LIBRARY libcds 
507+ ######################################## 
508+ 
509+ file (GLOB_RECURSE libcds_src "extern/libcds/src/*.cpp" )
510+ 
511+ add_library                  (libcds ${libcds_src} )
512+ target_compile_definitions   (libcds PUBLIC  CDS_BUILD_STATIC_LIB)
513+ project_group               (libcds Extern)
514+ 
515+ 
378516######################################## 
379517# EXECUTABLE btyacc 
380518######################################## 
@@ -383,25 +521,27 @@ file(GLOB btyacc_src "extern/btyacc/*.c" "extern/btyacc/*.h")
383521
384522if  (NOT  CMAKE_CROSSCOMPILING )
385523
386- add_executable           (btyacc ${btyacc_src} )
387- project_group             (btyacc Extern )
388- set_output_directory     (btyacc . CURRENT_DIR )
524+ add_executable                (btyacc ${btyacc_src} )
525+ set_output_directory         (btyacc src CURRENT_DIR )
526+ project_group                 (btyacc Extern )
389527
390- endif () # if  (NOT CMAKE_CROSSCOMPILING) 
528+ endif () # (NOT CMAKE_CROSSCOMPILING) 
391529
392530######################################## 
393531# EXECUTABLE cloop 
394532######################################## 
395533
396534file (GLOB cloop_src "extern/cloop/src/cloop/*.cpp"  "extern/cloop/src/cloop/*.h" )
397535
398- add_executable           (cloop ${cloop_src} )
399- project_group           (cloop Extern)
536+ add_executable               (cloop ${cloop_src} )
537+ set_output_directory        (cloop src CURRENT_DIR)
538+ project_group               (cloop Extern)
400539
401540######################################## 
402541# subdirectories 
403542######################################## 
404543
544+ add_subdirectory ("extern/re2" )
405545add_subdirectory ("examples" )
406546add_subdirectory ("src" )
407547
0 commit comments