cmake-basis / BASIS

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!
https://cmake-basis.github.io
Other
48 stars 10 forks source link

Installing externally supplied headers in nonstandard directories via basis #621

Closed ahundt closed 4 years ago

ahundt commented 7 years ago

moved from https://github.com/cmake-basis/BASIS/issues/339

It seems a problem has come up again with my software installation, some header files are missing from the install and their location is also not on the include path: ahundt/grl#128

It is due to my script that unzips and builds a user supplied zip file with source provided by another company (I can't change the contents): https://github.com/ahundt/grl/blob/master/config/FRI_Client_SDK_Cpp.cmake

I need to install the unzipped headers into an appropriate location so users can include it in their own code.

I think I need to add an $<INSTALL_INTERFACE:include/mylib> parameter to the target_include_directories() call, but I think I'll also need an installation call for the individual headers.

I can write custom cmake code that does this, but some of the basis automation may be lost for those files. Do you have recommendations on what I can do?

ahundt commented 7 years ago

If I should just write custom install code for this component that's okay, was just hoping to clarify if I might be able to use an appropriate basis function to make sure install/uninstall other basis features still work smoothly with minimal custom steps.

ahundt commented 7 years ago

To clarify, I can change the contents of the cmake script that unzips builds and installs the code. I cannot change the zip itself.

schuhschuh commented 7 years ago

I guess what it comes down to is how the BASIS functions are supposed to work, which ones you use, and what you expect of them otherwise...

basis_add_library: only handles source files that you provide as arguments. For these files of the library target it will add installation rules, but not for any other file that is included by these source files.

basis_install_directory: installs an entire subtree (I believe it's recursive), for each file within the directory, I think a corresponding removal command should be added to the uninstall script. See <Project>Uninstall.cmake file in <prefix>/lib/cmake/<project>/ of the installation.

basis_include_directories: works just as CMake's include_directories, hence, has nothing to do with installation.

target_include_directories: not a BASIS command, but also does not automatically add any installation rules.

I not quite sure what you would expect from BASIS to do in this case? Can you provide a minimalistic example of functionality you think should be there?

Otherwise, it looks to me as if you need to add manual installation steps (e.g., using basis_install_directory or basis_install) plus target_include_directories to have CMake add the respective paths to the include path of the exported targets.

schuhschuh commented 7 years ago

Maybe you could extract this external zip in a modules subdirectory and then copy a BasisProject.cmake and possibly CMakeLists.txt file into this subdirectory, where the BasisProject.cmake file sets INCLUDE_DIR, CODE_DIR, and the like according to the external projects structure using basis_project ?

schuhschuh commented 7 years ago

I.e., kind of patch the unzipped subproject to turn it into a BASIS module (subproject) which your top-level project (or other modules) then depend on. You'd add a CMakeLists.txt for the build of the libraries of this external module to the extracted files with the respective basis_add_library commands between basis_project_begin() and basis_project_end() (see impl of basis_project_impl for reference).

ahundt commented 7 years ago

Interesting idea, is the top level Settings.cmake run early enough that if I generated a new modules repository in that way it would be picked up? Or should it be checked somewhere else?

probably not if it has to be between or before the basis_project_begin() call.

I'll try something out in a bit! Thanks for your suggestions. :-)

schuhschuh commented 7 years ago

I think this should be part of a pre-configuration step. It seems to be part of a source code download rather than build configuration.

schuhschuh commented 7 years ago

Respectively, you can perform the download and patching before basis_project_begin in your top-levels CMakeLists.txt. Still, that's more like Hunter works and I'm not a big fan of download during the CMake project build configuration stage...