Set LINK_FLAGS for INTERFACE libraries in cmake












1















I am working on a header-only C++11 library which uses modern CMake. By "modern," I mean not only using CMake v3.0+ but also trying to use as much as possible the best practices in Daniel Pfeifer's talk.



I have done some research on my question, but the answers are mostly regarding modifying the LINK_FLAGS directly in the global level, which I do not want to have. Right now, in my project, I require a minimum version of 3.9.0 of CMake because of some features I am using.



My question is about whether/how to add LINK_FLAGS coming from two of my dependencies: BLAS and LAPACK. Basically, I have the following excerpt from my CMakeLists.txt file:



cmake_minimum_required(VERSION 3.9.0)

project(polo VERSION 1.0.0 LANGUAGES C CXX)

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

add_library(polo INTERFACE)
add_library(polo::polo ALIAS polo)

target_compile_features(polo INTERFACE cxx_std_11)

target_include_directories(polo
INTERFACE
$<BUILD_INTERFACE:${polo_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(polo
INTERFACE
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)

set_property(
TARGET
polo
PROPERTY LINK_FLAGS
${BLAS_LINKER_FLAGS}
${LAPACK_LINKER_FLAGS}
)


As far as I can understand from documentations of the FindBLAS and FindLAPACK modules, I need to inform my users at least about {BLAS,LAPACK}_LIBRARIES and {BLAS,LAPACK}_LINKER_FLAGS. For the former, I think I have handled the issue properly. However, for the latter, I need to use either set_target_properties or set_property. Between the two, the latter seems to give me a cleaner solution in that I can use both variables coming from Find{BLAS,LAPACK} modules together. When I try to build my library using the above solution, I get the obvious error:



CMake Error at src/CMakeLists.txt:32 (set_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_FLAGS" is not allowed.


My question is two folds:




  1. Should I use *_LINKER_FLAGS coming from the modules at all, and,

  2. If yes, how should I integrate them cleanly into my CMake project?


As for the 2. above, I have seen some suggestions/answers for using target_link_libraries, but I am not sure whether that is the option to go for.



Thank you for your time!










share|improve this question























  • What do you mean by your users? You mean people using your library?

    – Matthieu Brucher
    Nov 19 '18 at 12:45













  • Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

    – Arda Aytekin
    Nov 19 '18 at 13:00
















1















I am working on a header-only C++11 library which uses modern CMake. By "modern," I mean not only using CMake v3.0+ but also trying to use as much as possible the best practices in Daniel Pfeifer's talk.



I have done some research on my question, but the answers are mostly regarding modifying the LINK_FLAGS directly in the global level, which I do not want to have. Right now, in my project, I require a minimum version of 3.9.0 of CMake because of some features I am using.



My question is about whether/how to add LINK_FLAGS coming from two of my dependencies: BLAS and LAPACK. Basically, I have the following excerpt from my CMakeLists.txt file:



cmake_minimum_required(VERSION 3.9.0)

project(polo VERSION 1.0.0 LANGUAGES C CXX)

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

add_library(polo INTERFACE)
add_library(polo::polo ALIAS polo)

target_compile_features(polo INTERFACE cxx_std_11)

target_include_directories(polo
INTERFACE
$<BUILD_INTERFACE:${polo_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(polo
INTERFACE
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)

set_property(
TARGET
polo
PROPERTY LINK_FLAGS
${BLAS_LINKER_FLAGS}
${LAPACK_LINKER_FLAGS}
)


As far as I can understand from documentations of the FindBLAS and FindLAPACK modules, I need to inform my users at least about {BLAS,LAPACK}_LIBRARIES and {BLAS,LAPACK}_LINKER_FLAGS. For the former, I think I have handled the issue properly. However, for the latter, I need to use either set_target_properties or set_property. Between the two, the latter seems to give me a cleaner solution in that I can use both variables coming from Find{BLAS,LAPACK} modules together. When I try to build my library using the above solution, I get the obvious error:



CMake Error at src/CMakeLists.txt:32 (set_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_FLAGS" is not allowed.


My question is two folds:




  1. Should I use *_LINKER_FLAGS coming from the modules at all, and,

  2. If yes, how should I integrate them cleanly into my CMake project?


As for the 2. above, I have seen some suggestions/answers for using target_link_libraries, but I am not sure whether that is the option to go for.



Thank you for your time!










share|improve this question























  • What do you mean by your users? You mean people using your library?

    – Matthieu Brucher
    Nov 19 '18 at 12:45













  • Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

    – Arda Aytekin
    Nov 19 '18 at 13:00














1












1








1


1






I am working on a header-only C++11 library which uses modern CMake. By "modern," I mean not only using CMake v3.0+ but also trying to use as much as possible the best practices in Daniel Pfeifer's talk.



I have done some research on my question, but the answers are mostly regarding modifying the LINK_FLAGS directly in the global level, which I do not want to have. Right now, in my project, I require a minimum version of 3.9.0 of CMake because of some features I am using.



My question is about whether/how to add LINK_FLAGS coming from two of my dependencies: BLAS and LAPACK. Basically, I have the following excerpt from my CMakeLists.txt file:



cmake_minimum_required(VERSION 3.9.0)

project(polo VERSION 1.0.0 LANGUAGES C CXX)

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

add_library(polo INTERFACE)
add_library(polo::polo ALIAS polo)

target_compile_features(polo INTERFACE cxx_std_11)

target_include_directories(polo
INTERFACE
$<BUILD_INTERFACE:${polo_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(polo
INTERFACE
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)

set_property(
TARGET
polo
PROPERTY LINK_FLAGS
${BLAS_LINKER_FLAGS}
${LAPACK_LINKER_FLAGS}
)


As far as I can understand from documentations of the FindBLAS and FindLAPACK modules, I need to inform my users at least about {BLAS,LAPACK}_LIBRARIES and {BLAS,LAPACK}_LINKER_FLAGS. For the former, I think I have handled the issue properly. However, for the latter, I need to use either set_target_properties or set_property. Between the two, the latter seems to give me a cleaner solution in that I can use both variables coming from Find{BLAS,LAPACK} modules together. When I try to build my library using the above solution, I get the obvious error:



CMake Error at src/CMakeLists.txt:32 (set_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_FLAGS" is not allowed.


My question is two folds:




  1. Should I use *_LINKER_FLAGS coming from the modules at all, and,

  2. If yes, how should I integrate them cleanly into my CMake project?


As for the 2. above, I have seen some suggestions/answers for using target_link_libraries, but I am not sure whether that is the option to go for.



Thank you for your time!










share|improve this question














I am working on a header-only C++11 library which uses modern CMake. By "modern," I mean not only using CMake v3.0+ but also trying to use as much as possible the best practices in Daniel Pfeifer's talk.



I have done some research on my question, but the answers are mostly regarding modifying the LINK_FLAGS directly in the global level, which I do not want to have. Right now, in my project, I require a minimum version of 3.9.0 of CMake because of some features I am using.



My question is about whether/how to add LINK_FLAGS coming from two of my dependencies: BLAS and LAPACK. Basically, I have the following excerpt from my CMakeLists.txt file:



cmake_minimum_required(VERSION 3.9.0)

project(polo VERSION 1.0.0 LANGUAGES C CXX)

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)

add_library(polo INTERFACE)
add_library(polo::polo ALIAS polo)

target_compile_features(polo INTERFACE cxx_std_11)

target_include_directories(polo
INTERFACE
$<BUILD_INTERFACE:${polo_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(polo
INTERFACE
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)

set_property(
TARGET
polo
PROPERTY LINK_FLAGS
${BLAS_LINKER_FLAGS}
${LAPACK_LINKER_FLAGS}
)


As far as I can understand from documentations of the FindBLAS and FindLAPACK modules, I need to inform my users at least about {BLAS,LAPACK}_LIBRARIES and {BLAS,LAPACK}_LINKER_FLAGS. For the former, I think I have handled the issue properly. However, for the latter, I need to use either set_target_properties or set_property. Between the two, the latter seems to give me a cleaner solution in that I can use both variables coming from Find{BLAS,LAPACK} modules together. When I try to build my library using the above solution, I get the obvious error:



CMake Error at src/CMakeLists.txt:32 (set_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_FLAGS" is not allowed.


My question is two folds:




  1. Should I use *_LINKER_FLAGS coming from the modules at all, and,

  2. If yes, how should I integrate them cleanly into my CMake project?


As for the 2. above, I have seen some suggestions/answers for using target_link_libraries, but I am not sure whether that is the option to go for.



Thank you for your time!







c++ c++11 cmake cmake-modules






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 12:40









Arda AytekinArda Aytekin

678518




678518













  • What do you mean by your users? You mean people using your library?

    – Matthieu Brucher
    Nov 19 '18 at 12:45













  • Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

    – Arda Aytekin
    Nov 19 '18 at 13:00



















  • What do you mean by your users? You mean people using your library?

    – Matthieu Brucher
    Nov 19 '18 at 12:45













  • Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

    – Arda Aytekin
    Nov 19 '18 at 13:00

















What do you mean by your users? You mean people using your library?

– Matthieu Brucher
Nov 19 '18 at 12:45







What do you mean by your users? You mean people using your library?

– Matthieu Brucher
Nov 19 '18 at 12:45















Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

– Arda Aytekin
Nov 19 '18 at 13:00





Yes, @MatthieuBrucher, I mean the users of the library. In the end, my goal is to have a cmake-enabled, social library where you can simply use add_library(foo foo.c) and target_link_libraries(foo PRIVATE polo::polo) as the user.

– Arda Aytekin
Nov 19 '18 at 13:00












2 Answers
2






active

oldest

votes


















1














First of all, I do apologize to the community for cross posting the issue.



Matthieu has tried helping me with two options:




  1. Providing a helper function so that the consumers of the library could call the function to properly handle the LINK_FLAGS, and,

  2. The IMPORTED library option, which he has kept as the final answer (please see the comments there for the motivation).


Unfortunately, neither of these solutions seem to work. The first one is not a clean way of informing the consumer about your dependencies. The second version seems to work with INTERFACE libraries, but any consumer that depends on the INTERFACE library that build an object, such as, e.g., a C-API of the header-only library that builds a SHARED library, has problems building and installing the IMPORTED library.



The solution seems to be to use CMake v3.13 and above, which, as of the posting date, is in the release candidate (rc3) state. Apparently, CMake v3.13 will be introducing INTERFACE_LINK_OPTIONS for such purposes.



EDIT. CMake v3.13 has been released.






share|improve this answer


























  • Interesting, thanks for letting us know!

    – Matthieu Brucher
    Nov 19 '18 at 21:01











  • Thank you for the brainstorming!

    – Arda Aytekin
    Nov 19 '18 at 21:02











  • @MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

    – Arda Aytekin
    Nov 21 '18 at 15:12



















0














The nice thing is that you can provide a helper .cmake for them (called polo-config.cmake).



One option inside the .cmake file is to create an IMPORTED library, which you hold the flags that you want, probably as PUBLIC this time, so that they are propagated to the next user.



Of course, you need to add the library properly, setting up the include paths, the path to the library...






share|improve this answer


























  • Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

    – Arda Aytekin
    Nov 19 '18 at 15:16













  • By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

    – Arda Aytekin
    Nov 19 '18 at 15:17











  • These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

    – Matthieu Brucher
    Nov 19 '18 at 15:22











  • And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

    – Matthieu Brucher
    Nov 19 '18 at 15:23






  • 1





    Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

    – Matthieu Brucher
    Nov 19 '18 at 16:03













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374869%2fset-link-flags-for-interface-libraries-in-cmake%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














First of all, I do apologize to the community for cross posting the issue.



Matthieu has tried helping me with two options:




  1. Providing a helper function so that the consumers of the library could call the function to properly handle the LINK_FLAGS, and,

  2. The IMPORTED library option, which he has kept as the final answer (please see the comments there for the motivation).


Unfortunately, neither of these solutions seem to work. The first one is not a clean way of informing the consumer about your dependencies. The second version seems to work with INTERFACE libraries, but any consumer that depends on the INTERFACE library that build an object, such as, e.g., a C-API of the header-only library that builds a SHARED library, has problems building and installing the IMPORTED library.



The solution seems to be to use CMake v3.13 and above, which, as of the posting date, is in the release candidate (rc3) state. Apparently, CMake v3.13 will be introducing INTERFACE_LINK_OPTIONS for such purposes.



EDIT. CMake v3.13 has been released.






share|improve this answer


























  • Interesting, thanks for letting us know!

    – Matthieu Brucher
    Nov 19 '18 at 21:01











  • Thank you for the brainstorming!

    – Arda Aytekin
    Nov 19 '18 at 21:02











  • @MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

    – Arda Aytekin
    Nov 21 '18 at 15:12
















1














First of all, I do apologize to the community for cross posting the issue.



Matthieu has tried helping me with two options:




  1. Providing a helper function so that the consumers of the library could call the function to properly handle the LINK_FLAGS, and,

  2. The IMPORTED library option, which he has kept as the final answer (please see the comments there for the motivation).


Unfortunately, neither of these solutions seem to work. The first one is not a clean way of informing the consumer about your dependencies. The second version seems to work with INTERFACE libraries, but any consumer that depends on the INTERFACE library that build an object, such as, e.g., a C-API of the header-only library that builds a SHARED library, has problems building and installing the IMPORTED library.



The solution seems to be to use CMake v3.13 and above, which, as of the posting date, is in the release candidate (rc3) state. Apparently, CMake v3.13 will be introducing INTERFACE_LINK_OPTIONS for such purposes.



EDIT. CMake v3.13 has been released.






share|improve this answer


























  • Interesting, thanks for letting us know!

    – Matthieu Brucher
    Nov 19 '18 at 21:01











  • Thank you for the brainstorming!

    – Arda Aytekin
    Nov 19 '18 at 21:02











  • @MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

    – Arda Aytekin
    Nov 21 '18 at 15:12














1












1








1







First of all, I do apologize to the community for cross posting the issue.



Matthieu has tried helping me with two options:




  1. Providing a helper function so that the consumers of the library could call the function to properly handle the LINK_FLAGS, and,

  2. The IMPORTED library option, which he has kept as the final answer (please see the comments there for the motivation).


Unfortunately, neither of these solutions seem to work. The first one is not a clean way of informing the consumer about your dependencies. The second version seems to work with INTERFACE libraries, but any consumer that depends on the INTERFACE library that build an object, such as, e.g., a C-API of the header-only library that builds a SHARED library, has problems building and installing the IMPORTED library.



The solution seems to be to use CMake v3.13 and above, which, as of the posting date, is in the release candidate (rc3) state. Apparently, CMake v3.13 will be introducing INTERFACE_LINK_OPTIONS for such purposes.



EDIT. CMake v3.13 has been released.






share|improve this answer















First of all, I do apologize to the community for cross posting the issue.



Matthieu has tried helping me with two options:




  1. Providing a helper function so that the consumers of the library could call the function to properly handle the LINK_FLAGS, and,

  2. The IMPORTED library option, which he has kept as the final answer (please see the comments there for the motivation).


Unfortunately, neither of these solutions seem to work. The first one is not a clean way of informing the consumer about your dependencies. The second version seems to work with INTERFACE libraries, but any consumer that depends on the INTERFACE library that build an object, such as, e.g., a C-API of the header-only library that builds a SHARED library, has problems building and installing the IMPORTED library.



The solution seems to be to use CMake v3.13 and above, which, as of the posting date, is in the release candidate (rc3) state. Apparently, CMake v3.13 will be introducing INTERFACE_LINK_OPTIONS for such purposes.



EDIT. CMake v3.13 has been released.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 15:10

























answered Nov 19 '18 at 20:16









Arda AytekinArda Aytekin

678518




678518













  • Interesting, thanks for letting us know!

    – Matthieu Brucher
    Nov 19 '18 at 21:01











  • Thank you for the brainstorming!

    – Arda Aytekin
    Nov 19 '18 at 21:02











  • @MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

    – Arda Aytekin
    Nov 21 '18 at 15:12



















  • Interesting, thanks for letting us know!

    – Matthieu Brucher
    Nov 19 '18 at 21:01











  • Thank you for the brainstorming!

    – Arda Aytekin
    Nov 19 '18 at 21:02











  • @MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

    – Arda Aytekin
    Nov 21 '18 at 15:12

















Interesting, thanks for letting us know!

– Matthieu Brucher
Nov 19 '18 at 21:01





Interesting, thanks for letting us know!

– Matthieu Brucher
Nov 19 '18 at 21:01













Thank you for the brainstorming!

– Arda Aytekin
Nov 19 '18 at 21:02





Thank you for the brainstorming!

– Arda Aytekin
Nov 19 '18 at 21:02













@MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

– Arda Aytekin
Nov 21 '18 at 15:12





@MatthieuBrucher, CMake v3.13 has been released and the target_link_options command seems to work.

– Arda Aytekin
Nov 21 '18 at 15:12













0














The nice thing is that you can provide a helper .cmake for them (called polo-config.cmake).



One option inside the .cmake file is to create an IMPORTED library, which you hold the flags that you want, probably as PUBLIC this time, so that they are propagated to the next user.



Of course, you need to add the library properly, setting up the include paths, the path to the library...






share|improve this answer


























  • Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

    – Arda Aytekin
    Nov 19 '18 at 15:16













  • By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

    – Arda Aytekin
    Nov 19 '18 at 15:17











  • These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

    – Matthieu Brucher
    Nov 19 '18 at 15:22











  • And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

    – Matthieu Brucher
    Nov 19 '18 at 15:23






  • 1





    Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

    – Matthieu Brucher
    Nov 19 '18 at 16:03


















0














The nice thing is that you can provide a helper .cmake for them (called polo-config.cmake).



One option inside the .cmake file is to create an IMPORTED library, which you hold the flags that you want, probably as PUBLIC this time, so that they are propagated to the next user.



Of course, you need to add the library properly, setting up the include paths, the path to the library...






share|improve this answer


























  • Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

    – Arda Aytekin
    Nov 19 '18 at 15:16













  • By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

    – Arda Aytekin
    Nov 19 '18 at 15:17











  • These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

    – Matthieu Brucher
    Nov 19 '18 at 15:22











  • And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

    – Matthieu Brucher
    Nov 19 '18 at 15:23






  • 1





    Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

    – Matthieu Brucher
    Nov 19 '18 at 16:03
















0












0








0







The nice thing is that you can provide a helper .cmake for them (called polo-config.cmake).



One option inside the .cmake file is to create an IMPORTED library, which you hold the flags that you want, probably as PUBLIC this time, so that they are propagated to the next user.



Of course, you need to add the library properly, setting up the include paths, the path to the library...






share|improve this answer















The nice thing is that you can provide a helper .cmake for them (called polo-config.cmake).



One option inside the .cmake file is to create an IMPORTED library, which you hold the flags that you want, probably as PUBLIC this time, so that they are propagated to the next user.



Of course, you need to add the library properly, setting up the include paths, the path to the library...







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 16:22

























answered Nov 19 '18 at 14:20









Matthieu BrucherMatthieu Brucher

14.1k32140




14.1k32140













  • Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

    – Arda Aytekin
    Nov 19 '18 at 15:16













  • By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

    – Arda Aytekin
    Nov 19 '18 at 15:17











  • These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

    – Matthieu Brucher
    Nov 19 '18 at 15:22











  • And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

    – Matthieu Brucher
    Nov 19 '18 at 15:23






  • 1





    Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

    – Matthieu Brucher
    Nov 19 '18 at 16:03





















  • Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

    – Arda Aytekin
    Nov 19 '18 at 15:16













  • By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

    – Arda Aytekin
    Nov 19 '18 at 15:17











  • These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

    – Matthieu Brucher
    Nov 19 '18 at 15:22











  • And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

    – Matthieu Brucher
    Nov 19 '18 at 15:23






  • 1





    Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

    – Matthieu Brucher
    Nov 19 '18 at 16:03



















Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

– Arda Aytekin
Nov 19 '18 at 15:16







Thank you for your response. I do appreciate your time, but I still do not understand some things. First, I already provide the consumers of my library with a config file, which is found by CMake after a call to find_package(polo). This file already lists my dependencies, which I later on use on my CMake project. Why should any consumer of polo need to know anything about my dependencies, if I define them properly? I mean, why should I list my libraries as in the example, again, as you have provided?

– Arda Aytekin
Nov 19 '18 at 15:16















By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

– Arda Aytekin
Nov 19 '18 at 15:17





By the way, you might have a typo in your function definition --- target_include_directories should read target_link_libraries for BLAS and LAPACK, I assume, or?

– Arda Aytekin
Nov 19 '18 at 15:17













These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

– Matthieu Brucher
Nov 19 '18 at 15:22





These are properties of a target that is already built. But they are in CMake language, not in the file itself. So you need a way of propagating these flags from your polo target (that doesn't exist for the user) to the users target, and that what the config file does.

– Matthieu Brucher
Nov 19 '18 at 15:22













And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

– Matthieu Brucher
Nov 19 '18 at 15:23





And indeed, it was target_link_library. For instance, for pybind11, libsimdpp, they provide functions in their CMakeLists or their .cmake to do proper links with the proper flags.

– Matthieu Brucher
Nov 19 '18 at 15:23




1




1





Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

– Matthieu Brucher
Nov 19 '18 at 16:03







Added also the IMPORTED solution which could fit your purpose better (not sure you should make the used libraries part of your interface, especially if they are shared libs? Except blas/lapack, but would it matter to have them private?)

– Matthieu Brucher
Nov 19 '18 at 16:03




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374869%2fset-link-flags-for-interface-libraries-in-cmake%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?