CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Alexander
Hello,

I would like to add an extra .defs file for linking of a DLL on Windows. I want to use the CMake command line option -DCMAKE_SHARED_LINKER_FLAGS="/DEF:my_defs.defs". I expect that besides the automatically generated <project_path>/bin/<project>.dir/Release/exports.def i see additionally /DEF:my_defs.defs in the resulting linking command, but it does not happen.

What is especially irritating that CMake deliberately removes namely /DEF: from CMAKE_SHARED_LINKER_FLAGS. Any other word combinations (if I write  /DEF111:my_defs.def for example) are accepted and I see them the linking command.

I tried to reach the same goal using a CMakeLists.txt like this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:my_defs.def")
but it did not help - the same way CMake removes my /DEF: option.

Could you please open a ticket to fix this behavior to not cut /DEF: option from CMAKE_***_LINKER_FLAGS?

On my opinion CMake should not interpret or modify the content of CMAKE_SHARED_LINKER_FLAGS value, but should put it entirely as the user specified it. If you have another opinion, please provide any other possibility to pass an arbitrary arguments to the linking command "as is" so that they are not modified.

Any workaround is highly appreciated (better command-line, because we build 3rd party software and it would not really fine to change CMakeLists.txt)

--
Best Regards,
Alexander Samoilov
Build & Integration Engineer
Compart AG, 71034 Böblingen Germany

--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Cristian Adam
Hi,

You should simply add the my_defs.def file as a source files to add_library/add_executable.
CMake will automagically pass /DEF: to the linker with my_defs.def

Cheers,
Cristian. 

On Fri, Oct 4, 2019 at 4:45 PM Alexander <[hidden email]> wrote:
Hello,

I would like to add an extra .defs file for linking of a DLL on Windows. I want to use the CMake command line option -DCMAKE_SHARED_LINKER_FLAGS="/DEF:my_defs.defs". I expect that besides the automatically generated <project_path>/bin/<project>.dir/Release/exports.def i see additionally /DEF:my_defs.defs in the resulting linking command, but it does not happen.

What is especially irritating that CMake deliberately removes namely /DEF: from CMAKE_SHARED_LINKER_FLAGS. Any other word combinations (if I write  /DEF111:my_defs.def for example) are accepted and I see them the linking command.

I tried to reach the same goal using a CMakeLists.txt like this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:my_defs.def")
but it did not help - the same way CMake removes my /DEF: option.

Could you please open a ticket to fix this behavior to not cut /DEF: option from CMAKE_***_LINKER_FLAGS?

On my opinion CMake should not interpret or modify the content of CMAKE_SHARED_LINKER_FLAGS value, but should put it entirely as the user specified it. If you have another opinion, please provide any other possibility to pass an arbitrary arguments to the linking command "as is" so that they are not modified.

Any workaround is highly appreciated (better command-line, because we build 3rd party software and it would not really fine to change CMakeLists.txt)

--
Best Regards,
Alexander Samoilov
Build & Integration Engineer
Compart AG, 71034 Böblingen Germany
--

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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Alexander
Dear Cristian,

It would better for me not modifying CMakeFiles.txt, because as I wrote it is 3rd party stuff (we just download it and build, but some different way).
My concern is why the command line option -DCMAKE_SHARED_LINKER_FLAGS deliberately ignores /DEF: option. It this behavior expected? What is the logic behind this behavior? Why not simply allow /DEF in CMAKE_SHARED_LINKER_FLAGS and not cut it?

--
Best Regards,
Alexander

On Fri, 4 Oct 2019 at 16:54, Cristian Adam <[hidden email]> wrote:
Hi,

You should simply add the my_defs.def file as a source files to add_library/add_executable.
CMake will automagically pass /DEF: to the linker with my_defs.def

Cheers,
Cristian. 

On Fri, Oct 4, 2019 at 4:45 PM Alexander <[hidden email]> wrote:
Hello,

I would like to add an extra .defs file for linking of a DLL on Windows. I want to use the CMake command line option -DCMAKE_SHARED_LINKER_FLAGS="/DEF:my_defs.defs". I expect that besides the automatically generated <project_path>/bin/<project>.dir/Release/exports.def i see additionally /DEF:my_defs.defs in the resulting linking command, but it does not happen.

What is especially irritating that CMake deliberately removes namely /DEF: from CMAKE_SHARED_LINKER_FLAGS. Any other word combinations (if I write  /DEF111:my_defs.def for example) are accepted and I see them the linking command.

I tried to reach the same goal using a CMakeLists.txt like this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:my_defs.def")
but it did not help - the same way CMake removes my /DEF: option.

Could you please open a ticket to fix this behavior to not cut /DEF: option from CMAKE_***_LINKER_FLAGS?

On my opinion CMake should not interpret or modify the content of CMAKE_SHARED_LINKER_FLAGS value, but should put it entirely as the user specified it. If you have another opinion, please provide any other possibility to pass an arbitrary arguments to the linking command "as is" so that they are not modified.

Any workaround is highly appreciated (better command-line, because we build 3rd party software and it would not really fine to change CMakeLists.txt)

--
Best Regards,
Alexander Samoilov
Build & Integration Engineer
Compart AG, 71034 Böblingen Germany
--

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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Craig Scott-3


On Sat, Oct 5, 2019 at 12:59 AM Alexander <[hidden email]> wrote:
Dear Cristian,

It would better for me not modifying CMakeFiles.txt, because as I wrote it is 3rd party stuff (we just download it and build, but some different way).
My concern is why the command line option -DCMAKE_SHARED_LINKER_FLAGS deliberately ignores /DEF: option. It this behavior expected? What is the logic behind this behavior? Why not simply allow /DEF in CMAKE_SHARED_LINKER_FLAGS and not cut it?


You don't have to modify the third party CMakeLists.txt file to achieve what Cristian suggested. You can call target_sources() on the third party target from your own CMakeLists.txt file to add .def files to their target. You don't have to be in the same directory scope as the target to use target_sources() on it.

I'm not familiar with why CMake is stripping out the /DEF: option in your case, but I suspect it would be related to the way CMake expects to add such options based on .def files given as sources.

 
On Fri, 4 Oct 2019 at 16:54, Cristian Adam <[hidden email]> wrote:
Hi,

You should simply add the my_defs.def file as a source files to add_library/add_executable.
CMake will automagically pass /DEF: to the linker with my_defs.def

Cheers,
Cristian. 

On Fri, Oct 4, 2019 at 4:45 PM Alexander <[hidden email]> wrote:
Hello,

I would like to add an extra .defs file for linking of a DLL on Windows. I want to use the CMake command line option -DCMAKE_SHARED_LINKER_FLAGS="/DEF:my_defs.defs". I expect that besides the automatically generated <project_path>/bin/<project>.dir/Release/exports.def i see additionally /DEF:my_defs.defs in the resulting linking command, but it does not happen.

What is especially irritating that CMake deliberately removes namely /DEF: from CMAKE_SHARED_LINKER_FLAGS. Any other word combinations (if I write  /DEF111:my_defs.def for example) are accepted and I see them the linking command.

I tried to reach the same goal using a CMakeLists.txt like this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:my_defs.def")
but it did not help - the same way CMake removes my /DEF: option.

Could you please open a ticket to fix this behavior to not cut /DEF: option from CMAKE_***_LINKER_FLAGS?

On my opinion CMake should not interpret or modify the content of CMAKE_SHARED_LINKER_FLAGS value, but should put it entirely as the user specified it. If you have another opinion, please provide any other possibility to pass an arbitrary arguments to the linking command "as is" so that they are not modified.

Any workaround is highly appreciated (better command-line, because we build 3rd party software and it would not really fine to change CMakeLists.txt)

--
Best Regards,
Alexander Samoilov
Build & Integration Engineer
Compart AG, 71034 Böblingen Germany


--
Craig Scott
Melbourne, Australia

Get the hand-book for every CMake user: Professional CMake: A Practical Guide
Consulting services (CMake, C++, build/release processes): https://crascit.com/services

--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake removes /DEF: option in CMAKE_SHARED_LINKER_FLAGS

Alexander
Hi Craig,
Thank you for this information. I never tried this way with the own CMakeLists.txt and I should try it. I found one efficient workaround however which is the option -DCMAKE_CXX_STANDARD_LIBRARIES=/DEF:additionalDefFile.def. It turned that the content of CMAKE_CXX_STANDARD_LIBRARIES is pushed to the linking command without any preprocessing which is exactly what I wanted (reference: https://cmake.cmake.narkive.com/UuC3PGkF/how-to-append-arbitrary-linker-options). What about stripping of the /DEF:option from CMAKE_SHARED_LINKER_FLAGS I see I would better ask CMake developers ([hidden email]) or submit a bug.

--
Best Regards,
Alexander

On Sat, 5 Oct 2019 at 10:33, Craig Scott <[hidden email]> wrote:


On Sat, Oct 5, 2019 at 12:59 AM Alexander <[hidden email]> wrote:
Dear Cristian,

It would better for me not modifying CMakeFiles.txt, because as I wrote it is 3rd party stuff (we just download it and build, but some different way).
My concern is why the command line option -DCMAKE_SHARED_LINKER_FLAGS deliberately ignores /DEF: option. It this behavior expected? What is the logic behind this behavior? Why not simply allow /DEF in CMAKE_SHARED_LINKER_FLAGS and not cut it?


You don't have to modify the third party CMakeLists.txt file to achieve what Cristian suggested. You can call target_sources() on the third party target from your own CMakeLists.txt file to add .def files to their target. You don't have to be in the same directory scope as the target to use target_sources() on it.

I'm not familiar with why CMake is stripping out the /DEF: option in your case, but I suspect it would be related to the way CMake expects to add such options based on .def files given as sources.

 
On Fri, 4 Oct 2019 at 16:54, Cristian Adam <[hidden email]> wrote:
Hi,

You should simply add the my_defs.def file as a source files to add_library/add_executable.
CMake will automagically pass /DEF: to the linker with my_defs.def

Cheers,
Cristian. 

On Fri, Oct 4, 2019 at 4:45 PM Alexander <[hidden email]> wrote:
Hello,

I would like to add an extra .defs file for linking of a DLL on Windows. I want to use the CMake command line option -DCMAKE_SHARED_LINKER_FLAGS="/DEF:my_defs.defs". I expect that besides the automatically generated <project_path>/bin/<project>.dir/Release/exports.def i see additionally /DEF:my_defs.defs in the resulting linking command, but it does not happen.

What is especially irritating that CMake deliberately removes namely /DEF: from CMAKE_SHARED_LINKER_FLAGS. Any other word combinations (if I write  /DEF111:my_defs.def for example) are accepted and I see them the linking command.

I tried to reach the same goal using a CMakeLists.txt like this:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEF:my_defs.def")
but it did not help - the same way CMake removes my /DEF: option.

Could you please open a ticket to fix this behavior to not cut /DEF: option from CMAKE_***_LINKER_FLAGS?

On my opinion CMake should not interpret or modify the content of CMAKE_SHARED_LINKER_FLAGS value, but should put it entirely as the user specified it. If you have another opinion, please provide any other possibility to pass an arbitrary arguments to the linking command "as is" so that they are not modified.

Any workaround is highly appreciated (better command-line, because we build 3rd party software and it would not really fine to change CMakeLists.txt)

--
Best Regards,
Alexander Samoilov
Build & Integration Engineer
Compart AG, 71034 Böblingen Germany


--
Craig Scott
Melbourne, Australia

Get the hand-book for every CMake user: Professional CMake: A Practical Guide
Consulting services (CMake, C++, build/release processes): https://crascit.com/services

--

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