0

I'm currently work with the project that chosen the CMake as the build system. Nonetheless, I'm not very familiar with CMake. I spent much time on including the third-party library, the result is not very prefer. Could someone provide a way to fix my scenario?

My project tree is given in following section:

|--->top-Level
|--->ThirdLib
|------>Lib1
|---------->DLL
|---------->Include
|---------->LIB
|------>Lib2
|---------->DLL
|---------->Include
|---------->LIB
|--->UseThirdLib
|----->test.h                  //this file will used third-part lib

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Savner_Dig
  • 21
  • 1
  • 8
  • Maybe this thread helps: [How to properly link libraries with cmake?](https://stackoverflow.com/questions/39598323/how-to-properly-link-libraries-with-cmake) – hddmss Aug 26 '21 at 03:41
  • In the net there are many examples (and even tutorials) about using third-party library in CMake. Please, add your attempt into the question post. With the current form your scenario is quite vague: e.g. I see neither executable nor library created in your project and which uses third-party libraries. Also, by providing the code you would show your level of understanding of CMake. So we won't suggest you an answer which you cannot understand. – Tsyvarev Aug 26 '21 at 07:20

2 Answers2

1

it seems u need some basic cmake tutorial?

https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20a%20Library.html

target_include_directories

target_link_libraries

kenash0625
  • 657
  • 3
  • 8
1

in Top level CmakeLists.txt

include_directories(${PROJECT_SOURCE_DIR}/ThirdLib/Lib1/include)
include_directories(${PROJECT_SOURCE_DIR}/ThirdLib/Lib2/include)

target_link_directories(your_target_name ${PROJECT_SOURCE_DIR}/ThirdLib/Lib1/lib)
target_link_directories(your_target_name ${PROJECT_SOURCE_DIR}/ThirdLib/Lib2/lib)

And all .dll should be placed in the same folder as executable or env:PATH should refer to folder with .dlls

Deumaudit
  • 978
  • 7
  • 17
  • 1
    Note that command `target_link_directories` doesn't actually link with the libraries. This command only provides a directory for search the libraries. The linkage itself is provided by `target_link_libraries` command. – Tsyvarev Aug 26 '21 at 07:23