I am sorry that I did not make it clear from the beginning. You are right.
Not only MSBuild, but MSVC linker (link.exe) accepts only one /DEF
parameter according to
https://docs.microsoft.com/en-us/cpp/build/reference/def-specify-module-definition-file?view=vs-2019
:
"""
The /DEF option passes a module-definition file (.def) to the linker. Only
one .def file can be specified to LINK.
"""
In reality you can pass multiple /DEF to the linker, but it uses the last
one.
The problem is that the original /DEF parameter
/DEF:"E:/workspace/cmake_test_option/tesseract/bin/libtesseract.dir/Release/exports.def"
is added by CMake automatically and I cannot control it (CMake first
creates a file objects.txt and then exports.def from it).
I wanted to override this parameter with a custom /DEF parameter, that
means my /DEF parameter must be passed after that default one in the
linking command.
However, as you can see from the linking command in my previous e-mail, I
could not easily achieve this with the current CMake functionality, because:
- CMAKE_CXX_STANDARD_LIBRARIES adds custom /DEF parameter before the
default /DEF:exports.def that does not help
- CMAKE_SHARED_LINKER_FLAGS adds something to the end of the command, but
only if this something is not /DEF (because one /DEF is already defined and
CMake does not overwrite it, as you said earlier)
So, does CMake provide a way to override the value of the default
/DEF:exports.def or does it provide a way to pass my custom
/DEF after the default one so that link.exe would use my custom /DEF
parameter?
--
Best Regards,
Alexander
On Tue, 5 Nov 2019 at 17:57, Brad King wrote:
> On 11/5/19 7:30 AM, Alexander wrote:
> > string(APPEND CMAKE_SHARED_LINKER_FLAGS " -DEF:\"foo_1.def\"
> -DEF111:\"foo_1.def\"")
>
> This was the first you've mentioned using more than one copy of the flag.
>
> I tested with this:
>
> ```
> string(APPEND CMAKE_SHARED_LINKER_FLAGS "
> -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/foo.def\"")
> string(APPEND CMAKE_SHARED_LINKER_FLAGS "
> -DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/bar.def\"")
> ```
>
> With the command-line generators like Ninja or NMake Makefiles, both flags
> appear. With the Visual Studio generators, only the latter flag appears.
>
> The reason is that CMake maps the `-DEF:` linker flag to the `.vcxproj`
> file element `ModuleDefinitionFile` but only puts one value in it. The
> MSBuild documentation for that field is here:
>
>
> https://docs.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2019
>
> and says "Specifies the name of a module definition file." AFAIK it only
> supports one value. This is a limitation of MSBuild.
>
> -Brad
>
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers