Visual C++ Compile/Link Flags

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

Visual C++ Compile/Link Flags

ThePhD
I have a project where I attempt to add linker flags to a Visual Studio project using

     target_link_libraries(lib_target PRIVATE /OPT:NOREF)

But it seems like the `/` syntax automatically has CMake assuming that the flag is a file, and it complains it cannot find the file. Is there any way to have CMake recognize a passed-in linker flag using this syntax? As a side note, is there perhaps a better way of passing in Linker flags that I am not aware of? Documentation stated that using "target_link_libraries" is preferred, and I did not find "target_link_options".

--

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: Visual C++ Compile/Link Flags

Volker Enderlein

set_target_properties(target PROPERTIES LINK_FLAGS "/OPT:NOREF") should
work.

Am 13/02/2018 um 14:38 schrieb ThePhD:

> I have a project where I attempt to add linker flags to a Visual
> Studio project using
>
>      target_link_libraries(lib_target PRIVATE /OPT:NOREF)
>
> But it seems like the `/` syntax automatically has CMake assuming that
> the flag is a file, and it complains it cannot find the file. Is there
> any way to have CMake recognize a passed-in linker flag using this
> syntax? As a side note, is there perhaps a better way of passing in
> Linker flags that I am not aware of? Documentation stated that using
> "target_link_libraries" is preferred, and I did not find
> "target_link_options".
>
--

--

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: Visual C++ Compile/Link Flags

Jano Svitok
In reply to this post by ThePhD
On Tue, Feb 13, 2018 at 2:38 PM, ThePhD <[hidden email]> wrote:
I have a project where I attempt to add linker flags to a Visual Studio project using

     target_link_libraries(lib_target PRIVATE /OPT:NOREF)

But it seems like the `/` syntax automatically has CMake assuming that the flag is a file, and it complains it cannot find the file. Is there any way to have CMake recognize a passed-in linker flag using this syntax? As a side note, is there perhaps a better way of passing in Linker flags that I am not aware of? Documentation stated that using "target_link_libraries" is preferred, and I did not find "target_link_options".

You can try this; I don't know if this is the preferred way to do it.

set_property( TARGET lib_target APPEND_STRING PROPERTY LINK_FLAGS " /OPT:NOREF" )

Jano


--

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: Visual C++ Compile/Link Flags

ThePhD
In reply to this post by Volker Enderlein
Thank you, Jano Svitok and Volker Enderlein.

     I settled for using "set_target_properties( ... )", and to specify multiple LINK_FLAGS I encapsulated both arguments I wanted to pass in a single set of quotes (with a space between them). I suppose the APPEND_STRING approach could also work well, if I wanted to add multiple.

I appreciate the help!

On Tue, Feb 13, 2018 at 9:11 AM, Volker Enderlein <[hidden email]> wrote:

set_target_properties(target PROPERTIES LINK_FLAGS "/OPT:NOREF") should work.


Am 13/02/2018 um 14:38 schrieb ThePhD:
I have a project where I attempt to add linker flags to a Visual Studio project using

     target_link_libraries(lib_target PRIVATE /OPT:NOREF)

But it seems like the `/` syntax automatically has CMake assuming that the flag is a file, and it complains it cannot find the file. Is there any way to have CMake recognize a passed-in linker flag using this syntax? As a side note, is there perhaps a better way of passing in Linker flags that I am not aware of? Documentation stated that using "target_link_libraries" is preferred, and I did not find "target_link_options".

--

--

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: Visual C++ Compile/Link Flags

Shoaib Meenai

Visual Studio's linker (and compiler, for that matter) also accept flags that start with dashes instead of slashes (e.g. you can do -opt:noref instead of /opt:noref).

 

From: CMake <[hidden email]> on behalf of ThePhD <[hidden email]>
Date: Tuesday, February 13, 2018 at 1:10 PM
To: "[hidden email]" <[hidden email]>
Subject: Re: [CMake] Visual C++ Compile/Link Flags

 

Thank you, Jano Svitok and Volker Enderlein.

     I settled for using "set_target_properties( ... )", and to specify multiple LINK_FLAGS I encapsulated both arguments I wanted to pass in a single set of quotes (with a space between them). I suppose the APPEND_STRING approach could also work well, if I wanted to add multiple.

I appreciate the help!

 

On Tue, Feb 13, 2018 at 9:11 AM, Volker Enderlein <[hidden email]> wrote:


set_target_properties(target PROPERTIES LINK_FLAGS "/OPT:NOREF") should work.



Am 13/02/2018 um 14:38 schrieb ThePhD:

I have a project where I attempt to add linker flags to a Visual Studio project using

     target_link_libraries(lib_target PRIVATE /OPT:NOREF)

But it seems like the `/` syntax automatically has CMake assuming that the flag is a file, and it complains it cannot find the file. Is there any way to have CMake recognize a passed-in linker flag using this syntax? As a side note, is there perhaps a better way of passing in Linker flags that I am not aware of? Documentation stated that using "target_link_libraries" is preferred, and I did not find "target_link_options".

--

--

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