Browse Source

Integrating script binding generator into the build process (WIP)

BearishSun 8 years ago
parent
commit
50129a3a5b

+ 0 - 2
Source/BansheeCore/CMakeLists.txt

@@ -12,11 +12,9 @@ if(WIN32)
 endif()
 endif()
 
 
 include_directories(${BansheeCore_INC})	
 include_directories(${BansheeCore_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeCore/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
 add_library(BansheeCore SHARED ${BS_BANSHEECORE_SRC})
 add_library(BansheeCore SHARED ${BS_BANSHEECORE_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_BANSHEECORE_SRC} PARENT_SCOPE)
 
 
 # Defines
 # Defines
 target_compile_definitions(BansheeCore PRIVATE -DBS_CORE_EXPORTS)
 target_compile_definitions(BansheeCore PRIVATE -DBS_CORE_EXPORTS)

+ 0 - 2
Source/BansheeEditor/CMakeLists.txt

@@ -9,11 +9,9 @@ set(BansheeEditor_INC
 	"../BansheeEngine/Include")
 	"../BansheeEngine/Include")
 
 
 include_directories(${BansheeEditor_INC})	
 include_directories(${BansheeEditor_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeEditor/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
 add_library(BansheeEditor SHARED ${BS_BANSHEEEDITOR_SRC})
 add_library(BansheeEditor SHARED ${BS_BANSHEEEDITOR_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_BANSHEEEDITOR_SRC} PARENT_SCOPE)
 
 
 # Defines
 # Defines
 target_compile_definitions(BansheeEditor PRIVATE -DBS_ED_EXPORTS)
 target_compile_definitions(BansheeEditor PRIVATE -DBS_ED_EXPORTS)

+ 0 - 2
Source/BansheeEngine/CMakeLists.txt

@@ -8,11 +8,9 @@ set(BansheeEngine_INC
 	"../BansheeCore/Include")
 	"../BansheeCore/Include")
 
 
 include_directories(${BansheeEngine_INC})	
 include_directories(${BansheeEngine_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeEngine/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
 add_library(BansheeEngine SHARED ${BS_BANSHEEENGINE_SRC})
 add_library(BansheeEngine SHARED ${BS_BANSHEEENGINE_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_BANSHEEENGINE_SRC} PARENT_SCOPE)
 
 
 # Defines
 # Defines
 target_compile_definitions(BansheeEngine PRIVATE 
 target_compile_definitions(BansheeEngine PRIVATE 

+ 0 - 1
Source/BansheeMono/CMakeLists.txt

@@ -10,7 +10,6 @@ set(BansheeMono_INC
 	"../../Dependencies/Mono/include")
 	"../../Dependencies/Mono/include")
 
 
 include_directories(${BansheeMono_INC})	
 include_directories(${BansheeMono_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeMono/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
 add_library(BansheeMono SHARED ${BS_BANSHEEMONO_SRC})
 add_library(BansheeMono SHARED ${BS_BANSHEEMONO_SRC})

+ 0 - 2
Source/BansheeUtility/CMakeLists.txt

@@ -13,11 +13,9 @@ else()
 endif()
 endif()
 
 
 include_directories(${BansheeUtility_INC})	
 include_directories(${BansheeUtility_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeUtility/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
 add_library(BansheeUtility SHARED ${BS_BANSHEEUTILITY_SRC})
 add_library(BansheeUtility SHARED ${BS_BANSHEEUTILITY_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_BANSHEEUTILITY_SRC} PARENT_SCOPE)
 
 
 add_executable(BansheeUtilityTest Source/BsUtilityTest.cpp)
 add_executable(BansheeUtilityTest Source/BsUtilityTest.cpp)
 target_link_libraries(BansheeUtilityTest BansheeUtility)
 target_link_libraries(BansheeUtilityTest BansheeUtility)

+ 5 - 5
Source/BansheeUtility/Include/BsGlobalFrameAlloc.h

@@ -18,34 +18,34 @@ namespace bs
 	 *
 	 *
 	 * @note	Thread safe.
 	 * @note	Thread safe.
 	 */
 	 */
-	inline BS_UTILITY_EXPORT FrameAlloc& gFrameAlloc();
+	BS_UTILITY_EXPORT FrameAlloc& gFrameAlloc();
 
 
 	/**
 	/**
 	 * Allocates some memory using the global frame allocator.
 	 * Allocates some memory using the global frame allocator.
 	 *
 	 *
 	 * @param[in]	numBytes	Number of bytes to allocate.
 	 * @param[in]	numBytes	Number of bytes to allocate.
 	 */
 	 */
-	inline BS_UTILITY_EXPORT UINT8* bs_frame_alloc(UINT32 numBytes);
+	BS_UTILITY_EXPORT UINT8* bs_frame_alloc(UINT32 numBytes);
 
 
 	/** 
 	/** 
 	 * Allocates the specified number of bytes aligned to the provided boundary, using the global frame allocator. Boundary
 	 * Allocates the specified number of bytes aligned to the provided boundary, using the global frame allocator. Boundary
 	 * is in bytes and must be a power of two.
 	 * is in bytes and must be a power of two.
 	 */
 	 */
-	inline BS_UTILITY_EXPORT UINT8* bs_frame_alloc_aligned(UINT32 count, UINT32 align);
+	BS_UTILITY_EXPORT UINT8* bs_frame_alloc_aligned(UINT32 count, UINT32 align);
 
 
 	/**
 	/**
 	 * Deallocates memory allocated with the global frame allocator.
 	 * Deallocates memory allocated with the global frame allocator.
 	 *
 	 *
 	 * @note	Must be called on the same thread the memory was allocated on.
 	 * @note	Must be called on the same thread the memory was allocated on.
 	 */
 	 */
-	inline BS_UTILITY_EXPORT void bs_frame_free(void* data);
+	BS_UTILITY_EXPORT void bs_frame_free(void* data);
 
 
 	/** 
 	/** 
 	 * Frees memory previously allocated with bs_frame_alloc_aligned(). 
 	 * Frees memory previously allocated with bs_frame_alloc_aligned(). 
 	 *
 	 *
 	 * @note	Must be called on the same thread the memory was allocated on.
 	 * @note	Must be called on the same thread the memory was allocated on.
 	 */
 	 */
-	inline BS_UTILITY_EXPORT void bs_frame_free_aligned(void* data);
+	BS_UTILITY_EXPORT void bs_frame_free_aligned(void* data);
 
 
 	/**
 	/**
 	 * Allocates enough memory to hold the object of specified type using the global frame allocator, but does not 
 	 * Allocates enough memory to hold the object of specified type using the global frame allocator, but does not 

+ 40 - 0
Source/BansheeUtility/Include/BsPrerequisitesUtil.h

@@ -209,6 +209,46 @@
 #define BS_ASSERT(x)
 #define BS_ASSERT(x)
 #endif
 #endif
 
 
+// Script binding defines
+
+/** 
+ * @page scriptBindingMacro Script binding exports
+ * 
+ * Marks the specific type or a method to be exported to the scripting API. Supports a variety of options which can
+ * be specified in the "option:value" format, where multiple options are separated by commas, with no whitespace.
+ *
+ * Supported options:
+ *  - n - Specify a different name for the type in the scripting API (e.g. "n:MyName"). Usable on types and methods.
+ *  - v - Specify a different visibility (default is public). Supported values are "public" and "internal". Usable on types
+ *		  and methods.
+ *  - f - Specify the name of the output file(s) for the script object and its potential wrappers. If not specified
+ *		  the name of the type will be used for the file. Usable on types only.
+ *	- pl - Specify whether the type is plain or not (default is false). Supported values are "true" or "false". Plain 
+ *		  types don't have script interop objects generated, instead their are generated in script code as plain data
+ *		  types. No methods are exposed, but all data members and constructors are copied. Usable on types only.
+ *	- e - Specify that a method is external and is to be appended to some script class. Such methods must be static
+ *		  and as the first parameter accept the instance of the class they operate on. Value of this option should be
+ *		  the name of the class to attach this method to. Methods with this parameter must also be part of a class
+ *		  with this option. Usable on types and methods.
+ *	- ec - Similar to "e", but specifies an external constructor. Such method must have a return value that returns
+ *		   an instance of the class its registered for. Value of this option should be the name of the class to attach
+ *		   this method to. Methods with this parameter must also be part of a class with the "e" option. Usable on methods
+ *		   only.
+ *	- pr - Specify the method should be exported as a property in script code. Supported values are "getter" or "setter".
+ *		  Getter methods must return a single value and accept no parameters, while setter methods must accept one
+ *		  parameter and return no values. Usable on methods only.
+ *	- ed - Specify that a type should be exported for use in the editor only. Supported values are "true" or "false".
+ *		   Usable on types only.
+ */
+
+#if BS_COMPILER == BS_COMPILER_CLANG
+	/** @copydoc scriptBindingMacro */
+	#define BS_SCRIPT_EXPORT(...) __attribute__((annotate("se," #__VA_ARGS__)))
+#else
+	/** @copydoc scriptBindingMacro */
+	#define BS_SCRIPT_EXPORT(...) 
+#endif
+
 // Short-hand names for various built-in types
 // Short-hand names for various built-in types
 #include "BsTypes.h"
 #include "BsTypes.h"
 
 

+ 74 - 0
Source/CMake/GenerateScriptBindings.cmake

@@ -0,0 +1,74 @@
+# Outputs:
+#   BS_GENERATED_ENGINE_H_FILES
+#   BS_GENERATED_ENGINE_CPP_FILES
+#   BS_GENERATED_EDITOR_H_FILES
+#   BS_GENERATED_EDITOR_CPP_FILES
+#   BS_GENERATED_ENGINE_CS_FILES
+#   BS_GENERATED_EDITOR_CS_FILES
+
+set(BS_SCRIPT_PARSER_INCLUDE_DIRS "")
+set(BS_SCRIPT_PARSER_SOURCE_FILES "")
+
+function(prepend var prefix)
+   SET(listVar "")
+   FOREACH(f ${ARGN})
+      LIST(APPEND listVar "${prefix}/${f}")
+   ENDFOREACH(f)
+   SET(${var} "${listVar}" PARENT_SCOPE)
+endfunction()
+
+function(addForGeneration name)
+	set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "${name}/Include" PARENT_SCOPE)
+	
+	include(${name}/CMakeSources.cmake)
+	string(TOUPPER ${name} LIBNAME)
+
+	set(CPP_FILES "")
+	FOREACH(f ${BS_${LIBNAME}_SRC})
+		IF("${f}" MATCHES ".*\.cpp")
+			LIST(APPEND CPP_FILES ${f})
+		ENDIF()
+	ENDFOREACH(f)
+	
+	set(ABS_SOURCE_FILES "")
+	prepend(ABS_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${name} ${CPP_FILES})
+	set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${ABS_SOURCE_FILES} PARENT_SCOPE)	
+endfunction()
+
+addForGeneration(BansheeUtility)
+addForGeneration(BansheeCore)
+addForGeneration(BansheeEngine)
+addForGeneration(BansheeEditor)
+addForGeneration(SBansheeEngine)
+addForGeneration(SBansheeEditor)
+
+set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeMono/Include")
+
+list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_INCLUDE_DIRS)
+list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_SOURCE_FILES)
+
+set(BS_GENERATED_FILES_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Generated)
+prepend(BS_INCLUDE_DIRS "-I${PROJECT_SOURCE_DIR}" ${BS_SCRIPT_PARSER_INCLUDE_DIRS})
+
+#execute_process(
+#    COMMAND ${PROJECT_SOURCE_DIR}/../Dependencies/tools/SBGen 
+#		${BS_SCRIPT_PARSER_SOURCE_FILES}
+#		-output ${BS_GENERATED_FILES_OUTPUT_DIR}
+#		-- ${BS_INCLUDE_DIRS}
+#		-DBS_STATIC_LIB
+#	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+#    RESULT_VARIABLE SBGEN_RETURN_VALUE
+#)
+
+#if (NOT SBGEN_RETURN_VALUE EQUAL 0)
+#    message(FATAL_ERROR "Failed to generate script bindings.")
+#endif()
+
+file(GLOB BS_GENERATED_ENGINE_H_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Engine/Include)
+file(GLOB BS_GENERATED_ENGINE_CPP_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Engine/Source)
+
+file(GLOB BS_GENERATED_EDITOR_H_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Editor/Include)
+file(GLOB BS_GENERATED_EDITOR_CPP_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Editor/Source)
+
+file(GLOB BS_GENERATED_ENGINE_CS_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cs/Engine)
+file(GLOB BS_GENERATED_EDITOR_CS_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cs/Editor)

+ 2 - 5
Source/CMakeLists.txt

@@ -195,8 +195,8 @@ endfunction()
 
 
 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
 
 
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS "")
-set(BS_SCRIPT_PARSER_SOURCE_FILES "")
+# Code generation for script bindings
+include(CMake/GenerateScriptBindings.cmake)
 
 
 # Sub-directories
 # Sub-directories
 ## Layers
 ## Layers
@@ -275,9 +275,6 @@ else()
 # TODO - Use Mono compiler to build the managed code as a pre-build step
 # TODO - Use Mono compiler to build the managed code as a pre-build step
 endif()
 endif()
 
 
-list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_INCLUDE_DIRS)
-list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_SOURCE_FILES)
-
 # Config file
 # Config file
 ## Set names of libraries used in the config file
 ## Set names of libraries used in the config file
 if(RENDER_API_MODULE MATCHES "DirectX 11")
 if(RENDER_API_MODULE MATCHES "DirectX 11")

+ 6 - 4
Source/SBansheeEditor/CMakeLists.txt

@@ -9,14 +9,16 @@ set(SBansheeEditor_INC
 	"../BansheeEngine/Include"
 	"../BansheeEngine/Include"
 	"../BansheeEditor/Include"
 	"../BansheeEditor/Include"
 	"../BansheeMono/Include"
 	"../BansheeMono/Include"
-	"../SBansheeEngine/Include")
+	"../SBansheeEngine/Include"
+	"${PROJECT_BINARY_DIR}/Generated/Cpp/Editor/Include")
 
 
 include_directories(${SBansheeEditor_INC})	
 include_directories(${SBansheeEditor_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "SBansheeEditor/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
-add_library(SBansheeEditor SHARED ${BS_SBANSHEEEDITOR_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_SBANSHEEEDITOR_SRC} PARENT_SCOPE)
+add_library(SBansheeEditor SHARED 
+	${BS_SBANSHEEEDITOR_SRC} 
+	${BS_GENERATED_EDITOR_H_FILES} 
+	${BS_GENERATED_EDITOR_CPP_FILES})
 
 
 # Defines
 # Defines
 target_compile_definitions(SBansheeEditor PRIVATE -DBS_SCR_BED_EXPORTS)
 target_compile_definitions(SBansheeEditor PRIVATE -DBS_SCR_BED_EXPORTS)

+ 6 - 4
Source/SBansheeEngine/CMakeLists.txt

@@ -8,14 +8,16 @@ set(SBansheeEngine_INC
 	"../BansheeCore/Include"
 	"../BansheeCore/Include"
 	"../BansheeEngine/Include"
 	"../BansheeEngine/Include"
 	"../BansheeEditor/Include"
 	"../BansheeEditor/Include"
-	"../BansheeMono/Include")
+	"../BansheeMono/Include"
+	"${PROJECT_BINARY_DIR}/Generated/Cpp/Engine/Include")
 
 
 include_directories(${SBansheeEngine_INC})	
 include_directories(${SBansheeEngine_INC})	
-set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "SBansheeEngine/Include" PARENT_SCOPE)
 
 
 # Target
 # Target
-add_library(SBansheeEngine SHARED ${BS_SBANSHEEENGINE_SRC})
-set(BS_SCRIPT_PARSER_SOURCE_FILES ${BS_SCRIPT_PARSER_SOURCE_FILES} ${BS_SBANSHEEENGINE_SRC} PARENT_SCOPE)
+add_library(SBansheeEngine SHARED 
+	${BS_SBANSHEEENGINE_SRC}
+	${BS_GENERATED_ENGINE_H_FILES} 
+	${BS_GENERATED_ENGINE_CPP_FILES})
 
 
 # Defines
 # Defines
 target_compile_definitions(SBansheeEngine PRIVATE -DBS_SCR_BE_EXPORTS)
 target_compile_definitions(SBansheeEngine PRIVATE -DBS_SCR_BE_EXPORTS)