smanders / externpro

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

fmtFiles erroneously include .patch files #258

Closed smanders closed 5 years ago

smanders commented 5 years ago

webpro can't use the externpro 19.11.1 release

the expected behavior of fmtFiles changed with this code change

@@ -1032,8 +1032,10 @@ macro(xpSourceListAppend)
      list(SORT topdir) # sort list in-place alphabetically
      foreach(item ${topdir})
        xpGlobFiles(repoFiles ${item} *)
-       xpGlobFiles(fmtFiles ${item} *.c *.h *.cpp *.hpp *.cu *.cuh *.proto)
      endforeach()
+      set(fmtFiles ${repoFiles})
+      list(FILTER fmtFiles INCLUDE REGEX "^.*\.(c|h|cpp|hpp|cu|cuh|proto)$")
+      list(FILTER fmtFiles EXCLUDE REGEX "^.*\.crtoolrc$") # CMake was erroneously matching .crtoolrc
      foreach(item ${XP_SOURCE_DIR_IGNORE})
        xpGlobFiles(ignoreFiles ${item} *)
      endforeach()

https://github.com/smanders/externpro/commit/4cd20930b6274f922ef2eac7da1bd94830bd0ebd#diff-074a673c226cfda4a96b57733c01943e

somehow the *.patch files from the patches/ directory of internpro and webpro are included in fmtFiles

and webpro, which calls proAddProjectDir() twice from the toplevel CMakeLists.txt (once for packages and again for projects), which then calls xpSourceListAppend() and drops into the "top-level" conditional twice, tries to create two format custom targets, which is a cmake error!

      if(NOT MSVC AND fmtFiles AND NOT ${CMAKE_PROJECT_NAME} STREQUAL externpro)
        # make paths relative to CMAKE_SOURCE_DIR
        xpListRemoveFromAll(fmtFiles ${CMAKE_SOURCE_DIR} . ${fmtFiles})
        list(LENGTH fmtFiles lenFmtFiles)
        xpGetPkgVar(clangformat EXE)
        add_custom_command(OUTPUT format_cmake
          COMMAND ${CLANGFORMAT_EXE} -style=file -i ${fmtFiles}
          WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
          COMMENT "Running clang-format on ${lenFmtFiles} files..."
          )
        string(REPLACE ";" "\n" fmtFiles "${fmtFiles}")
        file(WRITE ${CMAKE_BINARY_DIR}/formatfiles.txt ${fmtFiles}\n)
        add_custom_target(format SOURCES ${CMAKE_BINARY_DIR}/formatfiles.txt DEPENDS format_cmake)
        list(APPEND masterSrcList ${CMAKE_BINARY_DIR}/formatfiles.txt)
        set_property(TARGET format PROPERTY FOLDER CMakeTargets)

https://github.com/smanders/externpro/blob/19.11.1/modules/xpfunmac.cmake#L1112-L1121

smanders commented 5 years ago

the last commit message is a little off... one of the bullets

isn't completely correct... there is a format custom target created now for externpro (if there are any fmtFiles), it's just not a "working" custom target because it doesn't know what format_cmake is (because it can't determine CLANGFORMAT_EXE since externpro is the thing that creates the clang-format executable)

smanders commented 5 years ago

completed with commits to dev branch referenced above