浏览代码

Merge topic 'ispc_control_header_suffixes'

c9a50f3556 ISPC: Generated Headers suffix configurable with a better default

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5597
Brad King 4 年之前
父节点
当前提交
67f12dd1d6

+ 1 - 0
Help/manual/cmake-properties.7.rst

@@ -259,6 +259,7 @@ Properties on Targets
    /prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG
    /prop_tgt/IOS_INSTALL_COMBINED
    /prop_tgt/ISPC_HEADER_DIRECTORY
+   /prop_tgt/ISPC_HEADER_SUFFIX
    /prop_tgt/ISPC_INSTRUCTION_SETS
    /prop_tgt/JOB_POOL_COMPILE
    /prop_tgt/JOB_POOL_LINK

+ 1 - 0
Help/manual/cmake-variables.7.rst

@@ -518,6 +518,7 @@ Variables for Languages
    /variable/CMAKE_Fortran_MODDIR_FLAG
    /variable/CMAKE_Fortran_MODOUT_FLAG
    /variable/CMAKE_ISPC_HEADER_DIRECTORY
+   /variable/CMAKE_ISPC_HEADER_SUFFIX
    /variable/CMAKE_ISPC_INSTRUCTION_SETS
    /variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE
    /variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX

+ 14 - 0
Help/prop_tgt/ISPC_HEADER_SUFFIX.rst

@@ -0,0 +1,14 @@
+ISPC_HEADER_SUFFIX
+------------------
+
+.. versionadded:: 3.19.2
+
+Specify output suffix to be used for ISPC generated headers provided by the target.
+
+This property is initialized by the value of the :variable:`CMAKE_ISPC_HEADER_SUFFIX`
+variable if it is set when a target  is created.
+
+If the target contains ISPC source files, this specifies the header suffix to
+be used for the generated headers.
+
+The default value is ``_ispc.h``.

+ 4 - 0
Help/release/3.19.rst

@@ -381,3 +381,7 @@ Changes made since CMake 3.19.0 include the following.
   the invoking process tree, the :variable:`CMAKE_APPLE_SILICON_PROCESSOR`
   variable or :envvar:`CMAKE_APPLE_SILICON_PROCESSOR` environment
   variable may be set to specify a host architecture explicitly.
+
+* The :variable:`CMAKE_ISPC_HEADER_SUFFIX` variable and corresponding
+  :prop_tgt:`ISPC_HEADER_SUFFIX` target property were added to control
+  the header suffix used by ``ISPC`` compiler generated headers.

+ 10 - 0
Help/variable/CMAKE_ISPC_HEADER_SUFFIX.rst

@@ -0,0 +1,10 @@
+CMAKE_ISPC_HEADER_SUFFIX
+------------------------
+
+.. versionadded:: 3.19.2
+
+Output suffix to be used for ISPC generated headers.
+
+This variable is used to initialize the :prop_tgt:`ISPC_HEADER_SUFFIX`
+property on all the targets.  See the target property for additional
+information.

+ 2 - 0
Source/cmCoreTryCompile.cxx

@@ -201,6 +201,7 @@ std::string const kCMAKE_CUDA_ARCHITECTURES = "CMAKE_CUDA_ARCHITECTURES";
 std::string const kCMAKE_CUDA_RUNTIME_LIBRARY = "CMAKE_CUDA_RUNTIME_LIBRARY";
 std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
 std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS";
+std::string const kCMAKE_ISPC_HEADER_SUFFIX = "CMAKE_ISPC_HEADER_SUFFIX";
 std::string const kCMAKE_LINK_SEARCH_END_STATIC =
   "CMAKE_LINK_SEARCH_END_STATIC";
 std::string const kCMAKE_LINK_SEARCH_START_STATIC =
@@ -718,6 +719,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
       vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY);
       vars.insert(kCMAKE_ENABLE_EXPORTS);
       vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS);
+      vars.insert(kCMAKE_ISPC_HEADER_SUFFIX);
       vars.insert(kCMAKE_LINK_SEARCH_END_STATIC);
       vars.insert(kCMAKE_LINK_SEARCH_START_STATIC);
       vars.insert(kCMAKE_OSX_ARCHITECTURES);

+ 12 - 4
Source/cmLocalGenerator.cxx

@@ -2438,9 +2438,12 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
     return;
   }
 
-  std::vector<std::string> ispcSuffixes =
+  cmProp ispcHeaderSuffixProp = target->GetProperty("ISPC_HEADER_SUFFIX");
+  assert(ispcHeaderSuffixProp != nullptr);
+
+  std::vector<std::string> ispcArchSuffixes =
     detail::ComputeISPCObjectSuffixes(target);
-  const bool extra_objects = (ispcSuffixes.size() > 1);
+  const bool extra_objects = (ispcArchSuffixes.size() > 1);
 
   std::vector<std::string> configsList =
     this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
@@ -2463,14 +2466,19 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target)
       const std::string& lang = sf->GetLanguage();
       if (lang == "ISPC") {
         std::string const& objectName = target->GetObjectName(sf);
+
+        // Drop both ".obj" and the source file extension
         std::string ispcSource =
           cmSystemTools::GetFilenameWithoutLastExtension(objectName);
+        ispcSource =
+          cmSystemTools::GetFilenameWithoutLastExtension(ispcSource);
 
-        auto headerPath = cmStrCat(headerDir, '/', ispcSource, ".h");
+        auto headerPath =
+          cmStrCat(headerDir, '/', ispcSource, *ispcHeaderSuffixProp);
         target->AddISPCGeneratedHeader(headerPath, config);
         if (extra_objects) {
           std::vector<std::string> objs = detail::ComputeISPCExtraObjects(
-            objectName, rootObjectDir, ispcSuffixes);
+            objectName, rootObjectDir, ispcArchSuffixes);
           target->AddISPCGeneratedObject(std::move(objs), config);
         }
       }

+ 6 - 1
Source/cmMakefileTargetGenerator.cxx

@@ -644,6 +644,11 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
   if (lang == "ISPC") {
     std::string ispcSource =
       cmSystemTools::GetFilenameWithoutLastExtension(objectName);
+    ispcSource = cmSystemTools::GetFilenameWithoutLastExtension(ispcSource);
+
+    cmProp ispcSuffixProp =
+      this->GeneratorTarget->GetProperty("ISPC_HEADER_SUFFIX");
+    assert(ispcSuffixProp != nullptr);
 
     std::string directory = this->GeneratorTarget->GetObjectDirectory(config);
     if (cmProp prop =
@@ -651,7 +656,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
       directory =
         cmStrCat(this->LocalGenerator->GetBinaryDirectory(), '/', *prop);
     }
-    ispcHeaderRelative = cmStrCat(directory, '/', ispcSource, ".h");
+    ispcHeaderRelative = cmStrCat(directory, '/', ispcSource, *ispcSuffixProp);
     ispcHeaderForShell = this->LocalGenerator->ConvertToOutputFormat(
       ispcHeaderRelative, cmOutputConverter::SHELL);
   }

+ 6 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -1356,6 +1356,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
       this->GeneratorTarget->GetObjectName(source);
     std::string ispcSource =
       cmSystemTools::GetFilenameWithoutLastExtension(objectName);
+    ispcSource = cmSystemTools::GetFilenameWithoutLastExtension(ispcSource);
+
+    cmProp ispcSuffixProp =
+      this->GeneratorTarget->GetProperty("ISPC_HEADER_SUFFIX");
+    assert(ispcSuffixProp != nullptr);
 
     std::string ispcHeaderDirectory =
       this->GeneratorTarget->GetObjectDirectory(config);
@@ -1366,7 +1371,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
     }
 
     std::string ispcHeader =
-      cmStrCat(ispcHeaderDirectory, '/', ispcSource, ".h");
+      cmStrCat(ispcHeaderDirectory, '/', ispcSource, *ispcSuffixProp);
     ispcHeader = this->ConvertToNinjaPath(ispcHeader);
 
     // Make sure ninja knows what command generates the header

+ 1 - 0
Source/cmTarget.cxx

@@ -369,6 +369,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
     initProp("JOB_POOL_PRECOMPILE_HEADER");
     initProp("ISPC_COMPILER_LAUNCHER");
     initProp("ISPC_HEADER_DIRECTORY");
+    initPropValue("ISPC_HEADER_SUFFIX", "_ispc.h");
     initProp("ISPC_INSTRUCTION_SETS");
     initProp("LINK_SEARCH_START_STATIC");
     initProp("LINK_SEARCH_END_STATIC");

+ 1 - 0
Tests/ISPC/CMakeLists.txt

@@ -7,6 +7,7 @@ macro (add_ispc_test_macro name)
 endmacro ()
 
 add_ispc_test_macro(ISPC.ChainedStaticLibraries ISPCChainedStaticLibraries)
+add_ispc_test_macro(ISPC.CustomHeaderSuffix ISPCCustomHeaderSuffix)
 add_ispc_test_macro(ISPC.Defines ISPCDefines)
 add_ispc_test_macro(ISPC.DynamicLibrary ISPCDynamicLibrary)
 add_ispc_test_macro(ISPC.ObjectGenex ISPCObjectGenex)

