CMake: split out SwiftShader GL deps into separate files
This change add a CMakeLists in each of the following folders, and
creates the following targets:
src/Common -> gl_common
src/Main -> gl_main
src/Renderer -> gl_renderer
src/Shader -> gl_shader
Bug: b/145758253
Change-Id: Ia1f68d0689f80955586235e125e0197da25d692d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43550
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f27475..6ace7a7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -647,32 +647,6 @@
# File Lists
###########################################################
-file(GLOB_RECURSE SWIFTSHADER_LIST
- ${SOURCE_DIR}/Common/*.cpp
- ${SOURCE_DIR}/Common/*.h
- ${SOURCE_DIR}/Common/*.hpp
- ${SOURCE_DIR}/Renderer/*.cpp
- ${SOURCE_DIR}/Renderer/*.h
- ${SOURCE_DIR}/Renderer/*.hpp
- ${SOURCE_DIR}/Shader/*.cpp
- ${SOURCE_DIR}/Shader/*.h
- ${SOURCE_DIR}/Shader/*.hpp
-)
-list(APPEND SWIFTSHADER_LIST
- ${SOURCE_DIR}/Main/Config.cpp
- ${SOURCE_DIR}/Main/Config.hpp
- ${SOURCE_DIR}/Main/FrameBuffer.cpp
- ${SOURCE_DIR}/Main/FrameBuffer.hpp
- ${SOURCE_DIR}/Main/SwiftConfig.cpp
- ${SOURCE_DIR}/Main/SwiftConfig.hpp
-)
-list(REMOVE_ITEM SWIFTSHADER_LIST
- ${SOURCE_DIR}/Common/DebugAndroid.cpp
- ${SOURCE_DIR}/Common/DebugAndroid.hpp
- ${SOURCE_DIR}/Common/GrallocAndroid.cpp
- ${SOURCE_DIR}/Common/GrallocAndroid.hpp
-)
-
file(GLOB_RECURSE EGL_LIST
${OPENGL_DIR}/libEGL/*.cpp
${OPENGL_DIR}/libEGL/*.h
@@ -775,14 +749,6 @@
###########################################################
if(WIN32)
- list(APPEND SWIFTSHADER_LIST
- ${SOURCE_DIR}/Main/FrameBufferDD.cpp
- ${SOURCE_DIR}/Main/FrameBufferDD.hpp
- ${SOURCE_DIR}/Main/FrameBufferGDI.cpp
- ${SOURCE_DIR}/Main/FrameBufferGDI.hpp
- ${SOURCE_DIR}/Main/FrameBufferWin.cpp
- ${SOURCE_DIR}/Main/FrameBufferWin.hpp
- )
list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp)
list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc)
list(APPEND GLES2_LIST ${OPENGL_DIR}/libGLESv2/libGLESv2.rc)
@@ -793,12 +759,6 @@
${SOURCE_DIR}/WSI/Win32SurfaceKHR.hpp
)
elseif(LINUX)
- list(APPEND SWIFTSHADER_LIST
- ${SOURCE_DIR}/Main/FrameBufferX11.cpp
- ${SOURCE_DIR}/Main/FrameBufferX11.hpp
- ${SOURCE_DIR}/Main/libX11.cpp
- ${SOURCE_DIR}/Main/libX11.hpp
- )
list(APPEND OPENGL_COMPILER_LIST
${OPENGL_COMPILER_DIR}/ossource_posix.cpp
)
@@ -820,10 +780,6 @@
endif()
elseif(APPLE)
- list(APPEND SWIFTSHADER_LIST
- ${SOURCE_DIR}/Main/FrameBufferOSX.mm
- ${SOURCE_DIR}/Main/FrameBufferOSX.hpp
- )
list(APPEND EGL_LIST
${OPENGL_DIR}/libEGL/OSXUtils.mm
${OPENGL_DIR}/libEGL/OSXUtils.hpp
@@ -837,10 +793,6 @@
${SOURCE_DIR}/WSI/MetalSurface.h
)
elseif(ANDROID)
- list(APPEND SWIFTSHADER_LIST
- ${SOURCE_DIR}/Main/FrameBufferAndroid.cpp
- ${SOURCE_DIR}/Main/FrameBufferAndroid.hpp
- )
list(APPEND OPENGL_COMPILER_LIST
${OPENGL_COMPILER_DIR}/ossource_posix.cpp
)
@@ -863,17 +815,6 @@
# SwiftShader Targets
###########################################################
-add_library(SwiftShader STATIC EXCLUDE_FROM_ALL ${SWIFTSHADER_LIST})
-set_target_properties(SwiftShader PROPERTIES
- INCLUDE_DIRECTORIES "${COMMON_INCLUDE_DIR}"
- POSITION_INDEPENDENT_CODE 1
- FOLDER "Core"
- COMPILE_OPTIONS "${SWIFTSHADER_COMPILE_OPTIONS};${WARNINGS_AS_ERRORS}"
- COMPILE_DEFINITIONS "NO_SANITIZE_FUNCTION=;"
- LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
-)
-target_link_libraries(SwiftShader ${OS_LIBS} ${SWIFTSHADER_LIBS})
-
add_subdirectory(src/Reactor) # Add ReactorSubzero and ReactorLLVM targets
if(${REACTOR_BACKEND} STREQUAL "LLVM")
@@ -884,6 +825,21 @@
message(FATAL_ERROR "REACTOR_BACKEND must be 'LLVM' or 'Subzero'")
endif()
+
+add_subdirectory(src/Common) # Add gl_common target
+add_subdirectory(src/Main) # Add gl_main target
+add_subdirectory(src/Shader) # Add gl_shader target
+add_subdirectory(src/Renderer) # Add gl_renderer target
+
+# Combine all gl_* targets into an interface target
+# along with other dependencies
+add_library(gl_swiftshader_core INTERFACE)
+target_link_libraries(gl_swiftshader_core INTERFACE
+ # Transitively depends on shader, main, core, Reactor,
+ # OS_LIBS and SWIFTSHADER_LIBS
+ gl_renderer
+)
+
add_library(GLCompiler STATIC EXCLUDE_FROM_ALL ${OPENGL_COMPILER_LIST})
set_target_properties(GLCompiler PROPERTIES
INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
@@ -919,7 +875,7 @@
set_target_properties(libEGL PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libEGL ${SOURCE_DIR}/OpenGL/libEGL)
- target_link_libraries(libEGL SwiftShader ${OS_LIBS} ${SWIFTSHADER_LIBS})
+ target_link_libraries(libEGL gl_swiftshader_core ${OS_LIBS} ${SWIFTSHADER_LIBS})
add_custom_command(
TARGET libEGL
POST_BUILD
@@ -944,7 +900,7 @@
set_target_properties(libGLESv2 PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libGLESv2 ${SOURCE_DIR}/OpenGL/libGLESv2)
- target_link_libraries(libGLESv2 SwiftShader ${Reactor} GLCompiler ${OS_LIBS} ${SWIFTSHADER_LIBS})
+ target_link_libraries(libGLESv2 gl_swiftshader_core ${Reactor} GLCompiler ${OS_LIBS} ${SWIFTSHADER_LIBS})
add_custom_command(
TARGET libGLESv2
POST_BUILD
@@ -969,7 +925,7 @@
set_target_properties(libGLES_CM PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libGLES_CM ${SOURCE_DIR}/OpenGL/libGLES_CM)
- target_link_libraries(libGLES_CM SwiftShader ${Reactor} GLCompiler ${OS_LIBS} ${SWIFTSHADER_LIBS})
+ target_link_libraries(libGLES_CM gl_swiftshader_core ${Reactor} GLCompiler ${OS_LIBS} ${SWIFTSHADER_LIBS})
add_custom_command(
TARGET libGLES_CM
POST_BUILD
diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt
new file mode 100644
index 0000000..fc7d1a5
--- /dev/null
+++ b/src/Common/CMakeLists.txt
@@ -0,0 +1,86 @@
+# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(ROOT_PROJECT_COMPILE_OPTIONS
+ ${SWIFTSHADER_COMPILE_OPTIONS}
+ ${WARNINGS_AS_ERRORS}
+)
+
+set(ROOT_PROJECT_LINK_LIBRARIES
+ ${OS_LIBS}
+ ${SWIFTSHADER_LIBS}
+)
+
+set(COMMON_SRC_FILES
+ Configurator.cpp
+ CPUID.cpp
+ Debug.cpp
+ # DebugAndroid.cpp
+ # GrallocAndroid.cpp
+ Half.cpp
+ Math.cpp
+ Memory.cpp
+ Resource.cpp
+ SharedLibrary.cpp
+ Socket.cpp
+ Thread.cpp
+ Timer.cpp
+ Version.h
+ Configurator.hpp
+ CPUID.hpp
+ Debug.hpp
+ # DebugAndroid.hpp
+ # GrallocAndroid.hpp
+ Half.hpp
+ Math.hpp
+ Memory.hpp
+ MutexLock.hpp
+ RecursiveLock.hpp
+ Resource.hpp
+ SharedLibrary.hpp
+ Socket.hpp
+ Thread.hpp
+ Timer.hpp
+ Types.hpp
+)
+
+add_library(gl_common EXCLUDE_FROM_ALL
+ ${COMMON_SRC_FILES}
+)
+
+set_target_properties(gl_common PROPERTIES
+ POSITION_INDEPENDENT_CODE 1
+ FOLDER "SwiftShader GL"
+ LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
+)
+
+target_include_directories(gl_common
+ PUBLIC
+ ".."
+)
+
+target_compile_definitions(gl_common
+ PRIVATE
+ "NO_SANITIZE_FUNCTION="
+)
+
+target_compile_options(gl_common
+ PUBLIC
+ ${ROOT_PROJECT_COMPILE_OPTIONS}
+)
+
+target_link_libraries(gl_common
+ PUBLIC
+ ${ROOT_PROJECT_LINK_LIBRARIES}
+)
diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt
new file mode 100644
index 0000000..34731fd
--- /dev/null
+++ b/src/Main/CMakeLists.txt
@@ -0,0 +1,88 @@
+# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(ROOT_PROJECT_COMPILE_OPTIONS
+ ${SWIFTSHADER_COMPILE_OPTIONS}
+ ${WARNINGS_AS_ERRORS}
+)
+
+set(MAIN_SRC_FILES
+ Config.cpp
+ Config.hpp
+ FrameBuffer.cpp
+ FrameBuffer.hpp
+ SwiftConfig.cpp
+ SwiftConfig.hpp
+)
+
+if(WIN32)
+ list(APPEND MAIN_SRC_FILES
+ FrameBufferDD.cpp
+ FrameBufferDD.hpp
+ FrameBufferGDI.cpp
+ FrameBufferGDI.hpp
+ FrameBufferWin.cpp
+ FrameBufferWin.hpp
+ )
+elseif(LINUX)
+ list(APPEND MAIN_SRC_FILES
+ FrameBufferX11.cpp
+ FrameBufferX11.hpp
+ libX11.cpp
+ libX11.hpp
+ )
+elseif(APPLE)
+ list(APPEND MAIN_SRC_FILES
+ FrameBufferOSX.mm
+ FrameBufferOSX.hpp
+ )
+elseif(ANDROID)
+ list(APPEND MAIN_SRC_FILES
+ FrameBufferAndroid.cpp
+ FrameBufferAndroid.hpp
+ )
+endif()
+
+add_library(gl_main EXCLUDE_FROM_ALL
+ ${MAIN_SRC_FILES}
+)
+
+set_target_properties(gl_main PROPERTIES
+ POSITION_INDEPENDENT_CODE 1
+ FOLDER "SwiftShader GL"
+ LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
+)
+
+target_include_directories(gl_main
+ PUBLIC
+ ".."
+ PRIVATE
+ ${CMAKE_SOURCE_DIR}/include # For EGL
+)
+
+target_compile_definitions(gl_main
+ PRIVATE
+ "NO_SANITIZE_FUNCTION="
+)
+
+target_compile_options(gl_main
+ PUBLIC
+ ${ROOT_PROJECT_COMPILE_OPTIONS}
+)
+
+target_link_libraries(gl_main
+ PUBLIC
+ gl_common
+ ${Reactor}
+)
diff --git a/src/Renderer/CMakeLists.txt b/src/Renderer/CMakeLists.txt
new file mode 100644
index 0000000..b3e166f
--- /dev/null
+++ b/src/Renderer/CMakeLists.txt
@@ -0,0 +1,93 @@
+# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(ROOT_PROJECT_COMPILE_OPTIONS
+ ${SWIFTSHADER_COMPILE_OPTIONS}
+ ${WARNINGS_AS_ERRORS}
+)
+
+set(RENDERER_SRC_FILES
+ Blitter.cpp
+ Clipper.cpp
+ Color.cpp
+ Context.cpp
+ ETC_Decoder.cpp
+ Matrix.cpp
+ PixelProcessor.cpp
+ Plane.cpp
+ Point.cpp
+ QuadRasterizer.cpp
+ Renderer.cpp
+ Sampler.cpp
+ SetupProcessor.cpp
+ Surface.cpp
+ TextureStage.cpp
+ Vector.cpp
+ VertexProcessor.cpp
+ Blitter.hpp
+ Clipper.hpp
+ Color.hpp
+ Context.hpp
+ ETC_Decoder.hpp
+ LRUCache.hpp
+ Matrix.hpp
+ PixelProcessor.hpp
+ Plane.hpp
+ Point.hpp
+ Polygon.hpp
+ Primitive.hpp
+ QuadRasterizer.hpp
+ Rasterizer.hpp
+ Renderer.hpp
+ RoutineCache.hpp
+ Sampler.hpp
+ SetupProcessor.hpp
+ Stream.hpp
+ Surface.hpp
+ TextureStage.hpp
+ Triangle.hpp
+ Vector.hpp
+ Vertex.hpp
+ VertexProcessor.hpp
+)
+
+add_library(gl_renderer EXCLUDE_FROM_ALL
+ ${RENDERER_SRC_FILES}
+)
+
+set_target_properties(gl_renderer PROPERTIES
+ POSITION_INDEPENDENT_CODE 1
+ FOLDER "SwiftShader GL"
+ LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
+)
+
+target_include_directories(gl_renderer
+ PUBLIC
+ ".."
+)
+
+target_compile_definitions(gl_renderer
+ PRIVATE
+ "NO_SANITIZE_FUNCTION="
+)
+
+target_compile_options(gl_renderer
+ PUBLIC
+ ${ROOT_PROJECT_COMPILE_OPTIONS}
+)
+
+target_link_libraries(gl_renderer
+ PUBLIC
+ gl_shader
+)
diff --git a/src/Shader/CMakeLists.txt b/src/Shader/CMakeLists.txt
new file mode 100644
index 0000000..5d3242d
--- /dev/null
+++ b/src/Shader/CMakeLists.txt
@@ -0,0 +1,77 @@
+# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(ROOT_PROJECT_COMPILE_OPTIONS
+ ${SWIFTSHADER_COMPILE_OPTIONS}
+ ${WARNINGS_AS_ERRORS}
+)
+
+set(SHADER_SRC_FILES
+ Constants.cpp
+ PixelPipeline.cpp
+ PixelProgram.cpp
+ PixelRoutine.cpp
+ PixelShader.cpp
+ SamplerCore.cpp
+ SetupRoutine.cpp
+ Shader.cpp
+ ShaderCore.cpp
+ VertexPipeline.cpp
+ VertexProgram.cpp
+ VertexRoutine.cpp
+ VertexShader.cpp
+ Constants.hpp
+ PixelPipeline.hpp
+ PixelProgram.hpp
+ PixelRoutine.hpp
+ PixelShader.hpp
+ SamplerCore.hpp
+ SetupRoutine.hpp
+ Shader.hpp
+ ShaderCore.hpp
+ VertexPipeline.hpp
+ VertexProgram.hpp
+ VertexRoutine.hpp
+ VertexShader.hpp
+)
+
+add_library(gl_shader EXCLUDE_FROM_ALL
+ ${SHADER_SRC_FILES}
+)
+
+set_target_properties(gl_shader PROPERTIES
+ POSITION_INDEPENDENT_CODE 1
+ FOLDER "SwiftShader GL"
+ LINK_FLAGS "${SWIFTSHADER_LINK_FLAGS}"
+)
+
+target_include_directories(gl_shader
+ PUBLIC
+ ".."
+)
+
+target_compile_definitions(gl_shader
+ PRIVATE
+ "NO_SANITIZE_FUNCTION="
+)
+
+target_compile_options(gl_shader
+ PUBLIC
+ ${ROOT_PROJECT_COMPILE_OPTIONS}
+)
+
+target_link_libraries(gl_shader
+ PUBLIC
+ gl_main
+)