Commit Graph

71 Commits

Author SHA1 Message Date
David Korth
3e853a59da [cmake] Don't enable -Werror or /WX by default; add a CMake option -DENABLE_WERROR.
Newer compilers usually add more warnings, so having -Werror by default
will most likely result in a compile error when new compiler versions
are released.

MSVC: Remove "-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING". This is no
longer relevant, since we don't support anything older than MSVC 2015.
2025-04-28 18:19:53 -04:00
David Korth
8b4b48a69c [platform] msvc.cmake: Disable warning C4503.
'identifier': decorated name length exceeded, name was truncated

This is generated by RomHeaderTest due to the lots of tests.

NOTE: Only generated by MSVC 2015 and earlier. MSVC 2017 and later
don't emit this warning.

https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4503?view=msvc-170
2025-04-01 19:17:19 -04:00
David Korth
56a033ea79 [platform] msvc.cmake: Fix ENDIF() for "^/guard:". 2025-04-01 19:17:19 -04:00
David Korth
f3bdc04bd9 [platform] msvc.cmake: Disable some more warnings that are causing errors now.
Disabled these warnings:
- C4005: macro redefinition (libpng's intprefix.out.tf1 is breaking on this...)
- C4091: 'typedef ': ignored on left of 'tagGPFIDL_FLAGS' when no variable is declared
- C4800: 'BOOL': forcing value to bool 'true' or 'false' (performance warning)

TODO:
- Re-enable C4800 as not-an-error?
- Figure out how to fix libpng's C4005 warnings.
2025-04-01 19:17:11 -04:00
David Korth
54e8215488 [platform] msvc.cmake: Add -D_SCL_SECURE_NO_WARNINGS.
[fmt] chrono.h: Revert the MSVC C4996 warning pragma. It didn't work.
Adding `-D_SCL_SECURE_NO_WARNINGS` *should* fix it.
2025-04-01 19:17:11 -04:00
David Korth
924ed20e29 [platform] msvc.cmake: Simplify the "/guard*" check by using a regex. 2025-03-31 22:10:21 -04:00
David Korth
e3a427f6c2 [cmake] msvc.cmake: Make all warnings act as errors. (/W3 /WX)
The MSVC build (64-bit, at least...) now builds with no warnings.
Tested using MSVC 2022 17.6.5.

NOTE: /W4 adds a *lot* of warnings that are mostly just noise. Need to
check /W4 and selectively enable at least some of them...

Removed /wd4482. I don't think this warning is relevant anymore.

Warning fixes:

[extlib] Add (unsigned int) casts where necessary.

[librpbase] Config::ImgTypePrio_t, KeyManager::KeyData_t:
- Change `length` from unsigned int to size_t.
  The struct is 16 bytes on 64-bit either way, but making it size_t
  fixes some conversion warnings.

[librpbase] Hash::Process():
- crc32() returns `unsigned long`, not `uint32_t`, for some reason.
- Also, its length parameter is `unsigned int`, not `size_t`.
- KeyManager::hexStringToBytes(): Take a `size_t` length parameter.

[librpfile] scsi:
- Change cdb_len from `uint8_t` to `size_t`. Using a `uint8_t` argument
  doesn't actually save any memory, since it uses 4 bytes on the stack
  for 32-bit, and one register on 64-bit, regardless.
- Also, limit the maximum cdb size to 260.

[rp-download] Disable warning C4996 when calling GetVersionEx().

[librptexture] DirectDrawSurface:
- Change some `expected_size` variables from `unsigned int` to `size_t`.

[librptexture] PalmOS_Tbmp:
- Change d->bitmapTypeAddr from `off64_t` to `uint32_t`.
- Change some size variables from `unsigned int` to `size_t`.
- loadTbmp(): v3 transparency: Explicitly cast the transparency value
  to uint16_t. (It's stored as a big-endian 32-bit value, but only
  16 bits are used.)
- getNextTbmpAddress(): Cast addresses to `uint32_t`. PalmOS executables
  are 32-bit and cannot possibly exceed 4 GB.
  - FIXME: This function isn't used? (Was it ever used?)

[libromdata]
- DMGPrivate::CartType(): Make `end_offset` constexpr.
- NCCHReader: Add casts for EncSections when using sizeof().
- KeyStoreUIPrivate: binToHexStr(), verifyKeyData():
  - Take a `size_t` length parameter.
- WiiUPackagePrivate: Added a parseHexBinary32() wrapper function
  that returns `uint32_t` instead of `uint64_t`.

[librpbyteswap/tests]
- BitstuffTest: Cast time(nullptr) to `unsigned int`.
  srand() takes `unsigned int`, not `time_t`.

[librpbase/tests]
- RpPngFormatTest: crc32()'s length parameter is `unsigned int`,
  not `size_t`.

[libromdata/tests]
- SuperMagicDriveTest: zlib uses `unsigned int`, so cast array sizes
  to `unsigned int` instead of changing decompress() to take `size_t`.
2025-03-31 21:34:35 -04:00
David Korth
35c716aee1 [cmake] msvc.cmake: Remove some extra whitespace. 2025-03-22 17:35:09 -04:00
David Korth
d5c37bff63 [cmake] msvc.cmake: Uncomment the "/Zi" flag for Release builds.
Not sure why it was commented out...
2025-03-22 17:33:14 -04:00
David Korth
734a72ca78 MSVC: Set /DEPENDENTLOADFLAG:0x800 to restrict DLL loading to SYSTEM32 on startup.
On Windows 10 1607+, this flag is equivalent to calling the
SetDefaultDllDirectories() function before the program starts.

We're already calling SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32)
in librpsecure/win32/restrict-dll.c, but this ensures that it's set even
before the program starts.

Related changes:

- amiiboc: Use delay-loading for libfmt. Otherwise, it fails with
  error code 0xC0000135.
  - Added a dummy stdafx.h file, required by DelayLoadHelper.c.

- All tests: Set /DEPENDENTLOADFLAG:0xA00 because gtest cannot be
  delay-loaded.

- msvc.cmake: Fix linker flags for RelWithDebInfo.

TODO:
- EXE: Show DEPENDENTLOADFLAG.
- Test svrplus.
2025-03-20 20:49:11 -04:00
David Korth
62aeead210 [cmake] msvc.cmake: Add more conformance options.
FIx an error in the non-clang section that caused the common conformance
flags to be overwritten with the MSVC-only flags. Not sure if this will
break anything, and I can't build with MSVC at the moment...

Move "/Zc:throwingNew" into the same non-clang-cl block as the other
options.
2025-01-20 18:45:52 -05:00
David Korth
302738c2d6 [cmake] msvc.cmake: Disable /permissive- if using an SDK version older than 10.0.
Enable it for both debug and release if using 10.0 or later.

This fixes an issue when running package.cmd that caused
InitPropVariantFromUInt16() to not be detected correctly when using
the Windows 7 SDK. (/permissive- was only enabled for debug builds,
but MSVC builds are technically debug and release, so it got enabled
in the InitPropVariantFromUInt16() check.)

These errors occurred without this fix:

c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusheaders.h(891): error C4596: 'EmfToWmfBits': illegal qualified name in member declaration
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusstringformat.h(220): error C4596: 'GetTrimming': illegal qualified name in member declaration
2024-11-10 18:57:20 -05:00
David Korth
cbf7c59bf5 [cmake] msvc.cmake: "/permissive-" was re-enabled in debug builds, immediately after this section.
See commit 57068b2157.
([cmake] msvc.cmake: Re-enable "/permissive-" but in debug builds only.)
2024-03-25 00:27:46 -04:00
David Korth
6b48a743ab [cmake] Add flags for RelWithDebInfo.
On gcc, Release no longer enables debugging flags.

On MSVC, both Release and RelWithDebInfo have debugging flags because
MSVC uses PDBs by default.
2024-03-24 16:58:18 -04:00
David Korth
57068b2157 [cmake] msvc.cmake: Re-enable "/permissive-" but in debug builds only.
This ensures that the permissive errors are fixed during development while
not causing build issues for the release build.
2024-03-03 17:48:50 -05:00
David Korth
2078c85642 [cmake] msvc.cmake: Disable "/permissive-" for now.
It's causing various issues due to the packaging script using the
Windows 7 SDK for i386.

package.cmd: Don't set CMAKE_SYSTEM_VERSION for i386.
2024-03-03 16:07:08 -05:00
David Korth
bd793eed4d [cmake] msvc.cmake: Increase the MSVC minimum to 2013 (12.0); set CMAKE_SYSTEM_VERSION if it isn't set.
Even 12.0 might be too low, but 10.0 is definitely not usable anymore.

CMAKE_SYSTEM_VERSION is set to 10.0 so it will use the latest installed
Windows 10 SDK. This is needed for proper handling of /permissive-
on MSVC 2017 and later.
2023-12-03 12:44:52 -05:00
David Korth
75e64168e0 [cmake] msvc.cmake: Add "/permissive-".
This makes MSVC a bit more standards-compliant, though it does require
working around some common Win32 idioms. In particular, some const_casts
are needed in order to use constant strings in various structs.

src\win32\RP_XAttrView.cpp(263,31): error C2440: '=': cannot convert from 'const wchar_t [5]' to 'LPWSTR'
src\win32\RP_XAttrView.cpp(263,21): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
src\win32\RP_XAttrView.cpp(265,32): error C2440: '=': cannot convert from 'const wchar_t [6]' to 'LPWSTR'
src\win32\RP_XAttrView.cpp(265,21): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
src\win32\RP_ShellPropSheetExt.cpp(890,30): error C2440: '=': cannot convert from 'const wchar_t [1]' to 'LPWSTR'
src\win32\RP_ShellPropSheetExt.cpp(890,24): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
src\win32\config\AboutTab.cpp(1421,30): error C2440: '=': cannot convert from 'const wchar_t [6]' to 'LPWSTR'
src\win32\config\AboutTab.cpp(1421,19): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
2023-11-11 20:44:23 -05:00
David Korth
ec32f1a7e6 [cmake] msvc.cmake: Enable some more security options.
Added the following security options:
- /guard:ehcont - enable EH continuation metadata
- /SAFESEH - image has safe exception handlers (i386 only)
2023-11-09 20:32:15 -05:00
David Korth
203dc72f1c [cmake] msvc.cmake: Re-disable thread-safe statics on amd64.
Our minimum supported 64-bit Windows is technically NT 5.2, which
includes both Windows Server 2003 and Windows XP x64 Edition,
so we need to disable thread-safe statics on amd64.

This partially reverts commit 648c9d8915.
([cmake] msvc.cmake: Consolidate "/guard:cf"; clean up some other checks.)
2023-08-05 12:15:59 -04:00
David Korth
afbf5fcf9b [cmake] msvc.cmake: Make C4477 an error.
C4477: 'function' : format string 'string' requires an argument of type
'type', but variadic argument number has type 'type'

Roughly equivalent to gcc's -Werror=format-security.
2023-08-01 18:07:32 -04:00
David Korth
648c9d8915 [cmake] msvc.cmake: Consolidate "/guard:cf"; clean up some other checks.
The "/guard:cf" linker check was using the wrong variable, so it didn't
work correctly. Handle it in the compiler flag check instead.

Simplify the checks for "/CETCOMPAT".

Use two underscores in the "/Zc:throwingNew" check for consistency with
the other checks.

Only disable thread-safe statics on i386 for Windows XP compatibility.
We're supporting a minimum of Windows Vista for amd64, and for ARM CPUs,
the minimum is Windows 10.
2023-07-28 18:40:11 -04:00
David Korth
551cccf218 [svrplus] Make (most) strings localizable using Win32 string tables.
svrplus is Windows only, so instead of gettext, we can use
string tables in resource files.

NOTE: Due to differences between MSVC's rc.exe and binutils's windres,
strings in the string table must be NULL-terminated.

- rc.exe ignores the explicit NULL-termination, but has an option "/n"
  that automatically adds NULL terminators to strings.

- windres.exe doesn't have an equivalent to "/n", but it *does* allow
  adding '\0' to strings to NULL-terminate them.

Updated msvc.cmake to add "/n" to CMAKE_RC_FLAGS.

NOTE: The '\0's in VS_VERSION_INFO doesn't actually do anything in the
resulting resource section with either rc.exe or windres.exe, so get
rid of them. I think this was mentioned on The Old New Thing before.

Renamed resource.rc to res-en_US.rc and added en_US identifiers.

Compiled executable size doesn't change much.

MSVC 2019, 32-bit release build: (both LTO and no-LTO are identical)

svrplus.exe: 114176 -> 114176 (no change)

   text    data     bss     dec     hex filename
 109644    2048       0  111692   1b44c svrplus.exe [before]
 110650    2048       0  112698   1b83a svrplus.exe [after]
  +1006       0       0   +1006    +3ee Difference
2023-07-08 15:31:14 -04:00
David Korth
3dc11589f6 Fix various issues when compiling with MSVC for ARM CPUs.
- /CETCOMPAT is i386/amd64 only.

- Explicitly link to certain Win32 SDK libraries that are implicitly
  linked on i386/amd64, but aren't on ARM.
2023-07-08 12:14:15 -04:00
David Korth
e3f9bd12d3 [cmake] msvc.cmake: Add /MP for multi-processor compilation. 2023-03-07 21:54:07 -05:00
David Korth
019a0470de Fix some build issues on macOS.
- Split debug symbols doesn't work properly due to an issue with `strip`:
  error: symbols referenced by indirect symbol table entries that can't be stripped in: [library]

- Add "arm64" for M1/M2 Macs.

- zstd: "-fdeclspec" is needed for Clang due to use of __declspec() even
  on non-MS compilers or OSes. Note that we have to check for both
  "Clang" and "AppleClang", since Apple uses its own customized version
  of LLVM/clang.

- msvc.cmake: Make sure "Clang" is quoted when STREQUAL is used.
2023-02-03 19:46:59 -05:00
David Korth
f55617c5da Move RegKey from libwin32common to libwin32ui.
RegKey is only used by win32/ (Win32 UI frontend), so it doesn't need to
be in libwin32common, which results in it getting exported by
romdata-2.dll.

NOTE: In theory, we can remove the HINSTANCE parameter from
RegisterComObject() now, since RegKey is always statically-linked into
rom-properties.dll, but we're better off keeping it there.

[doc/abi] RegKey has been removed from the Windows version.
2022-09-28 19:06:39 -04:00
David Korth
dc4666b672 [cmake] msvc.cmake: Don't set /Zc:externC or /Zc:noexceptTypes on clang-cl.
clang-cl prints a warning, not an error, for these, so it doesn't get
detected by CHECK_CXX_COMPILER_FLAG():

  clang-cl : warning : argument unused during compilation: '/Zc:externC' [-Wunused-command-line-argument]
  clang-cl : warning : argument unused during compilation: '/Zc:noexceptTypes' [-Wunused-command-line-argument]
2022-07-16 15:21:40 -04:00
David Korth
124eb941a8 [cmake] msvc.cmake: Fix duplicate "/guard:cf" check.
It's already checked once for CFLAGS, so use the same variable name to
get the cached value instead of having to recheck it.
2022-07-12 18:24:28 -04:00
David Korth
9352044ac6 [cmake] msvc.cmake: -"and" 2022-07-12 18:07:45 -04:00
David Korth
456760c64c [cmake] msvc.cmake: Added more /Zc options.
- /Zc:inline
- /Zc:__cplusplus
- /Zc:externC
- /Zc:noexceptTypes
- /Zc:rvalueCast
- /Zc:ternary

No code changes were needed, since gcc implements all of these anyway
as far as I know.
2022-07-11 22:30:58 -04:00
David Korth
6dfeed8c58 [cmake] msvc.cmake: Move /Zc:wchar_t here from win32-msvc.cmake; add /Zc:__cplusplus.
This sets the value of __cplusplus to reflect the C++ standard version
in use. MSVC normally doesn't do that for some reason.
2022-07-11 01:16:46 -04:00
David Korth
51ad07363d [cmake] msvc.cmake: INCLUDE(CheckCXXCompilerFlag)
Needed for CHECK_CXX_COMPILER_FLAG().
2022-02-23 18:32:03 -05:00
David Korth
e0d07f37f1 [cmake] platform/msvc.cmake: Don't check for "/Zc:throwingNew" if using clang-cl.
clang-cl defaults to /Zc:throwingNew internally, but it prints a warning
if the parameter is specified:

clang-cl : warning : argument unused during compilation: '/Zc:throwingNew'
[-Wunused-command-line-argument]
2022-02-21 18:34:37 -05:00
David Korth
9bab82452c [cmake] msvc.cmake: Use /Zc:throwingNew if available.
This eliminates NULL pointer checks when calling operator new.
https://devblogs.microsoft.com/cppblog/new-in-vs-2015-zcthrowingnew/

Note that this probably won't affect the release build, since LTCG
already eliminated the NULL pointer checks.
2021-08-31 23:24:39 -04:00
David Korth
9a49d1d701 [cmake] platform/gcc.cmake: Use -Bsymbolic-functions if available.
KDE Frameworks 5.85.0 enables this by default. It reduces startup time
by pre-linking global function symbols.

Also, filter out '=' from variable names. This broke the caching of
-Werror=return-type.

msvc.cmake: Copy the '=' change here.
2021-08-14 10:05:05 -04:00
David Korth
eadcdf9327 Remove "/Gz" for stdcall on i386 when building with MSVC.
I tested a release build and it saved a total of 10,752 bytes.

On the other hand, it had a rather huge maintenance overhead, since I had
to ensure that all extlibs had __cdecl set up in the headers properly,
and this had to be redone on every update.

The i386 build of LZ4 on AppVeyor was failing in tests because of missing
stdcall symbols. I decided not to bother adding stdcall support to LZ4
and simply revert stdcall entirely.
2021-03-31 22:24:17 -04:00
David Korth
8d973bc089 [cmake] Use ADD_DEFINITIONS() for macros that are common to both debug and release builds.
This cleans up the language-specific flags a bit.
2020-02-22 11:38:25 -05:00
David Korth
8d88e435a7 Fixed cross-compilation for Windows on ARM (32-bit and 64-bit).
I decided to try building rom-properties with MSVC 2019's ARM compilers,
and it seems to build properly. I can't test it at the moment, though.

CMake changes:
- ${CMAKE_SYSTEM_PROCESSOR} is always set to the host CPU. Check
  _MSVC_C_ARCHITECTURE_FAMILY to determine the real CPU, then set
  CMAKE_SYSTEM_PROCESSOR accordingly.
- Enable /EHsc if it isn't set already. It's set by CMake for i386
  and amd64, but not for ARM or ARM64.
- Minimum subsystem version for ARM and ARM64 is 6.2. (Windows 8)
- Added some Win32 libraries that are included by default on i386 and
  amd64, but not on ARM or ARM64.
  - Reference: https://pete.akeo.ie/2017/05/compiling-desktop-arm-applications-with.html

Source changes:
- DelayLoadHelper.c, rp-config.c: Added subdirectory names for
  ia64, ARM, and ARM64.
  - TODO: Consolidate this into a common header file?

FIXME: Maybe we should use RP_LINKER_FLAGS_WIN32_EXE and
RP_LINKER_FLAGS_CONSOLE_EXE on MSVC. (We're using this on gcc.)
Not sure why I used one method or the other...
2020-02-01 00:18:11 -05:00
David Korth
b5bdf59a84 [cmake] platform/msvc.cmake: Use /utf-8, which is an alias for source/execution-charset:utf-8. 2019-10-19 09:27:00 -04:00
David Korth
188f2b192c [cmake] platform/msvc.cmake: Set the source and execution character set to UTF-8. (MSVC 2015)
This fixes some build issues when the build system locale is set to
Japanese.

This bug was reported by @DankRank.
2019-10-19 09:24:25 -04:00
David Korth
074b8ff57b [cmake] msvc.cmake: Check CMAKE_CL_64 to determine if it's 32-bit or 64-bit. 2018-09-09 19:33:49 -04:00
David Korth
c9f354a472 [cmake] $(arch) cleanup.
- Set CPU_i386, CPU_amd64, and CPU_ia64 as appropriate.
- These will be used to determine if MMX should be enabled or not.
2018-09-09 19:31:01 -04:00
David Korth
bc995e249b [cmake] msvc.cmake: Handle C4024 and C4047 as errors.
C4024: 'function': different types for formal and actual parameter n
C4047: 'function': 'parameter' differs in levels of indirection from 'argument'

NOTE: /sdl doesn't do this.
2018-05-11 22:38:19 -04:00
David Korth
2e669b0154 [cmake] msvc.cmake: Disable std::tr1 deprecation warnings.
Some MSVC 2017 update added deprecation warnings for std::tr1.
Google Test 1.8.0 still uses it, so disable the warnings for now.
2018-01-26 22:06:01 -05:00
David Korth
57a92ca74f [cmake] Moved the stack protection flag check from gcc.cmake and msvc.cmake to platform.cmake. 2018-01-15 06:37:29 -05:00
David Korth
c5d71f944b [cmake] msvc.cmake: Use /Gz on 32-bit i386 MSVC builds.
File sizes for the 32-bit MSVC 2017 (15.3) release build:

|      Filename      |   Before  |    After  |  Diff  |
|-------------------:|----------:|----------:|-------:|
| rom-properties.dll |   629,248 |   627,200 | -2,048 |
|          zlib1.dll |    78,848 |    78,848 |      0 |
|       libpng16.dll |   185,344 |   184,320 | -1,024 |
|         jpeg62.dll |   432,640 |   432,640 |      0 |
|       tinyxml2.dll |    73,728 |    73,728 |      0 |
|          rpcli.exe |   453,120 |   452,096 | -1,024 |
|      rp-config.exe |    17,408 |    17,408 |      0 |
|        svrplus.exe |   335,872 |   335,872 |      0 |
|          **Total** | 2,206,208 | 2,202,112 | -4,096 |
2017-09-02 13:22:48 -04:00
David Korth
979214a6fa [cmake] msvc.cmake: Disable thread-safe static initialization on MSVC 2015 and later.
Thread-safe static initialization requires Vista or later, since XP
doesn't have enough TLS slots.

NOTE: We need to make sure that we use pthread_once() for one-time init
instead of using a static initializer.
2017-09-02 11:44:29 -04:00
David Korth
164b96687c [cmake] msvc.cmake: Enable control flow guard if it's available.
Release build sizes: (MSVC 2017)
- rom-properties.dll: 655,360 -> 676,864 (+21,504 bytes)
- rpcli.exe: 480,768 -> 496,128 (+15,360 bytes)

It's not that much overhead, so I'll keep it enabled for all builds.
2017-05-26 22:43:24 -04:00
David Korth
4d19631829 [cmake] msvc.cmake: Use '/' style options instead of '-' style.
win32-msvc.cmake: Likewise.
2017-05-20 00:02:24 -04:00