floooh / fips

High-level build system for distributed, multi-platform C/C++ projects.
MIT License
471 stars 82 forks source link

bugfix: files without extension will crash fips_files() #261

Closed mattiasljungstrom closed 4 years ago

mattiasljungstrom commented 4 years ago

Adding a file with fips_files(filname) will break on line 237 in fips_private.cmake if filename has no extension. This PR adds a check to see if the variable exists before comparing it.

You probably only expected source files to be added here. I'm using the code below to add my data resource files to a macOS app bundle. Your could perhaps use this code inside fips as well, but I wasn't sure exactly where to add this feature.

CMakeList.txt somewhere:

if (FIPS_MACOS)
    file(GLOB_RECURSE resources_data
            "${CMAKE_CURRENT_SOURCE_DIR}/data/*"
            )
endif()

Later inside fips_begin_app()

    if (FIPS_MACOS)
        fips_dir(.)
        foreach(res_file ${resources_data})
            # add to project
            fips_files(${res_file})
            # get the relative path and set location in app package (under Resources)
            file(RELATIVE_PATH res_rel_path "${CMAKE_CURRENT_SOURCE_DIR}" ${res_file})
            get_filename_component(res_path ${res_rel_path} DIRECTORY)
            set_property(SOURCE ${res_file} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${res_path}")
        endforeach(res_file)
    endif()
floooh commented 4 years ago

Makes sense, thanks. I actually sometimes also add non-source files (e.g. images), but those also have file extensions and didn't trigger the problem :)