From a8bd0a9b84156a10c647c47cbbdb30f748eb0a2b Mon Sep 17 00:00:00 2001 From: Mark Roszko Date: Sat, 10 Oct 2020 19:08:23 +0000 Subject: [PATCH] Handle Windows manifests ourselves and add dpi awareness option --- CMakeLists.txt | 30 ++++++++++++++-- CMakeModules/MinGWResourceCompiler.cmake | 12 ++++++- bitmap2component/bitmap2component.rc | 2 +- cvpcb/cvpcb.rc | 3 +- eeschema/eeschema.rc | 2 +- gerbview/gerbview.rc | 2 +- kicad/kicad.rc | 2 +- pagelayout_editor/pl_editor.rc | 2 +- pcb_calculator/pcb_calculator.rc | 2 +- pcbnew/pcbnew.rc | 2 +- resources/msw/kiwin32.rc | 32 +++++++++++++++++ resources/msw/manifests/x64.manifest | 21 +++++++++++ .../msw/manifests/x64_dpi_aware_pmv2.manifest | 35 +++++++++++++++++++ resources/msw/manifests/x86.manifest | 21 +++++++++++ .../msw/manifests/x86_dpi_aware_pmv2.manifest | 35 +++++++++++++++++++ 15 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 resources/msw/kiwin32.rc create mode 100644 resources/msw/manifests/x64.manifest create mode 100644 resources/msw/manifests/x64_dpi_aware_pmv2.manifest create mode 100644 resources/msw/manifests/x86.manifest create mode 100644 resources/msw/manifests/x86_dpi_aware_pmv2.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt index 074b81e0c2..8fcfc70775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,6 +126,10 @@ option( KICAD_NETLIST_QA "Run eeschema netlist QA tests (requires Python 3)" OFF ) +option( KICAD_WIN32_DPI_AWARE + "Turn on DPI awareness for Windows builds only" + OFF ) + # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled: # PYTHON_EXECUTABLE can be defined when invoking cmake # ( use -DPYTHON_EXECUTABLE=/python.exe or python2 ) @@ -226,6 +230,18 @@ if( WIN32 ) # In fully standards-compliant mode, M_PI et al. are defined only if # _USE_MATH_DEFINES is set. add_definitions( -D_USE_MATH_DEFINES ) + + # We need the arch for the resource compiler later + if ( NOT CMAKE_SIZEOF_VOID_P EQUAL 8 ) + set( KICAD_BUILD_ARCH "x86" ) + elseif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + set( KICAD_BUILD_ARCH "x64" ) + endif() + add_definitions( -DKICAD_BUILD_ARCH=${KICAD_BUILD_ARCH} ) + + if( KICAD_WIN32_DPI_AWARE ) + add_definitions( -DKICAD_WIN32_DPI_AWARE=1 ) + endif() endif() @@ -309,6 +325,12 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) endif() if( MINGW ) + list(APPEND mingw_resource_compiler_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/resources/msw/ ) + list(APPEND mingw_resource_compiler_DEFINES KICAD_BUILD_ARCH=${KICAD_BUILD_ARCH} ) + if( KICAD_WIN32_DPI_AWARE ) + list(APPEND mingw_resource_compiler_DEFINES KICAD_WIN32_DPI_AWARE=1 ) + endif() + set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) # Since version 2.8.5, Cmake uses a response file (.rsp) to @@ -355,6 +377,8 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) if( MSVC ) + include_directories( ${CMAKE_SOURCE_DIR}/resources/msw/ ) + # Disallow implicit linking for Boost add_definitions( -DBOOST_ALL_NO_LIB ) # But allow it for the UUID so that it will link against bcrypt @@ -375,11 +399,11 @@ if( MSVC ) string( APPEND CMAKE_CXX_FLAGS_RELEASE " /GF" ) foreach( type EXE SHARED MODULE) # /DEBUG: create PDB - string( APPEND CMAKE_${type}_LINKER_FLAGS " /DEBUG" ) + string( APPEND CMAKE_${type}_LINKER_FLAGS " /DEBUG /MANIFEST:NO" ) # /OPT:REF: omit unreferenced code - string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:REF" ) + string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:REF /MANIFEST:NO" ) # /OPT:ICF: fold common data - string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:ICF" ) + string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:ICF /MANIFEST:NO" ) endforeach() # Let cl.exe parallelize builds diff --git a/CMakeModules/MinGWResourceCompiler.cmake b/CMakeModules/MinGWResourceCompiler.cmake index 0e13ee5539..14e7197e42 100644 --- a/CMakeModules/MinGWResourceCompiler.cmake +++ b/CMakeModules/MinGWResourceCompiler.cmake @@ -24,10 +24,20 @@ macro(mingw_resource_compiler _NAME) foreach(wx_include_dir ${wxWidgets_INCLUDE_DIRS}) set(_WINDRES_INCLUDE_DIRS ${_WINDRES_INCLUDE_DIRS} -I${wx_include_dir}) endforeach(wx_include_dir ${wxWidgets_INCLUDE_DIRS}) + + foreach(_mingw_rc_include_dir ${mingw_resource_compiler_INCLUDE_DIRS}) + set(_WINDRES_INCLUDE_DIRS ${_WINDRES_INCLUDE_DIRS} -I${_mingw_rc_include_dir}) + endforeach() dbg_msg("_WINDRES_INCLUDE_DIRS: ${_WINDRES_INCLUDE_DIRS}") + + foreach(_mingw_rc_define ${mingw_resource_compiler_DEFINES}) + set(_WINDRES_DEFINES ${_WINDRES_DEFINES} -D${_mingw_rc_define}) + endforeach() + dbg_msg("_WINDRES_DEFINES: ${_WINDRES_DEFINES}") + # windres arguments. - set(_ARGS ${_WINDRES_INCLUDE_DIRS} -i${_IN} -o${_OUT}) + set(_ARGS ${_WINDRES_INCLUDE_DIRS} ${_WINDRES_DEFINES} -i${_IN} -o${_OUT}) dbg_msg("_ARGS: ${_ARGS}") # Compile resource file. diff --git a/bitmap2component/bitmap2component.rc b/bitmap2component/bitmap2component.rc index 37c3b72bef..ed8a87598d 100644 --- a/bitmap2component/bitmap2component.rc +++ b/bitmap2component/bitmap2component.rc @@ -1,3 +1,3 @@ icon_bitmap2component ICON "../bitmaps_png/icons/icon_bitmap2component.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/cvpcb/cvpcb.rc b/cvpcb/cvpcb.rc index 4c06802a27..ffb4fa77b8 100644 --- a/cvpcb/cvpcb.rc +++ b/cvpcb/cvpcb.rc @@ -1,2 +1,3 @@ icon_cvpcb ICON "../bitmaps_png/icons/icon_cvpcb.ico" -#include "wx/msw/wx.rc" + +#include "kiwin32.rc" diff --git a/eeschema/eeschema.rc b/eeschema/eeschema.rc index 6c12ddd863..6a3cc69a86 100644 --- a/eeschema/eeschema.rc +++ b/eeschema/eeschema.rc @@ -1,3 +1,3 @@ icon_eeschema ICON "../bitmaps_png/icons/icon_eeschema.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/gerbview/gerbview.rc b/gerbview/gerbview.rc index 05e745b8f0..352e724a0d 100644 --- a/gerbview/gerbview.rc +++ b/gerbview/gerbview.rc @@ -1,3 +1,3 @@ icon_gerbview ICON "../bitmaps_png/icons/icon_gerbview.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/kicad/kicad.rc b/kicad/kicad.rc index 578d82c465..ce1a18a8ba 100644 --- a/kicad/kicad.rc +++ b/kicad/kicad.rc @@ -1,3 +1,3 @@ icon_kicad ICON "../bitmaps_png/icons/icon_kicad.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/pagelayout_editor/pl_editor.rc b/pagelayout_editor/pl_editor.rc index 885f0e6b53..ef394934f7 100644 --- a/pagelayout_editor/pl_editor.rc +++ b/pagelayout_editor/pl_editor.rc @@ -1,3 +1,3 @@ icon_pagelayout_editor ICON "../bitmaps_png/icons/icon_pagelayout_editor.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/pcb_calculator/pcb_calculator.rc b/pcb_calculator/pcb_calculator.rc index 2695e79589..0bfdb74df0 100644 --- a/pcb_calculator/pcb_calculator.rc +++ b/pcb_calculator/pcb_calculator.rc @@ -1,3 +1,3 @@ icon_pcbcalculator ICON "../bitmaps_png/icons/icon_pcbcalculator.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/pcbnew/pcbnew.rc b/pcbnew/pcbnew.rc index f568bb0391..5d7c800161 100644 --- a/pcbnew/pcbnew.rc +++ b/pcbnew/pcbnew.rc @@ -1,3 +1,3 @@ icon_pcbnew ICON "../bitmaps_png/icons/icon_pcbnew.ico" -#include "wx/msw/wx.rc" +#include "kiwin32.rc" diff --git a/resources/msw/kiwin32.rc b/resources/msw/kiwin32.rc new file mode 100644 index 0000000000..3921c3e53c --- /dev/null +++ b/resources/msw/kiwin32.rc @@ -0,0 +1,32 @@ +// Turn off wxWidgets attempting to use its own manifests +#define wxUSE_NO_MANIFEST 1 +#include "wx/msw/wx.rc" + +#ifdef ISOLATION_AWARE_ENABLED +#define MANIFEST_ID ISOLATIONAWARE_MANIFEST_RESOURCE_ID +#else +#define MANIFEST_ID CREATEPROCESS_MANIFEST_RESOURCE_ID +#endif + +#if !defined( KICAD_WIN32_DPI_AWARE ) || KICAD_WIN32_DPI_AWARE == 0 +#define MANIFEST_SUFFIX .manifest +#else +#define MANIFEST_SUFFIX _dpi_aware_pmv2.manifest +#endif + +//MSYS2 +#define RC_STR( text ) RC_STR2( text ) +#define RC_STR2( text ) #text +//MSVC +#define RC_CONCAT( a, b, c ) RC_CONCAT2( a, b, c ) +#define RC_CONCAT2( a, b, c ) a##b##c + +#ifdef __GNUC__ +#define MANIFEST_FILE "manifests/" RC_STR( KICAD_BUILD_ARCH ) RC_STR( MANIFEST_SUFFIX ) +#else +//Do not try and quote the first part, it won't work, also make sure the IDE doesn't reformat it with spaces between slashes +#define MANIFEST_FILE RC_CONCAT( manifests/, KICAD_BUILD_ARCH, MANIFEST_SUFFIX ) +#endif + +MANIFEST_ID RT_MANIFEST MANIFEST_FILE +//RESOURCE FILES MUST CONTAIN A BLANK LINE AT THE END diff --git a/resources/msw/manifests/x64.manifest b/resources/msw/manifests/x64.manifest new file mode 100644 index 0000000000..c6de835dba --- /dev/null +++ b/resources/msw/manifests/x64.manifest @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/resources/msw/manifests/x64_dpi_aware_pmv2.manifest b/resources/msw/manifests/x64_dpi_aware_pmv2.manifest new file mode 100644 index 0000000000..39c2c5ff43 --- /dev/null +++ b/resources/msw/manifests/x64_dpi_aware_pmv2.manifest @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + PerMonitorV2, system + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/msw/manifests/x86.manifest b/resources/msw/manifests/x86.manifest new file mode 100644 index 0000000000..4fbbc3788e --- /dev/null +++ b/resources/msw/manifests/x86.manifest @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/resources/msw/manifests/x86_dpi_aware_pmv2.manifest b/resources/msw/manifests/x86_dpi_aware_pmv2.manifest new file mode 100644 index 0000000000..c3b0191ffa --- /dev/null +++ b/resources/msw/manifests/x86_dpi_aware_pmv2.manifest @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + PerMonitorV2, system + true + + + + + + + + + + + + + + + + + \ No newline at end of file