1# Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License, version 2.0, 5# as published by the Free Software Foundation. 6# 7# This program is also distributed with certain software (including 8# but not limited to OpenSSL) that is licensed under separate terms, 9# as designated in a particular file or component or in included license 10# documentation. The authors of MySQL hereby grant you an additional 11# permission to link the program and your derivative works with the 12# separately licensed software that they have included with MySQL. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License, version 2.0, for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program; if not, write to the Free Software 21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 23# This file includes Windows specific hacks, mostly around compiler flags 24 25INCLUDE (CheckCSourceCompiles) 26INCLUDE (CheckCXXSourceCompiles) 27INCLUDE (CheckStructHasMember) 28INCLUDE (CheckLibraryExists) 29INCLUDE (CheckFunctionExists) 30INCLUDE (CheckCCompilerFlag) 31INCLUDE (CheckCSourceRuns) 32INCLUDE (CheckSymbolExists) 33INCLUDE (CheckTypeSize) 34 35# Optionally read user configuration, generated by configure.js. 36# This is left for backward compatibility reasons only. 37INCLUDE(${CMAKE_BINARY_DIR}/win/configure.data OPTIONAL) 38 39# avoid running system checks by using pre-cached check results 40# system checks are expensive on VS since every tiny program is to be compiled in 41# a VC solution. 42GET_FILENAME_COMPONENT(_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) 43INCLUDE(${_SCRIPT_DIR}/WindowsCache.cmake) 44 45 46# OS display name (version_compile_os etc). 47# Used by the test suite to ignore bugs on some platforms, 48IF(CMAKE_SIZEOF_VOID_P MATCHES 8) 49 SET(SYSTEM_TYPE "Win64") 50 SET(MYSQL_MACHINE_TYPE "x86_64") 51ELSE() 52 SET(SYSTEM_TYPE "Win32") 53ENDIF() 54 55# Intel compiler is almost Visual C++ 56# (same compile flags etc). Set MSVC flag 57IF(CMAKE_C_COMPILER MATCHES "icl") 58 SET(MSVC TRUE) 59ENDIF() 60 61ADD_DEFINITIONS(-D_WINDOWS -D__WIN__ -D_CRT_SECURE_NO_DEPRECATE) 62ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501) 63# We do not want the windows.h macros min/max 64ADD_DEFINITIONS(-DNOMINMAX) 65# Speed up build process excluding unused header files 66ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) 67 68# Adjust compiler and linker flags 69IF(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4) 70 # mininal architecture flags, i486 enables GCC atomics 71 ADD_DEFINITIONS(-march=i486) 72ENDIF() 73 74IF(MSVC) 75 OPTION(LINK_STATIC_RUNTIME_LIBRARIES "Link with /MT" OFF) 76 # Enable debug info also in Release build, 77 # and create PDB to be able to analyze crashes. 78 FOREACH(type EXE SHARED MODULE) 79 SET(CMAKE_{type}_LINKER_FLAGS_RELEASE 80 "${CMAKE_${type}_LINKER_FLAGS_RELEASE} /debug") 81 ENDFOREACH() 82 83 # For release types Debug Release RelWithDebInfo (but not MinSizeRel): 84 # - Force static runtime libraries 85 # - Choose C++ exception handling: 86 # If /EH is not specified, the compiler will catch structured and 87 # C++ exceptions, but will not destroy C++ objects that will go out of 88 # scope as a result of the exception. 89 # /EHsc catches C++ exceptions only and tells the compiler to assume that 90 # extern C functions never throw a C++ exception. 91 # - Choose debugging information: 92 # /Z7 93 # Produces an .obj file containing full symbolic debugging 94 # information for use with the debugger. The symbolic debugging 95 # information includes the names and types of variables, as well as 96 # functions and line numbers. No .pdb file is produced by the compiler. 97 # We can't use /ZI too since it's causing __LINE__ macros to be non- 98 # constant on visual studio and hence XCom stops building correctly. 99 FOREACH(lang C CXX) 100 SET(CMAKE_${lang}_FLAGS_RELEASE "${CMAKE_${lang}_FLAGS_RELEASE} /Z7") 101 ENDFOREACH() 102 FOREACH(flag 103 CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO 104 CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT 105 CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO 106 CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT) 107 IF(LINK_STATIC_RUNTIME_LIBRARIES) 108 STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}") 109 ENDIF() 110 STRING(REPLACE "/Zi" "/Z7" "${flag}" "${${flag}}") 111 STRING(REPLACE "/ZI" "/Z7" "${flag}" "${${flag}}") 112 SET("${flag}" "${${flag}} /EHsc") 113 ENDFOREACH() 114 115 # Fix CMake's predefined huge stack size 116 FOREACH(type EXE SHARED MODULE) 117 STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}") 118 STRING(REGEX REPLACE "/INCREMENTAL:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO}") 119 ENDFOREACH() 120 121 # Mark 32 bit executables large address aware so they can 122 # use > 2GB address space 123 IF(CMAKE_SIZEOF_VOID_P MATCHES 4) 124 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE") 125 ENDIF() 126 127 # Speed up multiprocessor build 128 IF (MSVC_VERSION GREATER 1400) 129 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") 130 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") 131 ENDIF() 132 133 #TODO: update the code and remove the disabled warnings 134 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4800 /wd4805 /wd4996") 135 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800 /wd4805 /wd4996 /we4099") 136 137 IF(CMAKE_SIZEOF_VOID_P MATCHES 8) 138 # _WIN64 is defined by the compiler itself. 139 # Yet, we define it here again to work around a bug with Intellisense 140 # described here: http://tinyurl.com/2cb428. 141 # Syntax highlighting is important for proper debugger functionality. 142 ADD_DEFINITIONS("-D_WIN64") 143 ENDIF() 144ENDIF() 145 146# Always link with socket library 147LINK_LIBRARIES(ws2_32) 148# ..also for tests 149SET(CMAKE_REQUIRED_LIBRARIES ws2_32) 150 151# IPv6 constants appeared in Vista SDK first. We need to define them in any case if they are 152# not in headers, to handle dual mode sockets correctly. 153CHECK_SYMBOL_EXISTS(IPPROTO_IPV6 "winsock2.h" HAVE_IPPROTO_IPV6) 154IF(NOT HAVE_IPPROTO_IPV6) 155 SET(HAVE_IPPROTO_IPV6 41) 156ENDIF() 157CHECK_SYMBOL_EXISTS(IPV6_V6ONLY "winsock2.h;ws2ipdef.h" HAVE_IPV6_V6ONLY) 158IF(NOT HAVE_IPV6_V6ONLY) 159 SET(IPV6_V6ONLY 27) 160ENDIF() 161 162# Some standard functions exist there under different 163# names (e.g popen is _popen or strok_r is _strtok_s) 164# If a replacement function exists, HAVE_FUNCTION is 165# defined to 1. CMake variable <function_name> will also 166# be defined to the replacement name. 167# So for example, CHECK_FUNCTION_REPLACEMENT(popen _popen) 168# will define HAVE_POPEN to 1 and set variable named popen 169# to _popen. If the header template, one needs to have 170# cmakedefine popen @popen@ which will expand to 171# define popen _popen after CONFIGURE_FILE 172 173MACRO(CHECK_FUNCTION_REPLACEMENT function replacement) 174 STRING(TOUPPER ${function} function_upper) 175 CHECK_FUNCTION_EXISTS(${function} HAVE_${function_upper}) 176 IF(NOT HAVE_${function_upper}) 177 CHECK_FUNCTION_EXISTS(${replacement} HAVE_${replacement}) 178 IF(HAVE_${replacement}) 179 SET(HAVE_${function_upper} 1 ) 180 SET(${function} ${replacement}) 181 ENDIF() 182 ENDIF() 183ENDMACRO() 184MACRO(CHECK_SYMBOL_REPLACEMENT symbol replacement header) 185 STRING(TOUPPER ${symbol} symbol_upper) 186 CHECK_SYMBOL_EXISTS(${symbol} ${header} HAVE_${symbol_upper}) 187 IF(NOT HAVE_${symbol_upper}) 188 CHECK_SYMBOL_EXISTS(${replacement} ${header} HAVE_${replacement}) 189 IF(HAVE_${replacement}) 190 SET(HAVE_${symbol_upper} 1) 191 SET(${symbol} ${replacement}) 192 ENDIF() 193 ENDIF() 194ENDMACRO() 195 196CHECK_SYMBOL_REPLACEMENT(S_IROTH _S_IREAD sys/stat.h) 197CHECK_SYMBOL_REPLACEMENT(S_IFIFO _S_IFIFO sys/stat.h) 198CHECK_SYMBOL_REPLACEMENT(SIGQUIT SIGTERM signal.h) 199CHECK_SYMBOL_REPLACEMENT(SIGPIPE SIGINT signal.h) 200CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h) 201CHECK_SYMBOL_REPLACEMENT(finite _finite float.h) 202CHECK_SYMBOL_REPLACEMENT(tzname _tzname time.h) 203CHECK_SYMBOL_REPLACEMENT(snprintf _snprintf stdio.h) 204CHECK_FUNCTION_REPLACEMENT(popen _popen) 205CHECK_FUNCTION_REPLACEMENT(pclose _pclose) 206CHECK_FUNCTION_REPLACEMENT(access _access) 207CHECK_FUNCTION_REPLACEMENT(strcasecmp _stricmp) 208CHECK_FUNCTION_REPLACEMENT(strncasecmp _strnicmp) 209CHECK_FUNCTION_REPLACEMENT(strtok_r strtok_s) 210CHECK_FUNCTION_REPLACEMENT(strtoll _strtoi64) 211CHECK_FUNCTION_REPLACEMENT(strtoull _strtoui64) 212CHECK_FUNCTION_REPLACEMENT(vsnprintf _vsnprintf) 213CHECK_TYPE_SIZE(ssize_t SIZE_OF_SSIZE_T) 214IF(NOT HAVE_SIZE_OF_SSIZE_T) 215 SET(ssize_t SSIZE_T) 216ENDIF() 217 218SET(FN_NO_CASE_SENSE 1) 219SET(USE_SYMDIR 1) 220