From 36c1122b96ca550a541f9cea9ed2673319c7467b Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Sat, 3 Feb 2018 16:38:27 -0700 Subject: msvc: Use source folder structure for project file. 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 --- CMakeLists.txt | 3 +++ build_files/cmake/macros.cmake | 7 +++++++ build_files/cmake/platform/platform_win32.cmake | 6 ++++++ intern/cycles/CMakeLists.txt | 1 + intern/cycles/bvh/CMakeLists.txt | 2 +- intern/cycles/cmake/macros.cmake | 12 ++++++++++++ intern/cycles/device/CMakeLists.txt | 2 +- intern/cycles/graph/CMakeLists.txt | 2 +- intern/cycles/kernel/CMakeLists.txt | 3 ++- intern/cycles/kernel/osl/CMakeLists.txt | 2 +- intern/cycles/kernel/shaders/CMakeLists.txt | 4 +++- intern/cycles/render/CMakeLists.txt | 2 +- intern/cycles/subd/CMakeLists.txt | 2 +- intern/cycles/util/CMakeLists.txt | 2 +- 14 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 intern/cycles/cmake/macros.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 213b5e96f06..5c4ce5030ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 406f50eb4f4..8ec2b1c6da5 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -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 diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index a2fae22a963..ef3ef7b6517 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -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) diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 3da1170ec77..f720d389cbf 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -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 diff --git a/intern/cycles/bvh/CMakeLists.txt b/intern/cycles/bvh/CMakeLists.txt index 6078db5a8ca..b8171e7f70d 100644 --- a/intern/cycles/bvh/CMakeLists.txt +++ b/intern/cycles/bvh/CMakeLists.txt @@ -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 index 00000000000..f3ca06ac6b8 --- /dev/null +++ b/intern/cycles/cmake/macros.cmake @@ -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() diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 959c0aa97c9..75e78e038ea 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -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}) diff --git a/intern/cycles/graph/CMakeLists.txt b/intern/cycles/graph/CMakeLists.txt index e70a18137bd..168ca0210e7 100644 --- a/intern/cycles/graph/CMakeLists.txt +++ b/intern/cycles/graph/CMakeLists.txt @@ -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}) diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 3b76b3403e7..d981b67559e 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -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} diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt index d2eb89e0e0a..159de63a044 100644 --- a/intern/cycles/kernel/osl/CMakeLists.txt +++ b/intern/cycles/kernel/osl/CMakeLists.txt @@ -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}) diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt index 5e8e98773d9..19b7769200e 100644 --- a/intern/cycles/kernel/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/shaders/CMakeLists.txt @@ -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) diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt index 17ac66644e2..580d76e7777 100644 --- a/intern/cycles/render/CMakeLists.txt +++ b/intern/cycles/render/CMakeLists.txt @@ -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}) diff --git a/intern/cycles/subd/CMakeLists.txt b/intern/cycles/subd/CMakeLists.txt index fe0c221ab0d..7f952dd43ce 100644 --- a/intern/cycles/subd/CMakeLists.txt +++ b/intern/cycles/subd/CMakeLists.txt @@ -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}) diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt index bc9def7ca41..66c4f22a7e2 100644 --- a/intern/cycles/util/CMakeLists.txt +++ b/intern/cycles/util/CMakeLists.txt @@ -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}) -- cgit v1.2.3