Ver Fonte

Added XShaderCompiler as a dependency (and a submodule)

BearishSun há 8 anos atrás
pai
commit
19fcd1de4a

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "Source/External/XShaderCompiler"]
+	path = Source/External/XShaderCompiler
+	url = https://github.com/BearishSun/XShaderCompiler

+ 10 - 1
Source/BansheeSL/CMakeLists.txt

@@ -24,6 +24,11 @@ else()
 		COMMAND mv BsParserFX.c ${PROJECT_SOURCE_DIR}/BansheeSL/Source)
 endif()
 
+set(DEPENDENCY_BUILD_DIR "${CMAKE_SOURCE_DIR}/../Dependencies/Build/${DEPENDENCY_NAME}")
+set(DEPENDENCY_PARAMS -DXSC_BUILD_SHELL=OFF)
+
+find_package_or_build(XShaderCompiler inc/Xsc/Xsc.h ${DEPENDENCY_PARAMS})
+
 # Source files and their filters
 include(CMakeSources.cmake)
 
@@ -32,7 +37,8 @@ set(BansheeSL_INC
 	"Include"
 	"../BansheeUtility/Include"
 	"../BansheeCore/Include"
-	"../BansheeEngine/Include")
+	"../BansheeEngine/Include"
+	${XShaderCompiler_INCLUDE_DIR})
 
 include_directories(${BansheeSL_INC})
 
@@ -56,6 +62,9 @@ if(WIN32)
 endif()
 
 # Libraries
+## External lib: XShaderCompiler
+target_link_libraries(BansheeSL PRIVATE ${XShaderCompiler_LIBRARIES})
+
 ## Local libs
 target_link_libraries(BansheeSL BansheeEngine BansheeUtility BansheeCore)
 

+ 56 - 0
Source/CMake/FindPackageOrBuild.cmake

