The biggest advantage to setting up proper IMPORTED targets, when building on Windows, is that you can then use features like the $ generator expression to copy all of the necessary DLLs into the install directory when installing your binary. Any file named FindSomething.cmake on the CMAKE_MODULE_PATH is interpreted as a Find module for the dependency “Something”, and can be invoked from your CMakeLists.txt using a find_package(Something) call. That link has some information, but one of the best resources is reading the set of Find modules that come with CMake, they should be in a Modules directory somewhere in your CMake install dir. Target_link_libraries(myexe PRIVATE mylib)īut like I said, for portability you should really wrap that logic in a Find module that you can bundle with your project. # you can link the DLL into your project's executable with: # Then, assuming you've created an executable build target: Target_compile_definitions(mylib INTERFACE Target_include_directories(mylib INTERFACE IMPORTED_LOCATION "full_path_to_dll_file") You’re better off placing the DLLs you need in the same directory as the executable, Windows will always load them from there.)Īs far as your CMake target goes, though, the brute-force hardcoded version would look something like this: add_library(mylib SHARED IMPORTED) (You really shouldn’t ever install ANYTHING into C:\Windows\System32\, that’s major hackery and a recipe for trouble. Specifically, you’d want a SHARED IMPORTED target, which should have both the. (That hardcoded disk path isn’t going to work out so well if the build system is generated on a different machine.)īut even if you don’t use a Find module, you should still set your dependency DLL up as its own IMPORTED target. You might do this by way of a Find module for compatibility, especially if you plan to make your project available for others to build. If the DLL is from somewhere completely external to your project (meaning, it’s supplied precompiled and you aren’t building it), you’ll probably want to define an IMPORTED TARGET for it. What you should do depends a bit on the nature of the dependency. Yeah, you probably don’t want to do that.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |