Skip to content

[llvm] Revise IDE folder structure #89741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ configure_file(
add_custom_target(srpm
COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES
COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE})
set_target_properties(srpm PROPERTIES FOLDER "Misc")
set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc")

if(APPLE AND DARWIN_LTO_LIBRARY)
set(CMAKE_EXE_LINKER_FLAGS
Expand Down Expand Up @@ -1227,7 +1227,9 @@ if( LLVM_INCLUDE_UTILS )
add_subdirectory(utils/split-file)
add_subdirectory(utils/mlgo-utils)
if( LLVM_INCLUDE_TESTS )
set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
set(LLVM_SUBPROJECT_TITLE)
endif()
else()
if ( LLVM_INCLUDE_TESTS )
Expand Down Expand Up @@ -1291,7 +1293,7 @@ if( LLVM_INCLUDE_TESTS )
if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS)
add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS})
endif()
set_target_properties(test-depends PROPERTIES FOLDER "Tests")
set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests")
add_dependencies(check-all test-depends)
endif()

Expand Down Expand Up @@ -1348,7 +1350,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
# Installing the headers needs to depend on generating any public
# tablegen'd headers.
add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen)
set_target_properties(llvm-headers PROPERTIES FOLDER "Misc")
set_target_properties(llvm-headers PROPERTIES FOLDER "LLVM/Resources")

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-llvm-headers
Expand All @@ -1358,7 +1360,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)

# Custom target to install all libraries.
add_custom_target(llvm-libraries)
set_target_properties(llvm-libraries PROPERTIES FOLDER "Misc")
set_target_properties(llvm-libraries PROPERTIES FOLDER "LLVM/Resources")

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-llvm-libraries
Expand Down Expand Up @@ -1404,6 +1406,8 @@ if (LLVM_INCLUDE_BENCHMARKS)
set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark
${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
set_target_properties(benchmark PROPERTIES FOLDER "Third-Party/Google Benchmark")
set_target_properties(benchmark_main PROPERTIES FOLDER "Third-Party/Google Benchmark")
add_subdirectory(benchmarks)
endif()

Expand Down
83 changes: 62 additions & 21 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ include(LLVMProcessSources)
include(LLVM-Config)
include(DetermineGCCCompatible)

# get_subproject_title(titlevar)
# Set ${outvar} to the title of the current LLVM subproject (Clang, MLIR ...)
#
# The title is set in the subproject's top-level using the variable
# LLVM_SUBPROJECT_TITLE. If it does not exist, it is assumed it is LLVM itself.
# The title is not semantically significant, but use to create folders in
# CMake-generated IDE projects (Visual Studio/XCode).
function(get_subproject_title outvar)
if (LLVM_SUBPROJECT_TITLE)
set(${outvar} "${LLVM_SUBPROJECT_TITLE}" PARENT_SCOPE)
else ()
set(${outvar} "LLVM" PARENT_SCOPE)
endif ()
endfunction(get_subproject_title)

function(llvm_update_compile_flags name)
get_property(sources TARGET ${name} PROPERTY SOURCES)
if("${sources}" MATCHES "\\.c(;|$)")
Expand Down Expand Up @@ -151,7 +166,8 @@ function(add_llvm_symbol_exports target_name export_file)
endif()

add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
get_subproject_title(subproject_title)
set_target_properties(${target_name}_exports PROPERTIES FOLDER "${subproject_title}/API")

get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
foreach(src ${srcs})
Expand Down Expand Up @@ -543,6 +559,8 @@ function(llvm_add_library name)
endif()
endif()

get_subproject_title(subproject_title)

# Generate objlib
if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
# Generate an obj library for both targets.
Expand All @@ -564,7 +582,7 @@ function(llvm_add_library name)
# Bring in the target include directories from our original target.
target_include_directories(${obj_name} PRIVATE $<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>)

set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
set_target_properties(${obj_name} PROPERTIES FOLDER "${subproject_title}/Object Libraries")
if(ARG_DEPENDS)
add_dependencies(${obj_name} ${ARG_DEPENDS})
endif()
Expand Down Expand Up @@ -603,6 +621,7 @@ function(llvm_add_library name)
LINK_LIBS ${ARG_LINK_LIBS}
LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
)
set_target_properties(${name_static} PROPERTIES FOLDER "${subproject_title}/Libraries")