+ 1 - 1
Tests/ISPC/ChainedStaticLibraries/extra.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "extra.ispc.h"
+#include "extra_ispc.h"
 
 int extra()
 {

+ 1 - 1
Tests/ISPC/ChainedStaticLibraries/main.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 int main()
 {

+ 23 - 0
Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt

@@ -0,0 +1,23 @@
+
+cmake_minimum_required(VERSION 3.18)
+project(ISPCCustomHeaderSuffix CXX ISPC)
+
+if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+  set(CMAKE_ISPC_FLAGS "--arch=x86")
+endif()
+
+set(CMAKE_ISPC_INSTRUCTION_SETS "sse2-i32x4;sse4-i8x16")
+
+set(CMAKE_ISPC_HEADER_SUFFIX ".ispc.h")
+
+add_library(ispc_suffix_1 OBJECT simple.ispc)
+add_library(ispc_suffix_2 OBJECT extra.ispc)
+
+set_target_properties(ispc_suffix_2 PROPERTIES ISPC_HEADER_SUFFIX "___ispc.h")
+
+set_target_properties(ispc_suffix_1 ispc_suffix_2
+  PROPERTIES POSITION_INDEPENDENT_CODE ON
+)
+
+add_executable(ISPCCustomHeaderSuffix main.cxx extra.cxx)
+target_link_libraries(ISPCCustomHeaderSuffix PRIVATE ispc_suffix_1 ispc_suffix_2)

+ 17 - 0
Tests/ISPC/CustomHeaderSuffix/extra.cxx

@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+#include "extra___ispc.h"
+
+int extra()
+{
+  float vin[16], vout[16];
+  for (int i = 0; i < 16; ++i)
+    vin[i] = i;
+
+  ispc::extra(vin, vout, 16);
+
+  for (int i = 0; i < 16; ++i)
+    printf("%d: extra(%f) = %f\n", i, vin[i], vout[i]);
+
+  return 0;
+}

+ 12 - 0
Tests/ISPC/CustomHeaderSuffix/extra.ispc

@@ -0,0 +1,12 @@
+
+export void extra(uniform float vin[], uniform float vout[],
+                   uniform int count) {
+    foreach (index = 0 ... count) {
+        float v = vin[index];
+        if (v < 3.)
+            v = v * v;
+        else
+            v = sqrt(v);
+        vout[index] = v;
+    }
+}

+ 15 - 0
Tests/ISPC/CustomHeaderSuffix/main.cxx

@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+#include "simple.ispc.h"
+
+int main()
+{
+  float vin[16], vout[16];
+  for (int i = 0; i < 16; ++i)
+    vin[i] = i;
+
+  ispc::simple(vin, vout, 16);
+
+  for (int i = 0; i < 16; ++i)
+    printf("%d: simple(%f) = %f\n", i, vin[i], vout[i]);
+}

+ 12 - 0
Tests/ISPC/CustomHeaderSuffix/simple.ispc

@@ -0,0 +1,12 @@
+
+export void simple(uniform float vin[], uniform float vout[],
+                   uniform int count) {
+    foreach (index = 0 ... count) {
+        float v = vin[index];
+        if (v < 3.)
+            v = v * v;
+        else
+            v = sqrt(v);
+        vout[index] = v;
+    }
+}

+ 1 - 1
Tests/ISPC/Defines/main.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 int main()
 {

+ 1 - 1
Tests/ISPC/DynamicLibrary/extra.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "extra.ispc.h"
+#include "extra_ispc.h"
 
 #ifdef _WIN32
 #  define EXPORT __declspec(dllexport)

+ 1 - 1
Tests/ISPC/DynamicLibrary/simple.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 #ifdef _WIN32
 #  define EXPORT __declspec(dllexport)

+ 1 - 1
Tests/ISPC/ObjectLibrary/extra.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "extra.ispc.h"
+#include "extra_ispc.h"
 
 int extra()
 {

+ 1 - 1
Tests/ISPC/ObjectLibrary/main.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 int main()
 {

+ 1 - 1
Tests/ISPC/ResponseAndDefine/main.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 int main()
 {

+ 1 - 1
Tests/ISPC/StaticLibrary/main.cxx

@@ -1,6 +1,6 @@
 #include <stdio.h>
 
-#include "simple.ispc.h"
+#include "simple_ispc.h"
 
 int main()
 {

+ 2 - 0
Tests/ISPC/SystemIncludes/CMakeLists.txt

@@ -4,8 +4,10 @@ project(ispc_spaces_in_path ISPC CXX)
 
 add_executable(ISPCSystemIncludes main.cxx simple.ispc)
 set_target_properties(ISPCSystemIncludes PROPERTIES POSITION_INDEPENDENT_CODE ON)
+set_target_properties(ISPCSystemIncludes PROPERTIES ISPC_HEADER_SUFFIX ".ispc.h")
 target_include_directories(ISPCSystemIncludes SYSTEM PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
 
+
 target_compile_options(ISPCSystemIncludes PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--target=sse2-i32x4>")
 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
   target_compile_options(ISPCSystemIncludes PRIVATE "$<$<COMPILE_LANGUAGE:ISPC>:--arch=x86>")