CMake - How to inherit static library includes and dependencies?












0















I'm going to link my static library to some additional dependencies (which are installed in the system) then use this library, but my IDE says "No such file or directory" on inherited includes, like this:



CMakeLists.txt of my library:



find_package(lib1 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib1::lib1)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB1_INCLUDE_DIR})

find_package(lib2 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib2::lib2)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB2_INCLUDE_DIR})


CMakeLists.txt of project which uses my library:



find_library(${CMAKE_BINARY_DIR}/lib/ MyMegaLib.a)
target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib}


Errors are like this:



fatal error: lib1.h: No such file or directory
#include <lib1.h>


What should I do to inherit includes properly?



_
Full hierarchy of my libraries and executables:



pre-lib1, pre-lib2
^^
lib1 (installed at the CMAKE_INSTALL_PREFIX path)
^
MyMegaLib (static library)
^
MyProject(static library and an executable MyProject_tests)


So actually I'm getting errors about pre-lib1 and pre-lib2 about RE2 headers (prelib1.h : no such file or directory, preli2.h : no such file or directory) when I'm trying to cmake' MyProject_tests.










share|improve this question

























  • I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

    – Fred
    Nov 28 '18 at 15:55
















0















I'm going to link my static library to some additional dependencies (which are installed in the system) then use this library, but my IDE says "No such file or directory" on inherited includes, like this:



CMakeLists.txt of my library:



find_package(lib1 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib1::lib1)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB1_INCLUDE_DIR})

find_package(lib2 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib2::lib2)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB2_INCLUDE_DIR})


CMakeLists.txt of project which uses my library:



find_library(${CMAKE_BINARY_DIR}/lib/ MyMegaLib.a)
target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib}


Errors are like this:



fatal error: lib1.h: No such file or directory
#include <lib1.h>


What should I do to inherit includes properly?



_
Full hierarchy of my libraries and executables:



pre-lib1, pre-lib2
^^
lib1 (installed at the CMAKE_INSTALL_PREFIX path)
^
MyMegaLib (static library)
^
MyProject(static library and an executable MyProject_tests)


So actually I'm getting errors about pre-lib1 and pre-lib2 about RE2 headers (prelib1.h : no such file or directory, preli2.h : no such file or directory) when I'm trying to cmake' MyProject_tests.










share|improve this question

























  • I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

    – Fred
    Nov 28 '18 at 15:55














0












0








0








I'm going to link my static library to some additional dependencies (which are installed in the system) then use this library, but my IDE says "No such file or directory" on inherited includes, like this:



CMakeLists.txt of my library:



find_package(lib1 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib1::lib1)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB1_INCLUDE_DIR})

find_package(lib2 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib2::lib2)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB2_INCLUDE_DIR})


CMakeLists.txt of project which uses my library:



find_library(${CMAKE_BINARY_DIR}/lib/ MyMegaLib.a)
target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib}


Errors are like this:



fatal error: lib1.h: No such file or directory
#include <lib1.h>


What should I do to inherit includes properly?



_
Full hierarchy of my libraries and executables:



pre-lib1, pre-lib2
^^
lib1 (installed at the CMAKE_INSTALL_PREFIX path)
^
MyMegaLib (static library)
^
MyProject(static library and an executable MyProject_tests)


So actually I'm getting errors about pre-lib1 and pre-lib2 about RE2 headers (prelib1.h : no such file or directory, preli2.h : no such file or directory) when I'm trying to cmake' MyProject_tests.










share|improve this question
















I'm going to link my static library to some additional dependencies (which are installed in the system) then use this library, but my IDE says "No such file or directory" on inherited includes, like this:



CMakeLists.txt of my library:



find_package(lib1 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib1::lib1)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB1_INCLUDE_DIR})

find_package(lib2 REQUIRED)
target_link_libraries(${MY_MEGA_LIB_NAME} lib2::lib2)
target_include_directories(${MY_MEGA_LIB_NAME} PUBLIC ${LIB2_INCLUDE_DIR})


CMakeLists.txt of project which uses my library:



find_library(${CMAKE_BINARY_DIR}/lib/ MyMegaLib.a)
target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib}


Errors are like this:



fatal error: lib1.h: No such file or directory
#include <lib1.h>


What should I do to inherit includes properly?



_
Full hierarchy of my libraries and executables:



pre-lib1, pre-lib2
^^
lib1 (installed at the CMAKE_INSTALL_PREFIX path)
^
MyMegaLib (static library)
^
MyProject(static library and an executable MyProject_tests)


So actually I'm getting errors about pre-lib1 and pre-lib2 about RE2 headers (prelib1.h : no such file or directory, preli2.h : no such file or directory) when I'm trying to cmake' MyProject_tests.







c++ cmake






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 13:57







Ovoshnoe Ragoo

















asked Nov 28 '18 at 13:26









Ovoshnoe RagooOvoshnoe Ragoo

13




13













  • I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

    – Fred
    Nov 28 '18 at 15:55



















  • I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

    – Fred
    Nov 28 '18 at 15:55

















I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

– Fred
Nov 28 '18 at 15:55





I don't know about to get these properties to inherit across cmake projects. To use a library that was built outside a cmake project simply use the target_link_libraries and target_include_directories. Are you sure target_include_directories(${MY_MEGA_PROJECT} ${PROJECT_SOURCE_DIR}/include/MyMegaLib} is pointing to the correct directory that contains all the required header files? Also you have typos in this command it needs to at least be target_include_directories(${MY_MEGA_PROJECT} PRIVATE ${PROJECT_SOURCE_DIR}/include/MyMegaLib). find_library is also wrong syntax.

