No documentation that cmake_policy() does not affect add_subdirectory() projects
I needed to set two policies and some variable before importing SuperLU. However cmake_policy() had no effects in either attempt:
block()
cmake_policy(SET CMP0048 NEW) # silence SuperLU version variable warnings
cmake_policy(SET CMP0077 NEW) # override SuperLU option()s
set(BUILD_SHARED_LIBS FALSE)
set(enable_blaslib TRUE) # < 5.2.2
set(enable_internal_blaslib TRUE) # newer
add_subdirectory("opt/superlu" EXCLUDE_FROM_ALL)
endblock()
# gave up and tried setting globally
cmake_policy(SET CMP0048 NEW) # silence SuperLU version variable warnings
cmake_policy(SET CMP0077 NEW) # override SuperLU option()s
set(BUILD_SHARED_LIBS FALSE)
set(enable_blaslib TRUE) # < 5.2.2
set(enable_internal_blaslib TRUE) # newer
add_subdirectory("opt/superlu" EXCLUDE_FROM_ALL)
Eventually I tried setting CMAKE_POLICY_DEFAULT_CMP<NNNN>
, which worked:
block(SCOPE_FOR VARIABLES)
cmake_policy(SET CMP0048 NEW) # silence SuperLU version variable warnings
cmake_policy(SET CMP0077 NEW) # override SuperLU option()s
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) # silence SuperLU version variable warnings
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # override SuperLU option()s
set(BUILD_SHARED_LIBS FALSE)
set(enable_blaslib TRUE) # < 5.2.2
set(enable_internal_blaslib TRUE) # newer
add_subdirectory("opt/superlu" EXCLUDE_FROM_ALL)
endblock()
Is this intentional? cmake_policy()
's documentation does not explicitly mention that it does not affect subprojects like this, nor does it link to CMAKE_POLICY_DEFAULT_CMP<NNNN>
.