[CMake] Effective CMake - warning on bad practices

cen imbacen at gmail.com
Fri Nov 23 07:07:01 EST 2018


I finished watching "Effective CMake" talk by Daniel Pfeifer from last 
year and it seems to me it is the "GO TO" resource for best practices. A 
quick scan of my CMakeLists.txt files and sure enough, I use 
include_directories() and other "dont's". The problem is that none of 
the things mentioned in the talk:

a) give any warnings when running cmake

b) are mentioned as bad practice in the docs


What I would prefer is that everytime a bad practice is used a big red 
warning would be printed by CMake so I could see it and correct it.

Since CMake is apparently very slow deprecating things a solution 
appeared in my mind after seeing the function wrap functionality. How 
about a file called Effective.cmake which contains something like 
(pseudocode):

function(include_directories input output)

     message(DEPRECATION "Use target_include_directories() instead."

     _include_directories(...)

endfunction()

function(set input output)

     if (${ARG0} STREQUAL "CMAKE_CXX_FLAGS")

         message(DEPRECATION "You probably shouldn't use this directly")

     endif

     _set(...)

endfunction()

...


then include(Effective.cmake) in your CMakeLists.txt to enable all 
warnings. The effort here is to compile a list of existing bad practices 
and wrap them (if such a thing is possible).


Does this approach seem reasonable? Is there an effort with similar 
goals out in the wild which I should know about?



Best regards,

cen






More information about the CMake mailing list