diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-12-08 19:24:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-08 19:24:34 +0800 |
| commit | 4321929879c1ed5b87ff95a99ca7da91e28d18fd (patch) | |
| tree | ae1460dcb652981468e6fa4897e87b697f2bda33 /source/slang | |
| parent | 9903688ccc0793259d43f95cae88bd1a8e178824 (diff) | |
WIP: CMake (#3326)
* More robust input and output selection in generator tools
* Add cmake build system
* Get slang-test running with cmake
* Bump lz4 and miniz dependencies
* Make cmake build more declarative
* Correct preprocessor logic in slang.h
* Add cuda test to compute/simple
* Remove empty cmake files
* output placement for cmake, and commenting
* Correct include paths in spirv-embed-generator
* Format cmake with gersemi
* Make cmake build clerer
* Neaten header generation
Also work around https://gitlab.kitware.com/cmake/cmake/-/issues/18399
by introducing correct_generated_properties to set the GENERATED flag in
the correct scope
* remove unused files
* use 3.20 to set GENERATOR property properly
* spelling
* more flexible linker arg setting
* replace slang-static with obj collection
* Set rpath and linker path correctly
* neaten generated file generation
* tests working with cmake build
* fix premake5 build
* comment and neaten cmake
* remove unnecessary dependency
* Build aftermath example only when aftermath is enabled
* Add slang-llvm and other dependencies
* Put modules alongside binaries
* Find slang-glslang correctly
* Better option handling
* comments
* add llvm build test
* Better option handling
* cmake wobble
* use UNICODE and _UNICODE
* remove other workflows
* use ccache
* neaten
* limit parallel for llvm build
* use ninja for build
* Windows and Darwin slang-llvm builds
* cache key
* verbose llvm build
* cl on windows
* sccache and cl.exe
* use cl.exe
* Correct package detection
* less verbosity
* Simplify miniz inclusion
* fix build with sccache
* Neaten llvm building
* neaten
* Neaten slang-llvm fetching
* more surgical workarounds
* Add ci action
* Get version from git
* better variable naming
* add missing include
* clean up after premake in cmake
* more docs on cmake build
* ci wobble
* add imgui target
* more selective source
* do not download swiftshader
* Some missing dependencies
* only build llvm on dispatch
* Disable /Zi in CI where sccache is present
* simplify
* set PIC for miniz
* set policies before project
* reengage workaround
* more runs on ci
* Add cmake presets
* Add cpack
* move iterator debug level to preset
* Correct lib flag
* simplify action
* Neaten cmake init
* Add todo
* Add simple test wrapper
* Add tests to workflow presets
* rename packing preset
* Correctly set definitions
* docs
* correct preset names
* Make slang-test depend on test-server/test-process
* neaten
* use workflow in actions
* install docs
* Correct module install dir
* debug dist workflow
* Install headers
* neaten header globbing
* Neaten dependency handling
* make lib and bin variables
* Do not set compiler for vs builds, unnecessary
* docs
* allow setting explicit source for target
* maintain archive subdir
* cmake docs
* install headers
* place targets into folders
* cmake docs
* nest external projects in folder
* remove name clash
* Neater external packages
* meta targets in folder structure
* cleaner slang-glslang dll
* Add missing static directive to slang-no-embedded-stdlib
* more robust module copying
* make slang-test the startup project
* folder tweak
* Make FETCH_BINARY the default on all platforms
* Set DEBUG_DIR
* add natvis files to source
* skip spirv tests
* remove test step from debug dist
* Add build to .gitignore
* redo warnings to be more like premake
* Update imgui
* clean more premake files
* Disable PCH for glslang, gcc throws a warning
* Add /MP for msvc builds
* warning wobble
* Add script to build llvm
* Add slang-llvm and generators components
* Build slang-llvm in ci
* comments
* fetch llvm with git
* better abi approximation for cache
* better sccache key
* formatting
* Correct logic around disabling problematic debug info for ccache
* exclude gcc and clang from windows ci
* Make dist workflows use system llvm
* naming
* restore normal dist builds
* formatting
* run tests in ci
* Correct slang-llvm url setting
* Rely on the system to find the test tool library
* actions matrix wiggle
* cope with OSX ancient bash
* Correct compilers on windows
* more ci debugging
* Correct rpath handling on OSX
* neaten
* correct path to slang-llvm
* Correct rpath separator on osx
* Find slang-llvm correctly
* smoke tests only on osx
* ci wobble
* Give MacOS module a dylib suffix
* get swiftshader correctly
* cope with bsd cp
* remove debug output
* full tests on osx
* ci wobble
* Add some vk tests to expected failures
* simplify ci
* ci wobble
* exclude dx12 tests from github ci
* remove cmake code for building llvm
* warnings
* warnings as errors for cl
* spirv-tools in path
* add aarch64 ci build
* Add SLANG_GENERATORS_PATH option for prebuilt generators
* neaten
* Correct generator target name
* remove yaml anchors because github actions does not support them
* Demote CMake in docs
Also add info on cross compiling
* Restore premake CI
* use minimal ci for cmake
* Write miniz_export for premake build
and .gitignore it
* Mention build config tool options in docs
* Remove redefined macro for miniz
* regenerate vs project
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/CMakeLists.txt | 187 | ||||
| -rw-r--r-- | source/slang/slang-compiler.cpp | 1 |
2 files changed, 188 insertions, 0 deletions
diff --git a/source/slang/CMakeLists.txt b/source/slang/CMakeLists.txt new file mode 100644 index 000000000..c3ea18433 --- /dev/null +++ b/source/slang/CMakeLists.txt @@ -0,0 +1,187 @@ +# +# Compiling the meta.slang files +# + +# List of *.meta.slang headers +glob_append(SLANG_STDLIB_META_SOURCE "*.meta.slang") + +set(SLANG_STDLIB_META_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/stdlib-meta") + +# Generate the output file list +set(SLANG_STDLIB_META_GENERATED_HEADERS) +foreach(meta_source ${SLANG_STDLIB_META_SOURCE}) + file( + RELATIVE_PATH + meta_source_relative + ${CMAKE_CURRENT_LIST_DIR} + ${meta_source} + ) + list( + APPEND + SLANG_STDLIB_META_GENERATED_HEADERS + "${SLANG_STDLIB_META_OUTPUT_DIR}/${meta_source_relative}.h" + ) +endforeach() + +add_custom_command( + OUTPUT ${SLANG_STDLIB_META_GENERATED_HEADERS} + COMMAND ${CMAKE_COMMAND} -E make_directory ${SLANG_STDLIB_META_OUTPUT_DIR} + COMMAND + slang-generate ${SLANG_STDLIB_META_SOURCE} --target-directory + ${SLANG_STDLIB_META_OUTPUT_DIR} + DEPENDS ${SLANG_STDLIB_META_SOURCE} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + VERBATIM +) + +add_library( + slang-meta-headers + INTERFACE + EXCLUDE_FROM_ALL + ${SLANG_STDLIB_META_GENERATED_HEADERS} +) +set_target_properties(slang-meta-headers PROPERTIES FOLDER generated) +target_include_directories( + slang-meta-headers + INTERFACE ${SLANG_STDLIB_META_OUTPUT_DIR} +) + +# +# generated headers for reflection +# + +set(SLANG_REFLECT_INPUT + slang-ast-support-types.h + slang-ast-base.h + slang-ast-decl.h + slang-ast-expr.h + slang-ast-modifier.h + slang-ast-stmt.h + slang-ast-type.h + slang-ast-val.h +) +# Make them absolute +list(TRANSFORM SLANG_REFLECT_INPUT PREPEND "${CMAKE_CURRENT_LIST_DIR}/") + +set(SLANG_REFLECT_GENERATED_HEADERS + slang-generated-obj.h + slang-generated-obj-macro.h + slang-generated-ast.h + slang-generated-ast-macro.h + slang-generated-value.h + slang-generated-value-macro.h +) +set(SLANG_REFLECT_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/ast-reflect") +list( + TRANSFORM SLANG_REFLECT_GENERATED_HEADERS + PREPEND "${SLANG_REFLECT_OUTPUT_DIR}/" +) + +add_custom_command( + OUTPUT ${SLANG_REFLECT_GENERATED_HEADERS} + COMMAND ${CMAKE_COMMAND} -E make_directory ${SLANG_REFLECT_OUTPUT_DIR} + COMMAND + slang-cpp-extractor ${SLANG_REFLECT_INPUT} -strip-prefix slang- -o + ${SLANG_REFLECT_OUTPUT_DIR}/slang-generated -output-fields -mark-suffix + _CLASS + DEPENDS ${SLANG_REFLECT_INPUT} + VERBATIM +) + +add_library( + slang-reflect-headers + INTERFACE + EXCLUDE_FROM_ALL + ${SLANG_REFLECT_GENERATED_HEADERS} +) +set_target_properties(slang-reflect-headers PROPERTIES FOLDER generated) +target_include_directories( + slang-reflect-headers + INTERFACE ${SLANG_REFLECT_OUTPUT_DIR} +) + +# +# Slang static +# + +# TODO: Avoid compiling everything in this directory twice (once here and again +# for the shared library). This will be easier once premake is gone and we can +# move slang-stdlib-api.cpp to the build directory. It's basically instant with +# ccache, but that's not available everywhere. +slang_add_target( + . + OBJECT + TARGET_NAME slang-no-embedded-stdlib + EXCLUDE_FROM_ALL + EXTRA_COMPILE_DEFINITIONS_PUBLIC SLANG_STATIC + LINK_WITH_PRIVATE + core + compiler-core + # Bundle the source unconditionally + slang-meta-headers + slang-reflect-headers + SPIRV-Headers + FOLDER generators +) +target_compile_definitions( + slang-no-embedded-stdlib + PRIVATE SLANG_WITHOUT_EMBEDDED_STD_LIB +) + +# +# Generate an embeddable stdlib +# + +set(SLANG_STDLIB_GENERATED_HEADER + ${CMAKE_CURRENT_BINARY_DIR}/slang-stdlib-generated.h +) +add_custom_command( + OUTPUT ${SLANG_STDLIB_GENERATED_HEADER} + COMMAND + slang-bootstrap -archive-type riff-lz4 -save-stdlib-bin-source + ${SLANG_STDLIB_GENERATED_HEADER} + VERBATIM +) +add_library( + slang-stdlib-embed-headers + INTERFACE + EXCLUDE_FROM_ALL + ${SLANG_STDLIB_GENERATED_HEADER} +) +set_target_properties(slang-stdlib-embed-headers PROPERTIES FOLDER generated) +target_include_directories( + slang-stdlib-embed-headers + INTERFACE ${CMAKE_CURRENT_BINARY_DIR} +) + +# +# Slang itself +# +slang_add_target( + . + SHARED + LINK_WITH_PRIVATE + core + compiler-core + prelude + slang-reflect-headers + SPIRV-Headers + # slang.h is in the project root, so include that directory in the interface + # for slang + INCLUDE_DIRECTORIES_PUBLIC ${slang_SOURCE_DIR} + EXPORT_MACRO_PREFIX SLANG + INSTALL + PUBLIC_HEADERS ${slang_SOURCE_DIR}/slang*.h +) + +if(SLANG_EMBED_STDLIB_SOURCE) + target_link_libraries(slang PRIVATE slang-meta-headers) +else() + target_compile_definitions(slang PRIVATE SLANG_DISABLE_STDLIB_SOURCE) +endif() + +if(SLANG_EMBED_STDLIB) + target_link_libraries(slang PRIVATE slang-stdlib-embed-headers) +else() + target_compile_definitions(slang PRIVATE SLANG_WITHOUT_EMBEDDED_STD_LIB) +endif() diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 8956663cc..c2bb515f6 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1354,6 +1354,7 @@ namespace Slang if (_isCPUHostTarget(target)) { libraryPaths.add(Path::getParentDirectory(Path::getExecutablePath())); + libraryPaths.add(Path::combine(Path::getParentDirectory(Path::getExecutablePath()), "../lib")); // Set up the library artifact auto artifact = Artifact::create(ArtifactDesc::make(ArtifactKind::Library, Artifact::Payload::HostCPU), toSlice("slang-rt")); |