# Bring in the target link info from our original target.
target_link_directories(${name_static} PRIVATE $<TARGET_PROPERTY:${name},LINK_DIRECTORIES>)
Expand All @@ -620,6 +639,7 @@ function(llvm_add_library name)
else()
add_library(${name} STATIC ${ALL_FILES})
endif()
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Libraries")

if(ARG_COMPONENT_LIB)
set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
Expand Down Expand Up @@ -796,14 +816,16 @@ function(add_llvm_install_targets target)
endif()
endforeach()

get_subproject_title(subproject_title)

add_custom_target(${target}
DEPENDS ${file_dependencies}
COMMAND "${CMAKE_COMMAND}"
${component_option}
${prefix_option}
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
USES_TERMINAL)
set_target_properties(${target} PROPERTIES FOLDER "Component Install Targets")
set_target_properties(${target} PROPERTIES FOLDER "${subproject_title}/Installation")
add_custom_target(${target}-stripped
DEPENDS ${file_dependencies}
COMMAND "${CMAKE_COMMAND}"
Expand All @@ -812,7 +834,7 @@ function(add_llvm_install_targets target)
-DCMAKE_INSTALL_DO_STRIP=1
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
USES_TERMINAL)
set_target_properties(${target}-stripped PROPERTIES FOLDER "Component Install Targets (Stripped)")
set_target_properties(${target}-stripped PROPERTIES FOLDER "${subproject_title}/Installation")
if(target_dependencies)
add_dependencies(${target} ${target_dependencies})
add_dependencies(${target}-stripped ${target_dependencies})
Expand All @@ -832,6 +854,8 @@ endfunction()
function(add_llvm_component_group name)
cmake_parse_arguments(ARG "HAS_JIT" "" "LINK_COMPONENTS" ${ARGN})
add_custom_target(${name})
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Component Groups")
if(ARG_HAS_JIT)
set_property(TARGET ${name} PROPERTY COMPONENT_HAS_JIT ON)
endif()
Expand Down Expand Up @@ -865,6 +889,8 @@ function(add_llvm_component_library name)

if(ARG_ADD_TO_COMPONENT)
set_property(TARGET ${ARG_ADD_TO_COMPONENT} APPEND PROPERTY LLVM_LINK_COMPONENTS ${component_name})
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Libraries/${ARG_ADD_TO_COMPONENT}")
endif()

endfunction()
Expand Down Expand Up @@ -921,10 +947,12 @@ macro(add_llvm_library name)
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endif()

get_subproject_title(subproject_title)
if (ARG_MODULE)
set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Loadable Modules")
else()
set_target_properties(${name} PROPERTIES FOLDER "Libraries")
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Libraries")
endif()
endmacro(add_llvm_library name)

Expand All @@ -948,7 +976,8 @@ macro(generate_llvm_objects name)
add_dependencies(${obj_name} ${ARG_DEPENDS})
endif()

set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
get_subproject_title(subproject_title)
set_target_properties(${obj_name} PROPERTIES FOLDER "${subproject_title}/Object Libraries")
endif()

if (ARG_GENERATE_DRIVER)
Expand Down Expand Up @@ -999,6 +1028,8 @@ macro(add_llvm_executable name)
else()
add_executable(${name} ${ALL_FILES})
endif()
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Executables")

setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})

Expand Down Expand Up @@ -1418,8 +1449,9 @@ macro(llvm_add_tool project name)
if( LLVM_BUILD_TOOLS )
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endif()
set_target_properties(${name} PROPERTIES FOLDER "Tools")
endif()
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Tools")
endmacro(llvm_add_tool project name)

macro(add_llvm_tool name)
Expand All @@ -1435,7 +1467,8 @@ macro(add_llvm_example name)
if( LLVM_BUILD_EXAMPLES )
install(TARGETS ${name} RUNTIME DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}")
endif()
set_target_properties(${name} PROPERTIES FOLDER "Examples")
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Examples")
endmacro(add_llvm_example name)

macro(add_llvm_example_library name)
Expand All @@ -1446,7 +1479,8 @@ macro(add_llvm_example_library name)
add_llvm_library(${name} ${ARGN})
endif()

set_target_properties(${name} PROPERTIES FOLDER "Examples")
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Examples")
endmacro(add_llvm_example_library name)

# This is a macro that is used to create targets for executables that are needed
Expand All @@ -1457,7 +1491,8 @@ macro(add_llvm_utility name)
endif()

add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
set_target_properties(${name} PROPERTIES FOLDER "Utils")
get_subproject_title(subproject_title)
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Utils")
if ( ${name} IN_LIST LLVM_TOOLCHAIN_UTILITIES OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
get_target_export_arg(${name} LLVM export_to_llvmexports)
Expand All @@ -1480,19 +1515,20 @@ endmacro(add_llvm_utility name)

macro(add_llvm_fuzzer name)
cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN})
get_subproject_title(subproject_title)
if( LLVM_LIB_FUZZING_ENGINE )
set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE})
set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Fuzzers")
elseif( LLVM_USE_SANITIZE_COVERAGE )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN})
add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Fuzzers")
elseif( ARG_DUMMY_MAIN )
add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS})
set_target_properties(${name} PROPERTIES FOLDER "Fuzzers")
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Fuzzers")
endif()
endmacro()

Expand Down Expand Up @@ -1653,6 +1689,8 @@ function(add_unittest test_suite test_name)

list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream
add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
get_subproject_title(subproject_title)
set_target_properties(${test_name} PROPERTIES FOLDER "${subproject_title}/Tests/Unit")

# The runtime benefits of LTO don't outweight the compile time costs for tests.
if(LLVM_ENABLE_LTO)
Expand Down Expand Up @@ -1684,10 +1722,6 @@ function(add_unittest test_suite test_name)
target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest ${LLVM_PTHREAD_LIB})

add_dependencies(${test_suite} ${test_name})
get_target_property(test_suite_folder ${test_suite} FOLDER)
if (test_suite_folder)
set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
endif ()
endfunction()

# Use for test binaries that call llvm::getInputFileDirectory(). Use of this
Expand All @@ -1710,7 +1744,8 @@ function(add_benchmark benchmark_name)
add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
set_property(TARGET ${benchmark_name} PROPERTY FOLDER "Utils")
get_subproject_title(subproject_title)
set_property(TARGET ${benchmark_name} PROPERTY FOLDER "${subproject_title}/Benchmarks")
target_link_libraries(${benchmark_name} PRIVATE benchmark)
endfunction()

Expand Down Expand Up @@ -1999,6 +2034,8 @@ function(add_lit_target target comment)
COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
message(STATUS "${target} does nothing.")
endif()
get_subproject_title(subproject_title)
set_target_properties(${target} PROPERTIES FOLDER "${subproject_title}/Tests")

if (ARG_DEPENDS)
add_dependencies(${target} ${ARG_DEPENDS})
Expand Down Expand Up @@ -2080,7 +2117,8 @@ function(add_lit_testsuites project directory)
cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})

if (NOT ARG_FOLDER)
set(ARG_FOLDER "Test Subdirectories")
get_subproject_title(subproject_title)
set(ARG_FOLDER "${subproject_title}/Tests/LIT Testsuites")
endif()

