Making cmake library accessible by other cmake packages automatically -


i have 1 project produces library:

project (mycoollibrary) add_library(my_cool_library shared ${mysources_src}) 

and project should using library:

find_package (mycoollibrary required) include_directories("${mycoollibrary_include_dirs}" ) add_executable(mycoolexe ${my_sources_src} ) target_link_libraries(mycoolexe ${mycoollibrary_libraries} ) 

is there way can change first file second file works automatically? running cmake on first file , running make on output, running cmake on second file, cmake able find package?

an answer give address of first project built second package acceptable.

turning comment answer

taking code found in blog post @daniperez - use cmake-enabled libraries in cmake project (iii) - i've come following minimal solution:

mycoollibrary/cmakelists.txt

cmake_minimum_required(version 3.3)  project(mycoollibrary)  function(my_export_target _target _include_dir)     file(         write "${cmake_current_binary_dir}/${_target}config.cmake"         "             include(\"\$\{cmake_current_list_dir\}/${_target}targets.cmake\")             set_property(                 target ${_target}                  append property                      interface_include_directories \"${_include_dir}\"             )         "     )      export(targets ${_target} file "${cmake_current_binary_dir}/${_target}targets.cmake")      # note: following call can pollute pc's cmake package registry     #       see comments/alternatives below      export(package ${_target})  endfunction(my_export_target)  ...  add_library(${project_name} shared ${mysources_src}) my_export_target(${project_name} "${cmake_current_source_dir}") 

mycoolexe/cmakelists.txt

cmake_minimum_required(version 3.3)  project(mycoolexe)  find_package(mycoollibrary required)  ...  add_executable(${project_name} ${my_sources_src}) target_link_libraries(${project_name} mycoollibrary) 

to make reusable have packed my_export_target(). , i'm friend of self-propagating properties interface_include_directories.

edit: commented @ruslo using export(package ...) can pollute package registry. alternatively can:

  1. write target config files directly dedicated place specific toolchain

    see e.g. how install custom cmake-find module , 0003659: find_package command improvements

  2. set cmake_module_path via second project's cmake command line (injecting search path(s) outside). if building 2 projects anyway build script, direct way propagate module search path(s).

additional references


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -