compile_features: Ignore features that map to languages that aren't enabled

Remove the Cuda/ConsumeCompileFeatures test as it only existed to
validate that using `cxx_std_XY` would cause the paired language (CUDA) to also build in mode XY.
This commit is contained in:
Robert Maynard 2021-06-21 13:16:29 -04:00
parent 66488d4eb3
commit a3cafa4237
8 changed files with 11 additions and 60 deletions

View File

@ -0,0 +1,5 @@
target_compile_features-ignore-disabled-langs
---------------------------------------------
* :command:`target_compile_features` learned to ignored features for languages that
aren't enabled.

View File

@ -387,6 +387,10 @@ bool cmStandardLevelResolver::CheckCompileFeaturesAvailable(
return false;
}
if (!this->Makefile->GetGlobalGenerator()->GetLanguageEnabled(lang)) {
return true;
}
const char* features = this->CompileFeaturesAvailable(lang, error);
if (!features) {
return false;

View File

@ -4,7 +4,6 @@ macro (add_cuda_test_macro name)
PROPERTY LABELS "CUDA")
endmacro ()
add_cuda_test_macro(Cuda.ConsumeCompileFeatures CudaConsumeCompileFeatures)
add_cuda_test_macro(Cuda.CXXStandardSetTwice CXXStandardSetTwice)
add_cuda_test_macro(Cuda.ObjectLibrary CudaObjectLibrary)
add_cuda_test_macro(Cuda.MixedStandardLevels1 MixedStandardLevels1)

View File

@ -1,16 +0,0 @@
cmake_minimum_required(VERSION 3.18)
project(ConsumeCompileFeatures CXX CUDA)
#Goal for this example:
#build a c++11 library that express a c++11 public compile feature
#link a cuda library and verify it builds with c++11 enabled
#build a standalone c++/cuda mixed executable where we express a c++11
#compile feature.
add_library(CudaConsumeLib STATIC static.cpp static.cu)
target_compile_features(CudaConsumeLib PUBLIC cxx_nullptr)
add_executable(CudaConsumeCompileFeatures main.cu)
target_link_libraries(CudaConsumeCompileFeatures PRIVATE CudaConsumeLib)

View File

@ -1,20 +0,0 @@
#include <iostream>
int static_cxx11_func(int);
void test_functions()
{
auto x = static_cxx11_func(int(42));
std::cout << x << std::endl;
}
int main(int argc, char** argv)
{
test_functions();
std::cout
<< "this executable doesn't use cuda code, just call methods defined"
<< std::endl;
std::cout << "in libraries that have cuda code" << std::endl;
return 0;
}

View File

@ -1,10 +0,0 @@
#include <type_traits>
int static_cuda11_func(int);
int static_cxx11_func(int x)
{
return static_cuda11_func(x) + std::integral_constant<int, 32>::value;
}

View File

@ -1,9 +0,0 @@
#include <type_traits>
using tt = std::true_type;
using ft = std::false_type;
int __host__ static_cuda11_func(int x)
{
return x * x + std::integral_constant<int, 17>::value;
}

View File

@ -1,4 +1,2 @@
^CMake Error at cxx_not_enabled.cmake:[0-9]+ \(target_compile_features\):
target_compile_features cannot use features from non-enabled language CXX
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$
^CMake Error:.*CMake can not determine linker language for target: main.*
CMake Generate step failed. Build files cannot be regenerated correctly.$