I am using CMake to compile an EFI application for ARM64 with MSVC. EFI applications are not compatible with the /DYNAMICBASE linker command line switch, which CMake adds by default. For x86-64, it’s enough to add /DYNAMICBASE:NO to the linker command with add_link_options (/DYNAMICBASE:NO)
, but this isn’t enough for ARM64, the original /DYNAMICBASE must be removed.
So I need to remove the default /DYNAMICBASE from the linker command line. How do I do this?
I know the command line being generated by CMake includes /DYNAMICBASE from running cmake --build . --verbose, and I know that I am not adding the /DYNAMICBASE myself anywhere. It is coming from CMake itself.
I tried modifying LINK_OPTIONS, and that doesn’t remove it:
get_target_property (project_linkopts project LINK_OPTIONS)
list (REMOVE_ITEM project_linkopts “/DYNAMICBASE”)
set_target_properties(project PROPERTIES LINK_OPTIONS “${project_linkopts}”)
Using prints, I found that /DYNAMICBASE isn’t present in LINK_OPTIONS to begin with, it’s coming from somewhere else.
It’s built-in to the MSBuild templates that the MSBuild-based generators use. These were generated directly from the templates that MS ships with Visual Studio with the Source/cmConvertMSBuildXMLToJSON.py
script.
The simple answer is to use a generator other than MSBuild that doesn’t have such built-in flag assumptions. Ninja is the usual recommendation.