Home | History | Annotate | Download | only in cmake
      1 include(GNUInstallDirs)
      2 
      3 foreach(_library
      4   libprotobuf-lite
      5   libprotobuf
      6   libprotoc)
      7   set_property(TARGET ${_library}
      8     PROPERTY INTERFACE_INCLUDE_DIRECTORIES
      9     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
     10   install(TARGETS ${_library} EXPORT protobuf-targets
     11     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
     12     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
     13     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
     14 endforeach()
     15 
     16 install(TARGETS protoc EXPORT protobuf-targets
     17   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
     18 
     19 if(TRUE)
     20   file(STRINGS extract_includes.bat.in _extract_strings
     21     REGEX "^copy")
     22   foreach(_extract_string ${_extract_strings})
     23     string(REPLACE "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\" ""
     24       _extract_string ${_extract_string})
     25     string(REPLACE "\\" "/" _extract_string ${_extract_string})
     26     string(REGEX MATCH "^[^ ]+"
     27       _extract_from ${_extract_string})
     28     string(REGEX REPLACE "^${_extract_from} ([^$]+)" "\\1"
     29       _extract_to ${_extract_string})
     30     get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/${_extract_from}" ABSOLUTE)
     31     get_filename_component(_extract_name ${_extract_to} NAME)
     32     get_filename_component(_extract_to ${_extract_to} PATH)
     33     string(REPLACE "include/" "${CMAKE_INSTALL_INCLUDEDIR}/"
     34       _extract_to "${_extract_to}")
     35     if(EXISTS "${_extract_from}")
     36       install(FILES "${_extract_from}"
     37         DESTINATION "${_extract_to}"
     38         COMPONENT protobuf-headers
     39         RENAME "${_extract_name}")
     40     else()
     41       message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in "
     42         "\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" "
     43         "but there not exists. The file will not be installed.")
     44     endif()
     45   endforeach()
     46 endif()
     47 
     48 # Internal function for parsing auto tools scripts
     49 function(_protobuf_auto_list FILE_NAME VARIABLE)
     50   file(STRINGS ${FILE_NAME} _strings)
     51   set(_list)
     52   foreach(_string ${_strings})
     53     set(_found)
     54     string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}")
     55     if(_found)
     56       string(LENGTH "${_found}" _length)
     57       string(SUBSTRING "${_string}" ${_length} -1 _draft_list)
     58       foreach(_item ${_draft_list})
     59         string(STRIP "${_item}" _item)
     60         list(APPEND _list "${_item}")
     61       endforeach()
     62     endif()
     63   endforeach()
     64   set(${VARIABLE} ${_list} PARENT_SCOPE)
     65 endfunction()
     66 
     67 # Install well-known type proto files
     68 _protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
     69 foreach(_file ${nobase_dist_proto_DATA})
     70   get_filename_component(_file_from "../src/${_file}" ABSOLUTE)
     71   get_filename_component(_file_name ${_file} NAME)
     72   get_filename_component(_file_path ${_file} PATH)
     73   if(EXISTS "${_file_from}")
     74     install(FILES "${_file_from}"
     75       DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_file_path}"
     76       COMPONENT protobuf-protos
     77       RENAME "${_file_name}")
     78   else()
     79     message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in "
     80       "\"${protobuf_SOURCE_DIR}/../src/Makefile.am\" as nobase_dist_proto_DATA "
     81       "but there not exists. The file will not be installed.")
     82   endif()
     83 endforeach()
     84 
     85 # Export configuration
     86 
     87 install(EXPORT protobuf-targets
     88   DESTINATION "lib/cmake/protobuf"
     89   COMPONENT protobuf-export)
     90 
     91 configure_file(protobuf-config.cmake.in
     92   protobuf-config.cmake @ONLY)
     93 configure_file(protobuf-config-version.cmake.in
     94   protobuf-config-version.cmake @ONLY)
     95 configure_file(protobuf-module.cmake.in
     96   protobuf-module.cmake @ONLY)
     97 
     98 install(FILES
     99   "${protobuf_BINARY_DIR}/protobuf-config.cmake"
    100   "${protobuf_BINARY_DIR}/protobuf-config-version.cmake"
    101   "${protobuf_BINARY_DIR}/protobuf-module.cmake"
    102   DESTINATION "lib/cmake/protobuf"
    103   COMPONENT protobuf-export)
    104