Advertisement
justin_hanekom

cmake functions

Feb 1st, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 0.97 KB | None | 0 0
  1. # SPDX-License-Identifier: Unlicense
  2.  
  3. # include( CMakePrintHelpers REQUIRED )
  4.  
  5. # *INDENT-OFF*
  6.  
  7. # `abort_if_in_source` prints a fatal error message to stderr and exits the
  8. # make if attempting to build in the source directory.
  9. function( abort_if_in_source_build )
  10.   # Require out-of-source builds
  11.   file( TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH )
  12.   if( EXISTS "${LOC_PATH}" )
  13.     message( FATAL_ERROR
  14.       "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles." )
  15.   endif()
  16. endfunction()
  17.  
  18. # `print_all_variables` prints all the currently defined variables and their
  19. # values. The variables are printed in alphabetical order.
  20. function( print_all_variables )
  21.   get_cmake_property( _vars VARIABLES )
  22.   list( SORT _vars )
  23.  
  24.   foreach( _varName ${_vars} )
  25.     message( STATUS "${_varName}=${${_varName}}" )
  26.   endforeach()
  27. endfunction()
  28.  
Tags: cmake
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement