How to load all . lib in a directory through Cmake?

Asked

Viewed 40 times

0

I have in my CMakeLists.txt several calls to the add_library where these call libraries(.lib) are located in the same directory. I would like to import all libs from that directory /lib without having to use the add_library and set_target_properties for each of them.

Cmakelists:

add_library(avcodec STATIC IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/lib/avcodec.lib")

add_library(avformat STATIC IMPORTED)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/lib/avformat.lib")

add_library(avutil STATIC IMPORTED)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/lib/avutil.lib")

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/include")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static -lstdc++ -lwinpthread -D__STDC_CONSTANT_MACROS") 

add_executable(appffmpeg)
target_link_libraries(appffmpeg curl avcodec avformat avutil)

Is there any more efficient way to do that?

As I would if I wanted to import all libs and leave some out, example, do not matter postproc.lib and avfilter.lib, would have to name all manually on import?

1 answer

1


I think the way you put it in the question is the way "right".

But I also think you can do it the way you want:

...
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/lib")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/include")
...
add_executable(appffmpeg)
target_link_libraries(appffmpeg curl avcodec avformat avutil)

Ref.
link_directories
target_link_libraries

Obs. not tested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.