|
| 1 | + |
| 2 | +############################################################################### |
| 3 | +# Global compile options |
| 4 | +############################################################################### |
| 5 | + |
| 6 | +# Use conforming swprintfs |
| 7 | +remove_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS) |
| 8 | + |
| 9 | +# This requires NT6 |
| 10 | +remove_definitions(-D_WIN32_WINNT=0x502 -DWINVER=0x502) |
| 11 | +add_definitions(-D_WIN32_WINNT=0x601 -DWINVER=0x601) |
| 12 | + |
| 13 | +# Replace the global CRT include directory with the msvcrt include directory |
| 14 | +get_property(INCLUDE_DIRS DIRECTORY . PROPERTY INCLUDE_DIRECTORIES) |
| 15 | +list(REMOVE_ITEM INCLUDE_DIRS "${REACTOS_SOURCE_DIR}/sdk/include/crt") |
| 16 | +set_property(DIRECTORY . PROPERTY INCLUDE_DIRECTORIES ${INCLUDE_DIRS}) |
| 17 | +include_directories(include) |
| 18 | + |
| 19 | +# includes for wine code |
| 20 | +include_directories(BEFORE ${REACTOS_SOURCE_DIR}/sdk/include/wine) |
| 21 | + |
| 22 | +add_definitions( |
| 23 | + -D_CRTIMP= |
| 24 | + |
| 25 | + # Workarounds |
| 26 | + -DARRAY_SIZE=_countof |
| 27 | + -DI64_MIN=_I64_MIN |
| 28 | + -DI64_MAX=_I64_MAX |
| 29 | + -DUI64_MAX=_UI64_MAX |
| 30 | + -Dx87_asin=asin |
| 31 | + -Dmath_error=_invoke_matherr |
| 32 | + -Dasm_sqrt=sqrt |
| 33 | + -Dasm_sqrtf=sqrtf |
| 34 | +) |
| 35 | + |
| 36 | +if(ARCH STREQUAL "i386") |
| 37 | + add_definitions( |
| 38 | + -D__ASM_USE_THISCALL_WRAPPER |
| 39 | + ) |
| 40 | +endif() |
| 41 | + |
| 42 | +if(MSVC) |
| 43 | + add_compile_options( |
| 44 | + /wd4090 # 'function': different 'const' qualifiers |
| 45 | + /wd4146 # 'minus' operator applied to unsigned type, result still unsigned |
| 46 | + /wd4164 # 'function': intrinsic function not declared |
| 47 | + /wd4267 # 'conversion from 'size_t' to 'unsigned int', possible loss of data' |
| 48 | + /wd4723 # potential divide by 0 |
| 49 | + ) |
| 50 | + if(ARCH STREQUAL "amd64") |
| 51 | + add_compile_options(#msvcrt PRIVATE |
| 52 | + /wd4334 # 'result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)' |
| 53 | + ) |
| 54 | + endif() |
| 55 | +endif() |
| 56 | + |
| 57 | +############################################################################### |
| 58 | +# A static library shared with ucrtbase |
| 59 | +############################################################################### |
| 60 | + |
| 61 | +list(APPEND SHARED_SOURCE |
| 62 | + cpp.c |
| 63 | + except.c |
| 64 | + handler4.c |
| 65 | + undname.c |
| 66 | +) |
| 67 | + |
| 68 | +if(ARCH STREQUAL "i386") |
| 69 | + list(APPEND SHARED_SOURCE |
| 70 | + except_i386.c |
| 71 | + ) |
| 72 | + list(APPEND SHARED_ASM_SOURCE |
| 73 | + i386/__wine_RtlUnwind.s |
| 74 | + i386/inout.s |
| 75 | + ) |
| 76 | +elseif(ARCH STREQUAL "amd64") |
| 77 | + list(APPEND SHARED_SOURCE |
| 78 | + except_x86_64.c |
| 79 | + ) |
| 80 | +elseif(ARCH STREQUAL "arm") |
| 81 | + list(APPEND SHARED_SOURCE |
| 82 | + except_arm.c |
| 83 | + ) |
| 84 | +elseif(ARCH STREQUAL "arm64") |
| 85 | + list(APPEND SHARED_SOURCE |
| 86 | + except_arm64.c |
| 87 | + ) |
| 88 | +elseif(ARCH STREQUAL "arm64ec") |
| 89 | + list(APPEND SHARED_SOURCE |
| 90 | + except_arm64ec.c |
| 91 | + ) |
| 92 | +endif() |
| 93 | + |
| 94 | +# MSVC asm code |
| 95 | +if(MSVC) |
| 96 | + if(ARCH STREQUAL "i386") |
| 97 | + list(APPEND SHARED_ASM_SOURCE |
| 98 | + i386/cpp_alias.s |
| 99 | + i386/cpp_vtables.s |
| 100 | + i386/except_i386_asm.s |
| 101 | + ) |
| 102 | + elseif(ARCH STREQUAL "amd64") |
| 103 | + list(APPEND SHARED_ASM_SOURCE |
| 104 | + amd64/cpp_alias.s |
| 105 | + amd64/cpp_vtables.s |
| 106 | + amd64/except_x86_64.s |
| 107 | + ) |
| 108 | + endif() |
| 109 | +endif() |
| 110 | + |
| 111 | +add_asm_files(msvcrt_shared_asm ${SHARED_ASM_SOURCE}) |
| 112 | + |
| 113 | +add_library(msvcrt_shared |
| 114 | + ${SHARED_SOURCE} |
| 115 | + ${msvcrt_shared_asm} |
| 116 | +) |
| 117 | + |
| 118 | +target_compile_definitions(msvcrt_shared PRIVATE _MSVCR_VER=0) |
| 119 | +if(ARCH STREQUAL "i386") |
| 120 | + # ASM wrapper for Wine code, implemented in i386/__wine_RtlUnwind.s |
| 121 | + target_compile_definitions(msvcrt_shared PRIVATE RtlUnwind=__wine_RtlUnwind) |
| 122 | +endif() |
| 123 | +add_dependencies(msvcrt_shared psdk asm) |
| 124 | + |
| 125 | +############################################################################### |
| 126 | +# A static library shared between msvcrt.dll msvcrt20.dll and msvcrt40.dll |
| 127 | +############################################################################### |
| 128 | + |
| 129 | +list(APPEND MSVCRT_SOURCE |
| 130 | + ${SHARED_SOURCE} |
| 131 | + ${msvcrt_shared_asm} |
| 132 | + reactos/chkesp_failed.c |
| 133 | + reactos/misc.c |
| 134 | + concurrency.c |
| 135 | + console.c |
| 136 | + ctype.c |
| 137 | + data.c |
| 138 | + dir.c |
| 139 | + environ.c |
| 140 | + errno.c |
| 141 | + exception_ptr.c |
| 142 | + exit.c |
| 143 | + file.c |
| 144 | + heap.c |
| 145 | + locale.c |
| 146 | + lock.c |
| 147 | + main.c |
| 148 | + math.c |
| 149 | + mbcs.c |
| 150 | + misc.c |
| 151 | + process.c |
| 152 | + scanf.c |
| 153 | + sincos.c |
| 154 | + string.c |
| 155 | + thread.c |
| 156 | + time.c |
| 157 | + wcs.c |
| 158 | +) |
| 159 | + |
| 160 | +add_asm_files(msvcrt_asm ${MSVCRT_ASM_SOURCE}) |
| 161 | +list(APPEND MSVCRT_SOURCE ${msvcrt_asm}) |
| 162 | + |
| 163 | +add_library(msvcrt_static |
| 164 | + ${MSVCRT_SOURCE} |
| 165 | +) |
| 166 | + |
| 167 | +target_compile_definitions(msvcrt_static PRIVATE _MSVCR_VER=0) |
| 168 | +add_dependencies(msvcrt_static psdk asm) |
| 169 | + |
| 170 | +############################################################################### |
| 171 | +# MSVCRT.DLL |
| 172 | +############################################################################### |
| 173 | + |
| 174 | +spec2def(msvcrt.dll msvcrt.spec ADD_IMPORTLIB) |
| 175 | + |
| 176 | +add_library(msvcrt MODULE |
| 177 | + ${CMAKE_CURRENT_BINARY_DIR}/msvcrt_stubs.c |
| 178 | + ${CMAKE_CURRENT_BINARY_DIR}/msvcrt.def |
| 179 | + msvcrt.rc |
| 180 | +) |
| 181 | + |
| 182 | +target_compile_definitions(msvcrt PRIVATE _MSVCR_VER=0) |
| 183 | +set_module_type(msvcrt win32dll ENTRYPOINT DllMain 12) |
| 184 | +target_link_libraries(msvcrt msvcrt_static crtmath dbgrpt vcruntime wine chkstk ${PSEH_LIB}) |
| 185 | +if(ARCH STREQUAL "i386") |
| 186 | + target_link_libraries(msvcrt chkesp) |
| 187 | +endif() |
| 188 | +add_importlibs(msvcrt kernel32 kernel32_vista ntdll) |
| 189 | +add_delay_importlibs(msvcrt user32 advapi32) |
| 190 | + |
| 191 | +if(MSVC) |
| 192 | + # Silence warning C4102: export of deleting destructor "name" |
| 193 | + target_link_options(msvcrt PRIVATE "/ignore:4102") |
| 194 | + set_property(TARGET libmsvcrt APPEND PROPERTY STATIC_LIBRARY_OPTIONS "/ignore:4102") |
| 195 | +endif() |
| 196 | + |
| 197 | +add_cd_file(TARGET msvcrt DESTINATION reactos/system32 FOR all) |
| 198 | + |
| 199 | +############################################################################### |
| 200 | +# Import library |
| 201 | +############################################################################### |
| 202 | + |
| 203 | +# Let consumers of msvcrt have the right defines |
| 204 | +target_compile_definitions(libmsvcrt INTERFACE _DLL __USE_CRTIMP) |
| 205 | + |
| 206 | +# Embed msvcrtex into libmsvcrt |
| 207 | +target_sources(libmsvcrt PRIVATE $<TARGET_OBJECTS:msvcrtex>) |
| 208 | + |
| 209 | +# Embed RTC libs |
| 210 | +if (STACK_PROTECTOR) |
| 211 | + target_sources(libmsvcrt PRIVATE $<TARGET_OBJECTS:gcc_ssp_msvcrt>) |
| 212 | + target_link_libraries(libmsvcrt INTERFACE libkernel32) # For OutputDebugStringA |
| 213 | +endif() |
0 commit comments