– Fred
Nov 28 '18 at 15:55












1 Answer
1






active

oldest

votes


















0














As far as I can tell, in my project it's the TARGET_LINK_LIBRARIES call that pulls in the things exported in the library - don't you have something like that in your case?
Something like:



TARGET_LINK_LIBRARIES(${MY_MEGA_PROJECT} ${MY_MEGA_LIB_NAME})


But this is when specifying include directories/libraries inside the same CMake run.



When you want to reuse a library build in another CMake run, you probably have to import/export these targets and their include directories/library dependencies etc. Libraries which do that typically generate some .cmake files in their build/install directories which provide these targets.






share|improve this answer


























  • I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:43











  • You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

    – codeling
    Nov 28 '18 at 13:52











  • Finally added full hierarchy description in post, please look

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:58











  • Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

    – codeling
    Nov 28 '18 at 14:01













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%2f53520525%2fcmake-how-to-inherit-static-library-includes-and-dependencies%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As far as I can tell, in my project it's the TARGET_LINK_LIBRARIES call that pulls in the things exported in the library - don't you have something like that in your case?
Something like:



TARGET_LINK_LIBRARIES(${MY_MEGA_PROJECT} ${MY_MEGA_LIB_NAME})


But this is when specifying include directories/libraries inside the same CMake run.



When you want to reuse a library build in another CMake run, you probably have to import/export these targets and their include directories/library dependencies etc. Libraries which do that typically generate some .cmake files in their build/install directories which provide these targets.






share|improve this answer


























  • I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:43











  • You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

    – codeling
    Nov 28 '18 at 13:52











  • Finally added full hierarchy description in post, please look

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:58











  • Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

    – codeling
    Nov 28 '18 at 14:01


















0














As far as I can tell, in my project it's the TARGET_LINK_LIBRARIES call that pulls in the things exported in the library - don't you have something like that in your case?
Something like:



TARGET_LINK_LIBRARIES(${MY_MEGA_PROJECT} ${MY_MEGA_LIB_NAME})


But this is when specifying include directories/libraries inside the same CMake run.



When you want to reuse a library build in another CMake run, you probably have to import/export these targets and their include directories/library dependencies etc. Libraries which do that typically generate some .cmake files in their build/install directories which provide these targets.






share|improve this answer


























  • I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:43











  • You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

    – codeling
    Nov 28 '18 at 13:52











  • Finally added full hierarchy description in post, please look

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:58











  • Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

    – codeling
    Nov 28 '18 at 14:01
















0












0








0







As far as I can tell, in my project it's the TARGET_LINK_LIBRARIES call that pulls in the things exported in the library - don't you have something like that in your case?
Something like:



TARGET_LINK_LIBRARIES(${MY_MEGA_PROJECT} ${MY_MEGA_LIB_NAME})


But this is when specifying include directories/libraries inside the same CMake run.



When you want to reuse a library build in another CMake run, you probably have to import/export these targets and their include directories/library dependencies etc. Libraries which do that typically generate some .cmake files in their build/install directories which provide these targets.






share|improve this answer















As far as I can tell, in my project it's the TARGET_LINK_LIBRARIES call that pulls in the things exported in the library - don't you have something like that in your case?
Something like:



TARGET_LINK_LIBRARIES(${MY_MEGA_PROJECT} ${MY_MEGA_LIB_NAME})


But this is when specifying include directories/libraries inside the same CMake run.



When you want to reuse a library build in another CMake run, you probably have to import/export these targets and their include directories/library dependencies etc. Libraries which do that typically generate some .cmake files in their build/install directories which provide these targets.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 14:00

























answered Nov 28 '18 at 13:36









codelingcodeling

8,28332656




8,28332656













  • I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:43











  • You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

    – codeling
    Nov 28 '18 at 13:52











  • Finally added full hierarchy description in post, please look

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:58











  • Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

    – codeling
    Nov 28 '18 at 14:01





















  • I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:43











  • You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

    – codeling
    Nov 28 '18 at 13:52











  • Finally added full hierarchy description in post, please look

    – Ovoshnoe Ragoo
    Nov 28 '18 at 13:58











  • Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

    – codeling
    Nov 28 '18 at 14:01



















I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

– Ovoshnoe Ragoo
Nov 28 '18 at 13:43





I am linking library to my project (which is library too) exactly as you wrote, and the problem is still here.

– Ovoshnoe Ragoo
Nov 28 '18 at 13:43













You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

– codeling
Nov 28 '18 at 13:52





You didn't show it that's why I thought that was the reason ;). I'm doing this in the same CMake configuration run - are you cmake'ing your library and your project in a different cmake run? then there might be additional steps required (but I'm unfortunately out of my depth as to what those might be...)

– codeling
Nov 28 '18 at 13:52













Finally added full hierarchy description in post, please look

– Ovoshnoe Ragoo
Nov 28 '18 at 13:58





Finally added full hierarchy description in post, please look

– Ovoshnoe Ragoo
Nov 28 '18 at 13:58













Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

– codeling
Nov 28 '18 at 14:01







Updated my answer as well (though I can't give you specifics on this export/import procedure unfortunately)! Hope this helps...

– codeling
Nov 28 '18 at 14:01






















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%2f53520525%2fcmake-how-to-inherit-static-library-includes-and-dependencies%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

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)