IMPORTED_LOCATION IMPORTED_LOCATION Full path to the main file on disk for an IMPORTED target. Usage in an existing CMake project Having defined all of the above CMake is able to find the required parts of a library except where to find the find.cmake file itself. For STATIC libraries and modules this is the location of the library or module. # Example-FindMyPackage-UsingImportedTargets.cmake # # This module does the same thing as Example-FindMyPackage.cmake # except that rather than passing along full path names for libraries, # it creates imported targets. will simply create the file "liblibcool.a" in a Linux environment. When declaring dependency to in , I wrap it into third::third. If you don't specify commands like BUILD_COMMAND or INSTALL_COMMAND, CMake will look for a CMakeLists.txt in the external project and execute it. : export (EXPORT foobarLibTargets FILE "$ {CMAKE_CURRENT_BINARY_DIR}/foobarLibTargets.cmake") creates a Targets.cmake referencing the build tree. Now we will change the library project to be exported to a package. The export and install commands are both capable of generating cmake files for targets. However, because the library is already built, you need to use the IMPORTED flag to tell CMake that you only want to import the library into your project: add_library ( imported-lib SHARED IMPORTED ) You then need to specify the path to the library using the set_target_properties () command as shown below. I was so excited, I thought I had a working solution using the generator expression for IMPORTED_LOCATIONbased on my Windows Visual Studio test, but then it failed on my Linux tests. For STATIC libraries and modules this is the location of the library or module. IMPORTED_LOCATION $ {LIBIMAGEPIPELINE_LIBRARY} is the location of the library file provided by find_library. CMakeLists.txt for Go is based on the post in Stackoverflow 1 . Secondly, according to Craig Scott's CMake book, omitting the type argument in add_library (.) I declared the libraries IMPORTED because the libraries' own build system consists of a complex mix of Python, CMake and macros which I found difficult to integrate into . So it goes without saying that CMake takes care of the naming conventions and extensions for each platform. > > I thought I could simply declare this target as > > add_library(Foo::Foo UNKNOWN IMPORTED) > > and then configure its dependencies via the target property > IMPORTED_LOCATION. For example: JRR(John Rocha) These group together properties. Hello, My CMake project uses some third party libraries which I declared as IMPORTED then I set the IMPORTED_IMPLIB or IMPORTED_LOCATION properties (depending on compiler and type of library) to the full path and file name. Set this to the location of an IMPORTED target file on disk. This will install the import script JSONUtilsTargets.cmake that, when included in other scripts, will load the targets defined in the export jsonutils-export. on CMake 3.5.1 (that I must support as it is the default version on Ubuntu 16.04), when configuring , I have the following error: Target . Features The main advantage of this example is that it is auto-generated . The .lib name depends on bitness and build type, as does the dll, but the IMPORTED_IMPLIB and IMPORTED_LOCATION properties don't appear to take generator expressions. With IMPORTED_LOCATION and INTERFACE_INCLUDE_DIRECTORIES, CMake can detect where the library (.a or .so) and headers (.h) are. Link the consumer to the dependency. You can set this property, and like many properties in CMake, it gets it's default value from a CMAKE_CXX_STANDARD variable if it is set, but there is no INTERFACE version - you cannot force a CXX_STANDARD via a target. For executables this is the location of the executable file. It compiles projects with compilers like GCC, Clang, Intel, MS Visual C++. Yes, this was found in Visual Studio. While IMPORTED_LOCATION is empty. The current CMake integration seems to just create variables to the directories (include, lib, bin, ) for each dependency. Our Solution: In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share, you need the following. Add the following lines to the CMakeLists.txt file that defines the library: 1 2 3 4 set(INSTALL_CMAKE_DIR c: / Packages / DemoLibraryClient) The export command e.g. If need be, I can > specify a use case for this. Click to expand output results of configuring projects Import your targets inside your Config.cmake A header-only library is imported with add_library (INTERFACE). Importing Executables To start, we will walk through a simple example that creates an IMPORTED executable target and then references it from the add_custom_command () command. For example, add_library (libcool STATIC .) In our case we want to make use of the luajit library which is built using a Makefile. By using the NAMESPACE argument, we tell CMake to prepend the prefix JSONUtils:: to all targets imported. Set this to the location of an IMPORTED target file on disk. Update: now using modern cmake (version >= 3.9), since commit 46f0b93. Follow this tutorial to create a basic CMake library for Raspberry Pi and import it manually via add_subdirectory (). For bundles on macOS this is the location of the executable file inside Contents/MacOS under the application bundle folder. For quite some time CMake has supported what they call imported targets. The following is the example CMakeLists.txt code using OpenCV. CMake utilizes build-systems such as Ninja, Linux make, Visual Studio, and Xcode. For example, IMPORTED_LOCATION contains the full path to the target on disk. Use ExternalProject_Add to obtain, configure, and build the library. I will see about creating a simple example to prove and file an issue as suggested. add_library supports the import of already built libraries as well - we just have to set its IMPORTED_LOCATION . # application depends privately on a home-made (static)library which depends privately on a third-party library . The end result is roughly the same to # the end-user. We'll need to do some setup to get started. on CMake 3.19.2 it works fine. Autogenetared library version file: #include <foo/version.h> FOO_DEBUG added on Debug. I would have expected conan to declare proper imported targets for each dependency. Use add_library (IMPORTED) to declare an imported target. IMPORTED) CMakeCMake IMPORTED_LOCATION IMPORTED_LOCATION_<CONFIG> IMPORTED_LOCATION set_target_properties(foo PROPERTIES IMPORTED_LOCATION /path/to/real/library/libfoo.so) Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time. Only after instrumenting the source of cmake itself was I finally able to track this down. After configuring the projects, as we can see, ONLY IMPORTED_LOCATION_<CONFIG> of IMPORTED targets are populated. CMake is frequently used in compiling open-source and commercial projects. is good practice. You only need to change the project name, and add the files that need to be compiled in foo/CMakeLists.txt. For executables this is the location of the executable file. However you can simplify your command using the following syntax: if (CMAKE_BUILD_TYPE) get_target_property (PY_LIB_ADDRESS python IMPORTED_LOCATION_$ {CMAKE_BUILD_TYPE}) else () get_target_property (PY_LIB_ADDRESS python IMPORTED_LOCATION) endif () And to finish, as far as I know, get_filename_component () does not support generator expressions. The key part is add_library (IMPORTED) 2, to tell the library is not generated by CMake system and use the library located outside the project. INTERFACE libraries Using header-only libraries in CMake is a breeze. In the Cmake documentation this seems pretty straightforward; to import the .o file: add_library (bar OBJECT IMPORTED GLOBAL) set_property (TARGET bar PROPERTY IMPORTED_LOCATION $ {EXTERNAL_DIR}/bar.o) And to use it: add_executable (foo $<TARGET_OBJECTS:bar> foo.cpp) But when the build runs, I get all missing symbols for the stuff that's . # include path that has headers required by target project include_directories ($ {install_dir}/include) # import librarues from external project required by target project add_library (lmytls shared imported) set_target_properties (lmytls properties imported_location $ {install_dir}/lib/libmytls.so) add_library (lmyxdot509 shared imported) CMake is a cross-platform software for building projects written in C, C++, Fortran, CUDA and so on. CMake 3.21: I'm trying to wrap fmod with a SHARED IMPORTED target and support Windows builds. The IMPORTED_LOCATION target property (or its per-configuration variant IMPORTED_LOCATION_<CONFIG>) specifies the location of the main library file on disk: For a SHARED library on most non-Windows platforms, the main library file is the .so or .dylib file used by both linkers and dynamic loaders. Example 2: C++ standard There is a C++ standard property - CXX_STANDARD. > > This used to work in 3.0.2, since it allowed me to specify multiple > libraries separated by a semicolon (see . Please see that other file for the full documentation # of the example.