[CMake] breaking overly long lines without creating a list?

Marcel Loose loose at astron.nl
Thu Nov 19 03:46:29 EST 2009


Hi Daniel,

I've hit that wall too. For a pretty long list of compile definitions I
used the following macro to convert the list to a space-separated
string. IMHO this should be available as a built-in command, just like
separate_arguments().

# ----------------------------------------------------------------------
# join_arguments(var)
#
# Join the arguments in the (semi-colon separated) list VAR into one
# space separated string. The string will be returned in the variable
# VAR. This command is the opposite of the built-in command
# separate_arguments().
# ----------------------------------------------------------------------
macro(join_arguments var)
  set(_var)
  foreach(_v ${${var}})
    set(_var "${_var} ${_v}")
  endforeach(_v ${${var}})
  string(STRIP ${_var} _var)
  set(${var} ${_var})
endmacro(join_arguments)

HTH,
Marcel Loose.

On Wed, 2009-11-18 at 21:00 +0100, Daniel Franke wrote:
> Hi all,
> 
> I'd like to break overly long lines in CMakeLists.txt into something more 
> readable. But breaking a string into two as shown below generates a list, 
> which -- in this case -- breaks the compilation.
> 
> -- 8< --
> if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
>   set (CMAKE_Fortran_FLAGS     "-Wall -Wextra -Wno-unused-parameter "
>                                "-fimplicit-none")
> ...
> -- 8< --
> 
> Using '\' to continue the line doesn't work either. If 'cmake' takes it, 
> eventually 'make' will complain. 
> 
> This works, but sort of misses the point of increasing readability:
> -- 8< --
> if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
>   set (CMAKE_Fortran_FLAGS     "-Wall -Wextra")
>   set (CMAKE_Fortran_FLAGS     "${CMAKE_Fortran_FLAGS} -Wno-unused-parameter")
>   set (CMAKE_Fortran_FLAGS     "${CMAKE_Fortran_FLAGS} -fimplicit-none")
> ...
> -- 8< --
> 
> Any hints?
> 
> Thanks
> 
> 	Daniel
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list