msvc: Use source folder structure for project file.
authorRay Molenkamp <github@lazydodo.com>
Sat, 3 Feb 2018 23:38:27 +0000 (16:38 -0700)
committerRay Molenkamp <github@lazydodo.com>
Sat, 3 Feb 2018 23:38:27 +0000 (16:38 -0700)
This patch changes the huge list of projects in visual studio into a nice tree matching the source folder structure. see D2823 for details.

Differential Revision: http://developer.blender.org/D2823

14 files changed:
CMakeLists.txt
build_files/cmake/macros.cmake
build_files/cmake/platform/platform_win32.cmake
intern/cycles/CMakeLists.txt
intern/cycles/bvh/CMakeLists.txt
intern/cycles/cmake/macros.cmake [new file with mode: 0644]
intern/cycles/device/CMakeLists.txt
intern/cycles/graph/CMakeLists.txt
intern/cycles/kernel/CMakeLists.txt
intern/cycles/kernel/osl/CMakeLists.txt
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/render/CMakeLists.txt
intern/cycles/subd/CMakeLists.txt
intern/cycles/util/CMakeLists.txt

index 213b5e96f06af842c6574439d0f8f145026b30e8..5c4ce5030ac18f36a542b80962786aea8e92fd0f 100644 (file)
@@ -544,6 +544,9 @@ if(WIN32)
 
        set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
        mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
+
+       option(WINDOWS_USE_VISUAL_STUDIO_FOLDERS "Organize the visual studio project according to source folders." ON)
+       mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_FOLDERS)
 endif()
 
 # avoid using again
index 406f50eb4f40adf37d7397c7ccfa7ba5e937fa31..8ec2b1c6da56f4f048cac347fef3975a6665efba 100644 (file)
@@ -242,6 +242,13 @@ function(blender_add_lib__impl
        # listed is helpful for IDE's (QtCreator/MSVC)
        blender_source_group("${sources}")
 
+       #if enabled, set the FOLDER property for visual studio projects 
+       if(WINDOWS_USE_VISUAL_STUDIO_FOLDERS)
+               get_filename_component(FolderDir ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
+               string(REPLACE ${CMAKE_SOURCE_DIR} "" FolderDir ${FolderDir})
+               set_target_properties(${name} PROPERTIES FOLDER ${FolderDir})
+       endif()
+
        list_assert_duplicates("${sources}")
        list_assert_duplicates("${includes}")
        # Not for system includes because they can resolve to the same path
index a2fae22a96368dbf1f5fc611c248a14831fba124..ef3ef7b65170fa697182e0e68e7d49ac580ed238 100644 (file)
@@ -31,6 +31,12 @@ endif()
 
 # Libraries configuration for Windows when compiling with MSVC.
 
+set_property(GLOBAL PROPERTY USE_FOLDERS ${WINDOWS_USE_VISUAL_STUDIO_FOLDERS})
+
+if(NOT WITH_PYTHON_MODULE)
+       set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT blender)
+endif()
+
 macro(warn_hardcoded_paths package_name
        )
        if(WITH_WINDOWS_FIND_MODULES)
index 3da1170ec77fb3095f712c62407e9ddc826b8479..f720d389cbf19d3a1fb02cc58c2ff78707f4bdb1 100644 (file)
@@ -9,6 +9,7 @@ endif()
 # External Libraries
 
 include(cmake/external_libs.cmake)
+include(cmake/macros.cmake)
 
 # Build Flags
 # todo: this code could be refactored a bit to avoid duplication
index 6078db5a8caa7d04c324e800963d23afe4ebeafc..b8171e7f70dfdc5bb6ecea52764ba853e5c022c7 100644 (file)
@@ -34,4 +34,4 @@ set(SRC_HEADERS
 include_directories(${INC})
 include_directories(SYSTEM ${INC_SYS})
 
-add_library(cycles_bvh ${SRC} ${SRC_HEADERS})
+cycles_add_library(cycles_bvh ${SRC} ${SRC_HEADERS})
diff --git a/intern/cycles/cmake/macros.cmake b/intern/cycles/cmake/macros.cmake
new file mode 100644 (file)
index 0000000..f3ca06a
--- /dev/null
@@ -0,0 +1,12 @@
+function(cycles_set_solution_folder target)
+       if(WINDOWS_USE_VISUAL_STUDIO_FOLDERS)
+               get_filename_component(folderdir ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
+               string(REPLACE ${CMAKE_SOURCE_DIR} "" folderdir ${folderdir})
+               set_target_properties(${target} PROPERTIES FOLDER ${folderdir})
+       endif()
+endfunction()
+
+macro(cycles_add_library target)
+       add_library(${target} ${ARGN})
+       cycles_set_solution_folder(${target})
+endmacro()
index 959c0aa97c9ef50f2f57a92dc4ceae77a9c153fd..75e78e038eab4bbcacb00f8a60a0ea889a729085 100644 (file)
@@ -77,4 +77,4 @@ endif()
 include_directories(${INC})
 include_directories(SYSTEM ${INC_SYS})
 
-add_library(cycles_device ${SRC} ${SRC_OPENCL} ${SRC_HEADERS})
+cycles_add_library(cycles_device ${SRC} ${SRC_OPENCL} ${SRC_HEADERS})
index e70a18137bd069b9941c2556eda2ac8d936e5b3a..168ca0210e7d9dc612dc89835ca3da75444be633 100644 (file)
@@ -19,5 +19,5 @@ set(SRC_HEADERS
 include_directories(${INC})
 include_directories(SYSTEM ${INC_SYS})
 
-add_library(cycles_graph ${SRC} ${SRC_HEADERS})
+cycles_add_library(cycles_graph ${SRC} ${SRC_HEADERS})
 
index 3b76b3403e70d12bfdeff9e8c7bf634ab1758bfa..d981b67559e95853304b32185b633b16390a8cd2 100644 (file)
@@ -435,6 +435,7 @@ if(WITH_CYCLES_CUDA_BINARIES)
        endforeach()
 
        add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
+       cycles_set_solution_folder(cycles_kernel_cuda)
 endif()
 
 # OSL module
@@ -477,7 +478,7 @@ if(CXX_HAS_AVX2)
        set_source_files_properties(kernels/cpu/filter_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
 endif()
 
-add_library(cycles_kernel
+cycles_add_library(cycles_kernel
        ${SRC_CPU_KERNELS}
        ${SRC_CUDA_KERNELS}
        ${SRC_OPENCL_KERNELS}
index d2eb89e0e0abd5d7053275f6650fa623ba96d39d..159de63a044226e4493a131e534144c6608b0a2f 100644 (file)
@@ -30,5 +30,5 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RTTI_DISABLE_FLAGS}")
 include_directories(${INC})
 include_directories(SYSTEM ${INC_SYS})
 
-add_library(cycles_kernel_osl ${SRC} ${HEADER_SRC})
+cycles_add_library(cycles_kernel_osl ${SRC} ${HEADER_SRC})
 
index 5e8e98773d96d0cce603e1395f143103f339706a..19b7769200e6e8f43125cefb72325d980a73e067 100644 (file)
@@ -104,6 +104,7 @@ set(SRC_OSO
 # TODO, add a module to compile OSL
 foreach(_file ${SRC_OSL})
        set(_OSL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+       set_source_files_properties(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
        string(REPLACE ".osl" ".oso" _OSO_FILE ${_OSL_FILE})
        string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _OSO_FILE ${_OSO_FILE})
        add_custom_command(
@@ -118,7 +119,8 @@ foreach(_file ${SRC_OSL})
        unset(_OSO_FILE)
 endforeach()
 
-add_custom_target(cycles_osl_shaders ALL DEPENDS ${SRC_OSO} ${SRC_OSL_HEADERS} ${OSL_COMPILER})
+add_custom_target(cycles_osl_shaders ALL DEPENDS ${SRC_OSO} ${SRC_OSL_HEADERS} ${OSL_COMPILER} SOURCES ${SRC_OSL})
+cycles_set_solution_folder(cycles_osl_shaders)
 
 # CMAKE_CURRENT_SOURCE_DIR is already included in OSO paths
 delayed_install("" "${SRC_OSO}" ${CYCLES_INSTALL_PATH}/shader)
index 17ac66644e24f7eaf18fccf312d5293c8412d96c..580d76e7777a064a736bf9fc59f7c50d788a15dc 100644 (file)
@@ -71,4 +71,4 @@ include_directories(SYSTEM ${INC_SYS})
 
 add_definitions(${GL_DEFINITIONS})
 
-add_library(cycles_render ${SRC} ${SRC_HEADERS})
+cycles_add_library(cycles_render ${SRC} ${SRC_HEADERS})
index fe0c221ab0d0e003ef7c7069ce43c6662f9d60a8..7f952dd43cecb54b120c5bdc632cfc28f23a8ed4 100644 (file)
@@ -24,4 +24,4 @@ set(SRC_HEADERS
 include_directories(${INC})
 include_directories(SYSTEM ${INC_SYS})
 
-add_library(cycles_subd ${SRC} ${SRC_HEADERS})
+cycles_add_library(cycles_subd ${SRC} ${SRC_HEADERS})
index bc9def7ca41218c5242e7a210be70dfe9239f5e4..66c4f22a7e2fcaf5b44174a7368405307d967f8f 100644 (file)
@@ -127,4 +127,4 @@ include_directories(SYSTEM ${INC_SYS})
 
 add_definitions(${GL_DEFINITIONS})
 
-add_library(cycles_util ${SRC} ${SRC_HEADERS})
+cycles_add_library(cycles_util ${SRC} ${SRC_HEADERS})