smanders / externpro

build external projects with cmake
MIT License
13 stars 12 forks source link

xpfunmac.cmake improvements #376

Closed smanders closed 1 year ago

smanders commented 1 year ago

xpSourceListAppend() currently adds several files to the cmake list automatically https://github.com/smanders/externpro/blob/23.02/modules/xpfunmac.cmake#L1045-L1076

  file(GLOB miscFiles LIST_DIRECTORIES false
    ${_dir}/.git*
    ${_dir}/*clang-format
    ${_dir}/.crtoolrc
    ${_dir}/docker-compose.*
    ${_dir}/README.md
    ${_dir}/version.cmake
    )
  if(miscFiles)
    list(APPEND masterSrcList ${miscFiles})
    file(RELATIVE_PATH relPath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
    string(REPLACE "/" "" custTgt .CMake${relPath})
    if(NOT TARGET ${custTgt})
      if(EXISTS ${_dir}/.codereview)
        file(GLOB crFiles "${_dir}/.codereview/*")
        source_group(".codereview" FILES ${crFiles})
        list(APPEND masterSrcList ${crFiles})
      endif()
      if(EXISTS ${_dir}/.devcontainer)
        file(GLOB_RECURSE dcFiles "${_dir}/.devcontainer" "${_dir}/.devcontainer/*")
        source_group(".devcontainer" FILES ${dcFiles})
        list(APPEND masterSrcList ${dcFiles})
      endif()
      if(EXISTS ${_dir}/.github)
        file(GLOB_RECURSE githubFiles "${_dir}/.github/*")
        source_group(".github" FILES ${githubFiles})
        list(APPEND masterSrcList ${githubFiles})
      endif()
      add_custom_target(${custTgt} SOURCES ${miscFiles} ${crFiles} ${dcFiles} ${githubFiles})
      set_property(TARGET ${custTgt} PROPERTY FOLDER ${folder})
    endif()
  endif()

the latest addition was adding the entire .github/ directory with this issue https://github.com/smanders/externpro/issues/369

we have many projects and repos that are adding these four web-related files with cmake like the following

set(root_srcs
   .eslintrc.json
   .prettierrc
   package.json
   tsconfig.json
   )
 source_group("" FILES ${root_srcs})
 list(APPEND ${PROJECT_NAME}_srcs ${root_srcs})
 #######################################
 wpAddYarnTarget(${PROJECT_NAME}Deps)
 xpSourceListAppend("${${PROJECT_NAME}_srcs}")

it would be nice if these files were automatically taken care of by xpSourceListAppend() when they exist so these files are also properly added to a custom target and they are therefore searchable in Visual Studio and part of the VS solution and to simplify the cmake of these projects

smanders commented 1 year ago

completed with commit to dev branch referenced above

grahamaj commented 1 year ago

@smanders for your consideration: There are a couple of variants to tsconfig.json that we use to disambiguate a couple of tsconfig:

A couple of other setup files we use in many of our projects:

smanders commented 1 year ago

as discussed in-person with @grahamaj : we'll keep this automatic list taken care of by xpSourceListAppend() to just files that are in the root of the repo... but thanks for identifying these other files! we may want to consider having cmake do something with them in the future as we consider automatically looking for files in subdirectories of the repo