# Search recursively for test directories by assuming anything not
Expand Down Expand Up @@ -2282,7 +2320,8 @@ function(llvm_add_tool_symlink project link_name target)
set(should_build_all ALL)
endif()
add_custom_target(${target_name} ${should_build_all} DEPENDS ${target} ${output_path})
set_target_properties(${target_name} PROPERTIES FOLDER Tools)
get_subproject_title(subproject_title)
set_target_properties(${target_name} PROPERTIES FOLDER "${subproject_title}/Tools")

# Make sure both the link and target are toolchain tools
if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS)
Expand Down Expand Up @@ -2542,5 +2581,7 @@ function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
if(LLVM_USE_HOST_TOOLS AND NOT ${setting_name})
build_native_tool(${tool_name} exe_name DEPENDS ${tool_name})
add_custom_target(${target_var_name} DEPENDS ${exe_name})
get_subproject_title(subproject_title)
set_target_properties(${target_var_name} PROPERTIES FOLDER "${subproject_title}/Native")
endif()
endfunction()
6 changes: 4 additions & 2 deletions llvm/cmake/modules/AddOCaml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ function(add_ocaml_library name)
VERBATIM)

add_custom_target("ocaml_${name}" ALL DEPENDS ${ocaml_outputs} "${bin}/${name}.odoc")
get_subproject_title(subproject_title)
set_target_properties("ocaml_${name}" PROPERTIES FOLDER "${subproject_title}/Bindings/OCaml")

set_target_properties("ocaml_${name}" PROPERTIES
OCAML_FLAGS "-I;${bin}")
Expand Down Expand Up @@ -228,5 +230,5 @@ endfunction()
add_custom_target(ocaml_make_directory
COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${LLVM_LIBRARY_DIR}/ocaml/llvm")
add_custom_target("ocaml_all")
set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")
set_target_properties(ocaml_make_directory PROPERTIES FOLDER "Misc")
set_target_properties(ocaml_all PROPERTIES FOLDER "LLVM/Bindings/OCaml")
set_target_properties(ocaml_make_directory PROPERTIES FOLDER "LLVM/Bindings/OCaml")
3 changes: 3 additions & 0 deletions llvm/cmake/modules/AddSphinxTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (LLVM_ENABLE_SPHINX)
find_package(Sphinx REQUIRED)
if (LLVM_BUILD_DOCS AND NOT TARGET sphinx)
add_custom_target(sphinx ALL)
set_target_properties(sphinx PROPERTIES FOLDER "LLVM/Docs")
endif()
else()
message(STATUS "Sphinx disabled.")
Expand Down Expand Up @@ -58,6 +59,8 @@ function (add_sphinx_target builder project)
"${SPHINX_BUILD_DIR}" # Output
COMMENT
"Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"")
get_subproject_title(subproject_title)
set_target_properties(${SPHINX_TARGET_NAME} PROPERTIES FOLDER "${subproject_title}/Docs")

# When "clean" target is run, remove the Sphinx build directory
set_property(DIRECTORY APPEND PROPERTY
Expand Down
4 changes: 4 additions & 0 deletions llvm/cmake/modules/CrossCompile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)

add_custom_target(CREATE_${project_name}_${target_name}
DEPENDS ${${project_name}_${target_name}_BUILD})
get_subproject_title(subproject_title)
set_target_properties(CREATE_${project_name}_${target_name} PROPERTIES FOLDER "${subproject_title}/Native")

# Escape semicolons in the targets list so that cmake doesn't expand
# them to spaces.
Expand Down Expand Up @@ -98,6 +100,8 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)

add_custom_target(CONFIGURE_${project_name}_${target_name}
DEPENDS ${${project_name}_${target_name}_BUILD}/CMakeCache.txt)
get_subproject_title(subproject_title)
set_target_properties(CONFIGURE_${project_name}_${target_name} PROPERTIES FOLDER "${subproject_title}/Native")

endfunction()

Expand Down
Loading
Loading