![]() ![]() Then you can specify what to copy where.Īs you don't want to install this module, the best way is to create a package by providing a CMake config file for your project. So you wish is not very CMake-ish.ĬMake would put headers and libraries according to your wishes when you install the project. If you really want to copy files via CMake, the following would work: file(COPY srcDirĪs a general rule for CMake, sources are kept in the source directory and binaries and other generated files are within the build directory. Therefore you don't need to copy your headers! CMake >= 2.8.12 is beautiful, isn't it? Source # the headerfiles in source are the includesīy using the project name foo in target_link_libraries(.) you refer to the foo library targetįurthermore, by using the PUBLIC keyword in the foo library, your headers (your include directory) is automatically propagated to every CMake project that adds this library via add_subdirectory(.). # directories where to search for header files Your CMakeLists will look like the followingĮxample/CMakeLists.txt # use modern target-based cmake featuresĮxample/sub/foo/CMakeLists.txt # use modern target-based cmake features ![]() What you are looking for is the following structure: example/ It seems like cmake would have a clean solution for this. h file, which makes me feel like I'm missing something. However, I still have to point at the original include directory to get the. This allows me to refer to the library using 'foo_build', which is nice and clean. Which causes the foo build to happen in a subdirectory. I've seen other projects use something like this: add_subdirectory(/foo foo_build) It might help to clarify how I think I want to pull this project into another. Open to an answer that says "here's a better way", too. I believe I can jury rig this, but methinks there's a best practice out there. I've tried calling it a "FRAMEWORK", no luck that only makes is a macOs framework. Ideally, the foo.h would show up next to libfoo.a in the build directory. The idea here is that the library would be used by other CMake projects, not by the entire system. Set_target_properties(foo PROPERTIES PUBLIC_HEADER foo.h) # sad attempt to get it to output the header # tell cmake where to find headers for it Here's my current CMakeLists.txt: cmake_minimum_required(VERSION 3.8.2) The problem I run into is CMake doesn't seem to put foo.h anywhere, so getting the parent CMake to know how to find the header file is beguiling me. I want to create a CMakeLists.txt to build this as a library for use in other CMake projects that include it as a sub directory. To see all -E options, run cmake -E help.I have a directory with c++ source and header files. This provides a cross-platform way to achieve the copy, since cp isn't a Windows command. ![]() Here's how I'd set up the command: SET(COPY_TO_PATH custom1)ĪDD_CUSTOM_COMMAND(TARGET test POST_BUILDĬOMMENT "Copying 'test' library to '$) with its -E command line option. It also needlessly adds to your list of targets - maybe not an issue for a tiny project, but it can be for larger projects. Using add_custom_target requires you to remember to build this if the original target ( test in this case) is updated. ), this guarantees the command is executed every time the target is rebuilt. In your case, no target depends on your file - it's a product of the build process. The custom command is invoked when this target is built (right at the start), since the target needs the file to exist at that point. The OUTPUT version is designed to have the output file used as a source file in a different CMake target in the same CMakeLists.txt. ) form rather than add_custom_command(OUTPUT. However, I'd recommend you use the add_custom_command(TARGET. I'd stick with your original idea of using add_custom_command. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |