mirror of
https://github.com/reactos/CMake.git
synced 2025-02-24 05:53:21 +00:00
Merge topic 'extend-compile-language-genex'
2ae880fa Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio 2b7d59f3 Genex: Enable COMPILE_LANGUAGE for file(GENERATE) with Visual Studio 0f6f7c8a Genex: Fix COMPILE_LANGUAGE messages to allow file(GENERATE) with Xcode c5a82d0f Tests: Decouple COMPILE_LANGUAGE in file(GENERATE) from COMPILE_OPTIONS 25773650 Tests: Remove unnecessary result files from RunCMake.File_Generate Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Jason Juang <jasjuang@gmail.com> Merge-request: !1511
This commit is contained in:
commit
1882ba2e05
@ -97,7 +97,7 @@ Available logical expressions are:
|
||||
compile features and a list of supported compilers.
|
||||
``$<COMPILE_LANGUAGE:lang>``
|
||||
``1`` when the language used for compilation unit matches ``lang``,
|
||||
otherwise ``0``. This expression used to specify compile options for
|
||||
otherwise ``0``. This expression may be used to specify compile options for
|
||||
source files of a particular language in a target. For example, to specify
|
||||
the use of the ``-fno-exceptions`` compile option (compiler id checks
|
||||
elided):
|
||||
@ -109,10 +109,12 @@ Available logical expressions are:
|
||||
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
|
||||
)
|
||||
|
||||
This generator expression has limited use because it is not possible to
|
||||
use it with the Visual Studio generators. Portable buildsystems would
|
||||
not use this expression, and would create separate libraries for each
|
||||
source file language instead:
|
||||
Note that with :ref:`Visual Studio Generators` there is no way to represent
|
||||
target-wide flags separately for ``C`` and ``CXX`` languages. Under these
|
||||
generators, target-wide flags for both C and C++ sources will be evaluated
|
||||
using ``CXX`` if there are any C++ sources and otherwise using ``C``.
|
||||
A workaround is to create separate libraries for each source file language
|
||||
instead:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
|
7
Help/release/dev/extend-compile-language-genex.rst
Normal file
7
Help/release/dev/extend-compile-language-genex.rst
Normal file
@ -0,0 +1,7 @@
|
||||
extend-compile-language-genex
|
||||
-----------------------------
|
||||
|
||||
* The ``COMPILE_LANGUAGE`` :manual:`generator expression
|
||||
<cmake-generator-expressions(7)>` may now be used with
|
||||
:ref:`Visual Studio Generators` in :prop_tgt:`COMPILE_OPTIONS`
|
||||
and :command:`file(GENERATE)`.
|
@ -828,18 +828,21 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode
|
||||
}
|
||||
std::string genName = gg->GetName();
|
||||
if (genName.find("Visual Studio") != std::string::npos) {
|
||||
reportError(context, content->GetOriginalExpression(),
|
||||
"$<COMPILE_LANGUAGE:...> may not be used with Visual Studio "
|
||||
"generators.");
|
||||
return std::string();
|
||||
}
|
||||
if (genName.find("Xcode") != std::string::npos) {
|
||||
if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() ||
|
||||
dagChecker->EvaluatingIncludeDirectories())) {
|
||||
reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"$<COMPILE_LANGUAGE:...> may only be used with COMPILE_OPTIONS "
|
||||
"with the Xcode generator.");
|
||||
"$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS "
|
||||
"and file(GENERATE) with the Visual Studio generator.");
|
||||
return std::string();
|
||||
}
|
||||
} else if (genName.find("Xcode") != std::string::npos) {
|
||||
if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() ||
|
||||
dagChecker->EvaluatingIncludeDirectories())) {
|
||||
reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS "
|
||||
"and file(GENERATE) with the Xcode generator.");
|
||||
return std::string();
|
||||
}
|
||||
} else {
|
||||
|
@ -23,18 +23,19 @@ add_executable(consumer
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
|
||||
)
|
||||
|
||||
if (NOT CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
target_sources(consumer PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
|
||||
)
|
||||
target_compile_options(consumer
|
||||
PRIVATE
|
||||
-DCONSUMER_LANG_$<COMPILE_LANGUAGE>
|
||||
-DLANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
|
||||
-DLANG_IS_C=$<COMPILE_LANGUAGE:C>
|
||||
)
|
||||
target_sources(consumer PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
|
||||
)
|
||||
target_compile_options(consumer
|
||||
PRIVATE
|
||||
-DCONSUMER_LANG_$<COMPILE_LANGUAGE>
|
||||
-DLANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
|
||||
-DLANG_IS_C=$<COMPILE_LANGUAGE:C>
|
||||
)
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
target_compile_definitions(consumer
|
||||
PRIVATE -DTEST_LANG_DEFINES
|
||||
PRIVATE TEST_LANG_DEFINES_FOR_VISUAL_STUDIO
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -1,5 +1,23 @@
|
||||
|
||||
#ifdef TEST_LANG_DEFINES
|
||||
// Visual Studio allows only one set of flags for C and C++.
|
||||
// In a target using C++ we pick the C++ flags even for C sources.
|
||||
#ifdef TEST_LANG_DEFINES_FOR_VISUAL_STUDIO
|
||||
#ifndef CONSUMER_LANG_CXX
|
||||
#error Expected CONSUMER_LANG_CXX
|
||||
#endif
|
||||
|
||||
#ifdef CONSUMER_LANG_C
|
||||
#error Unexpected CONSUMER_LANG_C
|
||||
#endif
|
||||
|
||||
#if !LANG_IS_CXX
|
||||
#error Expected LANG_IS_CXX
|
||||
#endif
|
||||
|
||||
#if LANG_IS_C
|
||||
#error Unexpected LANG_IS_C
|
||||
#endif
|
||||
#else
|
||||
#ifdef CONSUMER_LANG_CXX
|
||||
#error Unexpected CONSUMER_LANG_CXX
|
||||
#endif
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TEST_LANG_DEFINES
|
||||
#ifndef CONSUMER_LANG_CXX
|
||||
#error Expected CONSUMER_LANG_CXX
|
||||
#endif
|
||||
@ -31,7 +30,6 @@
|
||||
#if LANG_IS_C
|
||||
#error Unexpected LANG_IS_C
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -32,6 +32,8 @@ add_executable(CudaOnlyWithDefs ${main})
|
||||
|
||||
target_compile_options(CudaOnlyWithDefs
|
||||
PRIVATE
|
||||
-DCOMPILE_LANG_$<COMPILE_LANGUAGE>
|
||||
-DLANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
|
||||
-Xcompiler=-DHOST_DEFINE
|
||||
$<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
|
||||
)
|
||||
|
@ -10,6 +10,18 @@
|
||||
#error "PACKED_DEFINE not defined!"
|
||||
#endif
|
||||
|
||||
#ifndef COMPILE_LANG_CUDA
|
||||
#error "COMPILE_LANG_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#ifndef LANG_IS_CUDA
|
||||
#error "LANG_IS_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#if !LANG_IS_CUDA
|
||||
#error "Expected LANG_IS_CUDA"
|
||||
#endif
|
||||
|
||||
static __global__ void DetermineIfValidCudaDevice()
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ CMake Error at CompileDefinitions.cmake:5 \(target_compile_definitions\):
|
||||
|
||||
\$<COMPILE_LANGUAGE:CXX>
|
||||
|
||||
\$<COMPILE_LANGUAGE:...> may not be used with Visual Studio generators.
|
||||
\$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
|
||||
file\(GENERATE\) with the Visual Studio generator.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
@ -3,7 +3,7 @@ CMake Error at CompileDefinitions.cmake:5 \(target_compile_definitions\):
|
||||
|
||||
\$<COMPILE_LANGUAGE:CXX>
|
||||
|
||||
\$<COMPILE_LANGUAGE:...> may only be used with COMPILE_OPTIONS with the
|
||||
Xcode generator.
|
||||
\$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
|
||||
file\(GENERATE\) with the Xcode generator.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
@ -1 +0,0 @@
|
||||
1
|
@ -1,8 +0,0 @@
|
||||
CMake Error at CompileOptions.cmake:5 \(target_compile_options\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<COMPILE_LANGUAGE:CXX>
|
||||
|
||||
\$<COMPILE_LANGUAGE:...> may not be used with Visual Studio generators.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
@ -1,5 +0,0 @@
|
||||
|
||||
enable_language(CXX)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_compile_options(main PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-DANYTHING>)
|
@ -3,6 +3,7 @@ CMake Error at IncludeDirectories.cmake:5 \(target_include_directories\):
|
||||
|
||||
\$<COMPILE_LANGUAGE:CXX>
|
||||
|
||||
\$<COMPILE_LANGUAGE:...> may not be used with Visual Studio generators.
|
||||
\$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
|
||||
file\(GENERATE\) with the Visual Studio generator.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
@ -3,7 +3,7 @@ CMake Error at IncludeDirectories.cmake:5 \(target_include_directories\):
|
||||
|
||||
\$<COMPILE_LANGUAGE:CXX>
|
||||
|
||||
\$<COMPILE_LANGUAGE:...> may only be used with COMPILE_OPTIONS with the
|
||||
Xcode generator.
|
||||
\$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
|
||||
file\(GENERATE\) with the Xcode generator.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
@ -1,9 +1,5 @@
|
||||
include(RunCMake)
|
||||
|
||||
if (RunCMake_GENERATOR MATCHES "Visual Studio")
|
||||
set(RunCMake-stderr-file CompileOptions-stderr-VS.txt)
|
||||
run_cmake(CompileOptions)
|
||||
endif()
|
||||
if (RunCMake_GENERATOR STREQUAL "Xcode")
|
||||
set(RunCMake-stderr-file CompileDefinitions-stderr-Xcode.txt)
|
||||
run_cmake(CompileDefinitions)
|
||||
|
@ -1 +0,0 @@
|
||||
0
|
@ -1,12 +1,6 @@
|
||||
|
||||
enable_language(CXX C)
|
||||
|
||||
add_library(empty empty.cpp empty.c)
|
||||
target_compile_options(empty
|
||||
PRIVATE LANG_IS_$<COMPILE_LANGUAGE>
|
||||
)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opts-$<COMPILE_LANGUAGE>.txt
|
||||
CONTENT "$<TARGET_PROPERTY:empty,COMPILE_OPTIONS>\n"
|
||||
CONTENT "LANG_IS_$<COMPILE_LANGUAGE>\n"
|
||||
)
|
||||
|
@ -1 +0,0 @@
|
||||
0
|
@ -1 +0,0 @@
|
||||
0
|
@ -1 +0,0 @@
|
||||
0
|
@ -21,15 +21,13 @@ if (NOT file_contents MATCHES "generated.cpp.rule")
|
||||
message(SEND_ERROR "Rule file not in target sources! ${file_contents}")
|
||||
endif()
|
||||
|
||||
if (NOT RunCMake_GENERATOR MATCHES "Visual Studio")
|
||||
run_cmake(COMPILE_LANGUAGE-genex)
|
||||
foreach(l CXX C)
|
||||
file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
|
||||
if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
|
||||
message(FATAL_ERROR "File content does not match: ${l_defs}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
run_cmake(COMPILE_LANGUAGE-genex)
|
||||
foreach(l CXX C)
|
||||
file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
|
||||
if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
|
||||
message(FATAL_ERROR "File content does not match: ${l_defs}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(timeformat "%Y%j%H%M%S")
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
0
|
Loading…
x
Reference in New Issue
Block a user