ISPC: Generated Headers suffix configurable with a better default
The target property `ISPC_HEADER_SUFFIX` and associated global variable now can control the suffix used when generating the C/C++ interoperability ISPC headers. In addition the default suffix is now "_ispc.h" which matches the common convention that the ISPC compiler team uses and recommends.
This commit is contained in:
parent
6aff058ab4
commit
c9a50f3556
@ -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
|
||||
|
@ -515,6 +515,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
Help/prop_tgt/ISPC_HEADER_SUFFIX.rst
Normal file
14
Help/prop_tgt/ISPC_HEADER_SUFFIX.rst
Normal file
@ -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``.
|
@ -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
Help/variable/CMAKE_ISPC_HEADER_SUFFIX.rst
Normal file
10
Help/variable/CMAKE_ISPC_HEADER_SUFFIX.rst
Normal file
@ -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.
|
@ -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);
|
||||
|
@ -2426,9 +2426,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);
|
||||
@ -2451,14 +2454,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);
|
||||
}
|
||||
}
|
||||
|
@ -591,6 +591,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 =
|
||||
@ -598,7 +603,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);
|
||||
}
|
||||
|
@ -1374,6 +1374,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);
|
||||
@ -1384,7 +1389,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
|
||||
|
@ -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");
|
||||
|
@ -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,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "extra.ispc.h"
|
||||
#include "extra_ispc.h"
|
||||
|
||||
int extra()
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
23
Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt
Normal file
23
Tests/ISPC/CustomHeaderSuffix/CMakeLists.txt
Normal file
@ -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
Tests/ISPC/CustomHeaderSuffix/extra.cxx
Normal file
17
Tests/ISPC/CustomHeaderSuffix/extra.cxx
Normal file
@ -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
Tests/ISPC/CustomHeaderSuffix/extra.ispc
Normal file
12
Tests/ISPC/CustomHeaderSuffix/extra.ispc
Normal file
@ -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
Tests/ISPC/CustomHeaderSuffix/main.cxx
Normal file
15
Tests/ISPC/CustomHeaderSuffix/main.cxx
Normal file
@ -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
Tests/ISPC/CustomHeaderSuffix/simple.ispc
Normal file
12
Tests/ISPC/CustomHeaderSuffix/simple.ispc
Normal file
@ -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,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "extra.ispc.h"
|
||||
#include "extra_ispc.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# define EXPORT __declspec(dllexport)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# define EXPORT __declspec(dllexport)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "extra.ispc.h"
|
||||
#include "extra_ispc.h"
|
||||
|
||||
int extra()
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "simple.ispc.h"
|
||||
#include "simple_ispc.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -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>")
|
||||
|
Loading…
Reference in New Issue
Block a user