CMake – linking to library downloaded from ExternalProject_add()

Because you’re downloading the external project, you already know where everything is because you just downloaded it, so it doesn’t need ‘finding’. I got it working with add_library. This is my actual code that works: ExternalProject_Add(ForexConnectDownload PREFIX 3rd_party #–Download step————– URL http://fxcodebase.com/bin/forexconnect/1.3.1/ForexConnectAPI-1.3.1-Linux-x86_64.tar.gz URL_HASH SHA1=7fdb90a2d45085feb8b76167cae419ad4c211d6b #–Configure step————- CONFIGURE_COMMAND “” #–Build step—————– BUILD_COMMAND “” #–Install step————— UPDATE_COMMAND … Read more

Recursive list of LINK_LIBRARIES in CMake

Your wish has been out there for a while and is – as far as I know – not yet (as for CMake 3.3.2) embedded into CMake itself (see 0012435: Possibility to get all link libraries for a target?). I got some hope because this ticket lists a few possible alternative approaches. But after I … Read more

CMake : How to get the name of all subdirectories of a directory?

Use this macro: MACRO(SUBDIRLIST result curdir) FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) SET(dirlist “”) FOREACH(child ${children}) IF(IS_DIRECTORY ${curdir}/${child}) LIST(APPEND dirlist ${child}) ENDIF() ENDFOREACH() SET(${result} ${dirlist}) ENDMACRO() Example: SUBDIRLIST(SUBDIRS ${MY_CURRENT_DIR}) Use foreach: FOREACH(subdir ${SUBDIRS}) ADD_SUBDIRECTORY(${subdir}) ENDFOREACH()

Why add header files into ADD_LIBRARY/ADD_EXECUTABLE command in CMake

In our projects we use a “simple” way of yours – add_library with both headers and sources. If you add only sources, then you won’t see headers in IDE-generated project. However, when installing, we have to do it like that, using two install commands: install(TARGETS library_name LIBRARY DESTINATION lib) install(FILES ${PUBLIC_HEADERS} DESTINATION include/library_name) If you … Read more

Listing include_directories in CMake

You can use the get_property command to retrieve the value of the directory property INCLUDE_DIRECTORIES Something like this: get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) foreach(dir ${dirs}) message(STATUS “dir=”${dir}””) endforeach() The value of this directory property only tracks the include_directories commands that have occurred previously in the same CMakeLists file, or that have been inherited from previous … Read more