@@ -0,0 +1,56 @@
+function(build_dependency DEPENDENCY_NAME BUILD_CONFIG BUILD_OPTIONS)
+	set(DEPENDENCY_BUILD_DIR "${CMAKE_SOURCE_DIR}/../Dependencies/Build/${DEPENDENCY_NAME}/${BUILD_CONFIG}")
+	
+	# Make the build folder
+	execute_process(COMMAND "${CMAKE_COMMAND}" 
+						-E make_directory ${DEPENDENCY_BUILD_DIR}
+					WORKING_DIRECTORY "${DEPENDENCY_BUILD_DIR}")	
+	
+	# Make build files
+	execute_process(COMMAND "${CMAKE_COMMAND}" 
+						-G "${CMAKE_GENERATOR}"
+						${BUILD_OPTIONS}
+						"${CMAKE_SOURCE_DIR}/External/${DEPENDENCY_NAME}"
+						WORKING_DIRECTORY "${DEPENDENCY_BUILD_DIR}")
+					
+	# Execute the build and install
+	execute_process(COMMAND "${CMAKE_COMMAND}" 
+		--build "${DEPENDENCY_BUILD_DIR}"
+		--config ${BUILD_CONFIG})		
+
+	execute_process(COMMAND "${CMAKE_COMMAND}" 
+		--build "${DEPENDENCY_BUILD_DIR}"
+		--config ${BUILD_CONFIG}
+		--target Install)
+endfunction()
+
+function(find_package_or_build DEPENDENCY_NAME DEPENDENCY_INCLUDE_PATH BUILD_OPTIONS)
+	set(DEPENDENCY_BUILD_DIR "${CMAKE_SOURCE_DIR}/../Dependencies/Build/${DEPENDENCY_NAME}")
+	set(DEPENDENCY_SOURCE_DIR "${CMAKE_SOURCE_DIR}/External/${DEPENDENCY_NAME}")
+
+	# Look for dependency binaries
+	find_package(${DEPENDENCY_NAME} QUIET)
+
+	# Cannot find binaries, see if we can compile them
+	if(NOT ${DEPENDENCY_NAME}_FOUND)
+		message(STATUS "...${DEPENDENCY_NAME} binaries cannot be found, building from source and retrying.")
+
+		# See if we have the source code for the dependency, and if not fetch them from git
+		find_path(SUBMODULE_SOURCES ${DEPENDENCY_INCLUDE_PATH} ${DEPENDENCY_SOURCE_DIR})
+		if(NOT SUBMODULE_SOURCES)
+			execute_process(COMMAND git submodule update 
+								--init 
+								-- External/${DEPENDENCY_NAME}
+							WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+		endif()
+
+		# Build
+		build_dependency(${DEPENDENCY_NAME} Release ${BUILD_OPTIONS})
+		build_dependency(${DEPENDENCY_NAME} Debug ${BUILD_OPTIONS})
+		
+		# Now try finding the package again, this time it's required
+		find_package(${DEPENDENCY_NAME} REQUIRED)
+		
+		mark_as_advanced(SUBMODULE_SOURCES)
+	endif()
+endfunction()

+ 61 - 0
Source/CMake/Modules/FindXShaderCompiler.cmake

@@ -0,0 +1,61 @@
+# Find XShaderCompiler tool dependency
+#
+# This module defines
+#  XShaderCompiler_INCLUDE_DIRS
+#  XShaderCompiler_LIBRARIES
+#  XShaderCompiler_FOUND
+
+set(XShaderCompiler_INSTALL_DIR ${PROJECT_SOURCE_DIR}/../Dependencies/XShaderCompiler CACHE PATH "")
+set(XShaderCompiler_SOURCE_DIR ${PROJECT_SOURCE_DIR}/External/XShaderCompiler)
+set(XShaderCompiler_BUILD_DIR ${PROJECT_SOURCE_DIR}/../Dependencies/Build/XShaderCompiler)
+
+set(XShaderCompiler_INCLUDE_SEARCH_DIRS 
+	"${XShaderCompiler_INSTALL_DIR}/include"
+	"${XShaderCompiler_SOURCE_DIR}/inc")
+
+if(BS_64BIT)
+	list(APPEND XShaderCompiler_LIBRARY_RELEASE_SEARCH_DIRS "${XShaderCompiler_INSTALL_DIR}/lib/x64/Release")
+	list(APPEND XShaderCompiler_LIBRARY_DEBUG_SEARCH_DIRS "${XShaderCompiler_INSTALL_DIR}/lib/x64/Debug")
+else()
+	list(APPEND XShaderCompiler_LIBRARY_RELEASE_SEARCH_DIRS "${XShaderCompiler_INSTALL_DIR}/lib/x86/Release")
+	list(APPEND XShaderCompiler_LIBRARY_DEBUG_SEARCH_DIRS "${XShaderCompiler_INSTALL_DIR}/lib/x86/Debug")
+endif()
+
+list(APPEND XShaderCompiler_LIBRARY_RELEASE_SEARCH_DIRS "${XShaderCompiler_BUILD_DIR}/Release/install")
+list(APPEND XShaderCompiler_LIBRARY_DEBUG_SEARCH_DIRS "${XShaderCompiler_BUILD_DIR}/Debug/install")
+
+message(STATUS "Looking for XShaderCompiler installation...")
+	
+find_path(XShaderCompiler_INCLUDE_DIR Xsc/Xsc.h PATHS ${XShaderCompiler_INCLUDE_SEARCH_DIRS})
+find_library(XShaderCompiler_LIBRARY_RELEASE NAMES xsc_core PATHS ${XShaderCompiler_LIBRARY_RELEASE_SEARCH_DIRS})
+find_library(XShaderCompiler_LIBRARY_DEBUG NAMES xsc_core PATHS ${XShaderCompiler_LIBRARY_DEBUG_SEARCH_DIRS})
+
+if(XShaderCompiler_INCLUDE_DIR AND XShaderCompiler_LIBRARY_DEBUG AND XShaderCompiler_LIBRARY_RELEASE)
+	set(XShaderCompiler_FOUND TRUE)
+endif()
+
+if(NOT XShaderCompiler_FOUND)
+	if(XShaderCompiler_FIND_REQUIRED)
+		message(FATAL_ERROR "Cannot find XShaderCompiler installation. Try modifying the XShaderCompiler_INSTALL_DIR path.")
+	elseif(NOT XShaderCompiler_FIND_QUIETLY)
+		message(WARNING "Cannot find XShaderCompiler installation. Try modifying the XShaderCompiler_INSTALL_DIR path.")
+	endif()
+else()
+	message(STATUS "...XShaderCompiler OK.")
+endif()
+
+if(XShaderCompiler)
+	add_library(XShaderCompiler STATIC IMPORTED)
+	set_target_properties(XShaderCompiler PROPERTIES IMPORTED_LOCATION_DEBUG "${XShaderCompiler_LIBRARY_DEBUG}")
+	set_target_properties(XShaderCompiler PROPERTIES IMPORTED_LOCATION_OPTIMIZEDDEBUG "${XShaderCompiler_LIBRARY_DEBUG}")
+	set_target_properties(XShaderCompiler PROPERTIES IMPORTED_LOCATION_RELEASE "${XShaderCompiler_LIBRARY_RELEASE}")
+endif()
+
+mark_as_advanced(
+	XShaderCompiler_INSTALL_DIR 
+	XShaderCompiler_INCLUDE_DIR 
+	XShaderCompiler_LIBRARY_RELEASE
+	XShaderCompiler_LIBRARY_DEBUG)
+
+set(XShaderCompiler_INCLUDE_DIRS ${XShaderCompiler_INCLUDE_DIR})
+set(XShaderCompiler_LIBRARIES XShaderCompiler)

+ 2 - 2
Source/CMakeLists.txt

@@ -130,8 +130,6 @@ else()
 endif()
 
 # Output
-set(CMAKE_BINARY_DIR "${PROJECT_SOURCE_DIR}/../Build/${CMAKE_GENERATOR}/")
-
 if(BS_64BIT)
 	set(BS_OUTPUT_DIR_PREFIX x64)
 else()
@@ -202,6 +200,8 @@ function(add_subdirectory_optional subdir_name)
 	endif()
 endfunction()
 
+include(CMake/FindPackageOrBuild.cmake)
+
 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
 
 # Config file

+ 1 - 0
Source/External/XShaderCompiler

@@ -0,0 +1 @@
+Subproject commit c37b3b10fa8e84e3bf435628291e4e20f7c8135b