Understanding CMake Policy CMP0062 and its Alternatives


  • Custom Module
    "CMP0062" could be an identifier from a custom CMake module that you or someone else added to your project. These modules can define custom policies and variables. You can check your project's CMakeLists.txt files to see if there are any custom modules included.


# Define a custom policy
cmake_policy( CMP0063 REQUIRE )

# Check the policy
if( NOT CMAKE_POLICY_CMP0063 )
  message(FATAL_ERROR "Policy CMP0063 is not enabled")
endif()

# Code that requires CMP0063 to be enabled
add_executable(my_program main.cpp)

This example defines a custom policy named CMP0063 and requires it to be enabled. The code then checks if the policy is enabled using CMAKE_POLICY_CMP0063. If the policy is not enabled, a fatal error message is displayed. Finally, some code that requires CMP0063 is added.



  1. Standard Policy for Installing export() Results
    If "CMP0062" relates to installing the output of the export() command, the standard CMake policy for this behavior is CMP0062.

    • Alternative
      Use install(EXPORT) instead of install(FILES) with the output of export(). install(EXPORT) generates files with relative paths suitable for installation.
  2. Custom Policy
    If "CMP0062" is from a custom module, the alternative depends on the module's functionality.

    • Alternative
      Look for documentation specific to the custom module to understand its purpose and potential alternatives. Consider contacting the module's author for clarification.
  3. Internal CMake Policy
    There likely isn't a user-accessible alternative for internal CMake policies.

Here are some general best practices when encountering unknown CMake policies

  • Consider Upgrading CMake
    If you're using an older version of CMake, consider upgrading. Newer versions might have replaced "CMP0062" with a standard policy.
  • Search CMake Documentation
    Look through the official CMake documentation for policies with similar names or functionalities.
  • Check Project Context
    Review your project's CMakeLists.txt files to see if there are any custom modules that might define "CMP0062".