cmake_minimum_required (VERSION 3.0.0) project(MyProject CXX) set(EXTENSION .c) # Fails # set(EXTENSION .cpp) # Fails # set(EXTENSION .txt) # Works set( TEST_A test ) set( TEST_B ${TEST_A}${EXTENSION} ) get_source_file_property(excluded ${TEST_B} HEADER_FILE_ONLY) message("Exclusion of ${TEST_B} is: ${excluded}") get_source_file_property(excluded ${TEST_A} HEADER_FILE_ONLY) message("Exclusion of ${TEST_A} is: ${excluded}") set_source_files_properties(${TEST_A} PROPERTIES HEADER_FILE_ONLY FALSE ) set_source_files_properties(${TEST_B} PROPERTIES HEADER_FILE_ONLY TRUE ) get_source_file_property(excluded ${TEST_B} HEADER_FILE_ONLY) message("Exclusion of ${TEST_B} is: ${excluded}") get_source_file_property(excluded ${TEST_A} HEADER_FILE_ONLY) message("Exclusion of ${TEST_A} is: ${excluded}") if( NOT "${excluded}" STREQUAL "FALSE" ) message(FATAL_ERROR "\${excluded} is ${excluded} but FALSE was expected.") endif()