CPMLicenses.cmake icon indicating copy to clipboard operation
CPMLicenses.cmake copied to clipboard

Allow the target to be run automatically

Open flagarde opened this issue 3 years ago • 1 comments

It would be nice to add an option to add the ALL keyword on the target options to allow it to be run automatically and maybe add an install path relative '${CMAKE_INSTALL_DOCDIR}'.

Something like this pseudo-code?

function(cpm_licenses_create_disclaimer_target TARGET_NAME FILE_NAME PACKAGES)
  cmake_parse_arguments(ARGS "ALL" "PATH" "" ${ARGN})
  set(PACKAGE_SOURCES "")
  foreach(package ${PACKAGES})
    cpm_get_fetch_properties(${package})
    list(APPEND PACKAGE_SOURCES "-D${package}_SOURCE_DIR=\"${${package}_SOURCE_DIR}\"")
  endforeach()

  if(ARGS_ALL)
  add_custom_target(
    ${TARGET_NAME} ALL
    COMMAND
      ${CMAKE_COMMAND} -DPRINT_license_FILE_NAME=${FILE_NAME}
      "-DPRINT_license_PACKAGES=\"${PACKAGES}\"" ${PACKAGE_SOURCES} -P ${CPMlicenses_SCRIPT_PATH}
  )
else()
  add_custom_target(
    ${TARGET_NAME} ALL
    COMMAND
      ${CMAKE_COMMAND} -DPRINT_license_FILE_NAME=${FILE_NAME}
      "-DPRINT_license_PACKAGES=\"${PACKAGES}\"" ${PACKAGE_SOURCES} -P ${CPMlicenses_SCRIPT_PATH}
  )
endif()
INSTALL(FILES ${FILE_NAME} DESTINATION "${CMAKE_INSTALL_DOCDIR}/${ARGS_PATH}")
endfunction()

flagarde avatar Jan 13 '22 16:01 flagarde

Hey thanks for the issue, I agree that would be a useful addition! I think in the second branch we should omit the ALL, but feel free to open a PR for a thorough review!

TheLartians avatar May 14 '22 16:05 TheLartians