cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
958 stars 105 forks source link

Formatting Breaks `add_library` Call #111

Closed sanssecours closed 5 years ago

sanssecours commented 5 years ago

Steps to Reproduce

  1. Create a file test.cmake with the following content:

    add_library (cframework OBJECT ${SOURCES})
  2. Run cmake-format:

    cmake-format test.cmake

Expected Result

The command cmake-format prints a nicely formatted version of the given CMake code.

Actual Result

cmake format breaks the add_library function call, since it moves the keyword OBJECT:

add_library(cframework ${SOURCES} OBJECT)

.

System Information

cheshirekow commented 5 years ago

You can disable the autosort config as a work-around.

cheshirekow commented 5 years ago

Ok, I added parsers for the non-"normal" add_library() forms. They are in the branch stage_v0.5.2 (here) if you'd like to try. I definitely should have done that before defaulting to autosort=on. I forgot that there were additional forms of this command. I'll need to add additional forms for add_executable() too.

cheshirekow commented 5 years ago

Also, as a note to myself: autosort will also break if the command form descriminator is hidden behind a cmake variable. For example:

set(libtype OBJECT)
add_library(foobar ${libtype} bar.cc baz.cc foo.cc)
gocarlos commented 5 years ago

same happens for ALIAS:

# correct
add_library(my_proj::my_comp
            ALIAS 
            ${PROJECT_NAME}_my_comp
            )
# not correct
add_library(my_proj::my_comp
            ${PROJECT_NAME}_my_comp
            ALIAS)
cheshirekow commented 5 years ago

@gocarlos I believe this case is already covered in stage_v0.5.2 (here) but if you are seeing this on that branch please let me know:

cheshirekow commented 5 years ago

Closed in v0.5.2