yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
2e0fe3d06
master
1# 2# A function to make target specification a little more declarative 3# 4# See the comments on the options below for usage 5# 6function ( slang_add_target dir type ) 7set ( no_value_args 8# Don't include in the 'all' target 9EXCLUDE_FROM_ALL 10# This is loaded at runtime as a shared library 11SHARED_LIBRARY_TOOL 12# -Wextra 13USE_EXTRA_WARNINGS 14# don't set -Wall 15USE_FEWER_WARNINGS 16# Make this a Windows app, rather than a console app, only makes a 17# difference when compiling for Windows 18WIN32_EXECUTABLE 19# Install this target for a non-component install 20INSTALL 21# Don't include any source in this target, this is a complement to 22# EXPLICIT_SOURCE, and doesn't interact with EXTRA_SOURCE_DIRS 23NO_SOURCE 24# Don't generate split debug info for this target 25NO_SPLIT_DEBUG_INFO 26) 27set ( single_value_args 28# Set the target name, useful for multiple targets from the same 29# directory. 30# By default this is the name of the last directory component given 31TARGET_NAME 32# Set the output name, otherwise defaults to the target name 33OUTPUT_NAME 34# Set an explicit output directory relative to the cmake binary 35# directory. otherwise defaults to the binary directory root. 36# Outputs are always placed in a further subdirectory according to 37# build config 38OUTPUT_DIR 39# If this is a shared library then the ${EXPORT_MACRO_PREFIX}_DYNAMIC and 40# ${EXPORT_MACRO_PREFIX}_DYNAMIC_EXPORT macros are set for using and 41# building respectively 42EXPORT_MACRO_PREFIX 43# Ignore target type and use a particular style of export macro 44# _DYNAMIC or _STATIC, this is useful when the target type is OBJECT 45# pass in STATIC or SHARED 46EXPORT_TYPE_AS 47# The folder in which to place this target for IDE-based generators (VS 48# and XCode) 49FOLDER 50# The working directory for debugging 51DEBUG_DIR 52# Install this target as part of a component 53INSTALL_COMPONENT 54# Override the debug info component name for installation 55# explicit name instead, used for externally built things such as 56# slang-glslang and slang-llvm which have large pdb files 57DEBUG_INFO_INSTALL_COMPONENT 58# The name of the Export set to associate with this installed target 59EXPORT_SET_NAME 60) 61set ( multi_value_args 62# Use exactly these sources, instead of globbing from the directory 63# argument 64EXPLICIT_SOURCE 65# Additional directories from which to glob source 66EXTRA_SOURCE_DIRS 67# Additional compile definitions and options 68EXTRA_COMPILE_DEFINITIONS_PRIVATE 69EXTRA_COMPILE_DEFINITIONS_PUBLIC 70EXTRA_COMPILE_OPTIONS_PRIVATE 71# Targets with which to link privately 72LINK_WITH_PRIVATE 73# Targets with which to link publicly, for example if their headers 74# appear in our headers 75LINK_WITH_PUBLIC 76# Frameworks with which to link privately 77LINK_WITH_FRAMEWORK 78# Targets whose headers we use, but don't link with 79INCLUDE_FROM_PRIVATE 80# Targets whose headers we use in our headers, so need to make sure 81# dependencies of this target also include them 82INCLUDE_FROM_PUBLIC 83# Any include directories other targets need to use this target 84INCLUDE_DIRECTORIES_PUBLIC 85# Any include directories this target only needs 86INCLUDE_DIRECTORIES_PRIVATE 87# Add a dependency on the new target to the specified targets 88REQUIRED_BY 89# Add a dependency to the new target on the specified targets 90REQUIRES 91# Add a dependency to the new target on the specified targets if they exist 92OPTIONAL_REQUIRES 93# Globs for any headers to install 94PUBLIC_HEADERS 95) 96cmake_parse_arguments ( 97ARG 98" ${ no_value_args } " 99" ${ single_value_args } " 100" ${ multi_value_args } " 101${ ARGN } 102) 103 104if ( DEFINED ARG_UNPARSED_ARGUMENTSOR DEFINED ARG_KEYWORDS_MISSING_VALUES) 105foreach ( unparsed_arg${ ARG_UNPARSED_ARGUMENTS }) 106message ( 107SEND_ERROR 108"Unrecognized argument in slang_add_target: ${ unparsed_arg } " 109) 110endforeach () 111foreach ( bad_kwarg${ ARG_KEYWORDS_MISSING_VALUES }) 112message ( 113SEND_ERROR 114"Keyword argument missing values in slang_add_target: ${ bad_kwarg } " 115) 116endforeach () 117return () 118endif () 119 120# 121# Set up some variables, including the target name 122# 123get_filename_component ( dir_absolute ${ dir } ABSOLUTE ) 124if ( DEFINED ARG_TARGET_NAME) 125set ( target ${ ARG_TARGET_NAME }) 126else () 127get_filename_component ( target ${ dir_absolute } NAME ) 128endif () 129 130# 131# Find the source for this target 132# 133if ( ARG_NO_SOURCE) 134elseif ( ARG_EXPLICIT_SOURCE) 135list ( APPEND source ${ ARG_EXPLICIT_SOURCE }) 136else () 137slang_glob_sources ( source ${ dir }) 138endif () 139foreach ( extra_dir${ ARG_EXTRA_SOURCE_DIRS }) 140slang_glob_sources ( source ${ extra_dir }) 141endforeach () 142 143# 144# Create the target 145# 146set ( library_types 147STATIC 148SHARED 149OBJECT 150MODULE 151ALIAS 152) 153if ( typeSTREQUAL "EXECUTABLE" ) 154add_executable ( $ { target } ${ source }) 155elseif ( typeSTREQUAL "LIBRARY" ) 156add_library ( $ { target } ${ source }) 157elseif ( typeIN_LIST library_types) 158add_library ( $ { target } ${ type } ${ source }) 159else () 160message ( 161SEND_ERROR 162"Unsupported target type ${ type } in slang_add_target" 163) 164return () 165endif () 166 167# Enable link-time optimization for release builds 168# See: https://cmake.org/cmake/help/latest/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html 169if ( SLANG_ENABLE_RELEASE_LTO) 170set_target_properties ( 171${ target } 172PROPERTIES 173INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE 174INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE 175) 176endif () 177 178# 179# Set the output directory 180# 181# We don't want the output directory to be sensitive to where 182# slang_add_target is called from, so set it explicitly here. 183# 184if ( DEFINED ARG_OUTPUT_DIR) 185set ( output_dir " ${ CMAKE_BINARY_DIR } / ${ ARG_OUTPUT_DIR } / $ <CONFIG>" ) 186else () 187# Default to placing things in the cmake binary root. 188# 189# While it would be nice to place things according to their 190# subdirectory, Windows' inflexibility in being able to find DLLs makes 191# this tricky there. 192set ( output_dir " ${ CMAKE_BINARY_DIR } / $ <CONFIG>" ) 193endif () 194set ( archive_subdir ${ library_subdir }) 195if ( typeSTREQUAL "MODULE" ) 196set ( library_subdir ${ module_subdir }) 197endif () 198 199# Respect user-defined CMAKE_*_OUTPUT_DIRECTORY variables if they are set 200if ( DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 201set ( archive_output_dir " ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } " ) 202else () 203set ( archive_output_dir " ${ output_dir } / ${ archive_subdir } " ) 204endif () 205 206if ( DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 207set ( library_output_dir " ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } " ) 208else () 209set ( library_output_dir " ${ output_dir } / ${ library_subdir } " ) 210endif () 211 212if ( DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 213set ( runtime_output_dir " ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " ) 214set ( pdb_output_dir " ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " ) 215else () 216set ( runtime_output_dir " ${ output_dir } / ${ runtime_subdir } " ) 217set ( pdb_output_dir " ${ output_dir } / ${ runtime_subdir } " ) 218endif () 219 220set_target_properties ( 221${ target } 222PROPERTIES 223ARCHIVE_OUTPUT_DIRECTORY " ${ archive_output_dir } " 224LIBRARY_OUTPUT_DIRECTORY " ${ library_output_dir } " 225RUNTIME_OUTPUT_DIRECTORY " ${ runtime_output_dir } " 226PDB_OUTPUT_DIRECTORY " ${ pdb_output_dir } " 227) 228 229# For Multi-Config generators we also need to set per-config output directories 230# if user-defined paths are provided 231if ( DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 232set_target_properties ( 233${ target } 234PROPERTIES 235ARCHIVE_OUTPUT_DIRECTORY_DEBUG 236" ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } " 237ARCHIVE_OUTPUT_DIRECTORY_RELEASE 238" ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } " 239ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO 240" ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } " 241ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL 242" ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } " 243) 244endif () 245 246if ( DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 247set_target_properties ( 248${ target } 249PROPERTIES 250LIBRARY_OUTPUT_DIRECTORY_DEBUG 251" ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } " 252LIBRARY_OUTPUT_DIRECTORY_RELEASE 253" ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } " 254LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO 255" ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } " 256LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL 257" ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } " 258) 259endif () 260 261if ( DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 262set_target_properties ( 263${ target } 264PROPERTIES 265RUNTIME_OUTPUT_DIRECTORY_DEBUG 266" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 267RUNTIME_OUTPUT_DIRECTORY_RELEASE 268" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 269RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO 270" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 271RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL 272" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 273PDB_OUTPUT_DIRECTORY_DEBUG " ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 274PDB_OUTPUT_DIRECTORY_RELEASE " ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 275PDB_OUTPUT_DIRECTORY_RELWITHDEBINFO 276" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 277PDB_OUTPUT_DIRECTORY_MINSIZEREL 278" ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } " 279) 280endif () 281 282set ( debug_configs "Debug,RelWithDebInfo" ) 283if ( SLANG_ENABLE_RELEASE_DEBUG_INFO) 284set ( debug_configs "Debug,RelWithDebInfo,Release" ) 285endif () 286 287set_target_properties ( 288${ target } 289PROPERTIES 290MSVC_DEBUG_INFORMATION_FORMAT 291" $ < $ <CONFIG: ${ debug_configs } >:Embedded>" 292) 293if ( MSVC) 294target_link_options ( 295${ target } 296PRIVATE " $ < $ <CONFIG: ${ debug_configs } >:/DEBUG>" 297) 298else () 299target_compile_options ( 300${ target } 301PRIVATE " $ < $ <CONFIG: ${ debug_configs } >:-g>" 302) 303endif () 304 305# 306# Set common compile options and properties 307# 308if ( ARG_USE_EXTRA_WARNINGS) 309set_default_compile_options ( $ { target } USE_EXTRA_WARNINGS ) 310elseif ( ARG_USE_FEWER_WARNINGS) 311set_default_compile_options ( $ { target } USE_FEWER_WARNINGS ) 312else () 313set_default_compile_options ( $ { target }) 314endif () 315 316# Set debug info options if not disabled 317# Determine if this target produces a binary that can have debug info 318if ( 319NOT ARG_NO_SPLIT_DEBUG_INFO 320AND typeMATCHES "^(EXECUTABLE|SHARED|MODULE) $ " 321AND SLANG_ENABLE_SPLIT_DEBUG_INFO 322) 323set ( generate_split_debug_info TRUE ) 324else () 325set ( generate_split_debug_info FALSE ) 326endif () 327 328if ( generate_split_debug_info) 329if ( MSVC) 330set_target_properties ( 331${ target } 332PROPERTIES 333COMPILE_PDB_NAME " ${ target } " 334COMPILE_PDB_OUTPUT_DIRECTORY " ${ output_dir } " 335) 336else () 337if ( CMAKE_SYSTEM_NAMEMATCHES "Darwin" ) 338# macOS - use dsymutil with --flat to create separate debug file 339add_custom_command ( 340TARGET ${ target } 341POST_BUILD 342COMMAND 343dsymutil --flat $ <TARGET_FILE: ${ target } > -o 344$ <TARGET_FILE: ${ target } >.dwarf 345COMMAND chmod 644 $ <TARGET_FILE: ${ target } >.dwarf 346COMMAND ${ CMAKE_STRIP } -S $ <TARGET_FILE: ${ target } > 347WORKING_DIRECTORY ${ output_dir } 348VERBATIM 349) 350else () 351add_custom_command ( 352TARGET ${ target } 353POST_BUILD 354COMMAND 355${ CMAKE_OBJCOPY } --only-keep-debug 356$ <TARGET_FILE: ${ target } > $ <TARGET_FILE: ${ target } >.dwarf 357WORKING_DIRECTORY ${ output_dir } 358VERBATIM 359) 360# We may be building for Android on a Windows host, where chmod isn't available or needed. 361if ( NOT CMAKE_HOST_WIN32) 362add_custom_command ( 363TARGET ${ target } 364POST_BUILD 365COMMAND chmod 644 $ <TARGET_FILE: ${ target } >.dwarf 366WORKING_DIRECTORY ${ output_dir } 367VERBATIM 368) 369endif () 370add_custom_command ( 371TARGET ${ target } 372POST_BUILD 373COMMAND 374${ CMAKE_STRIP } --strip-debug $ <TARGET_FILE: ${ target } > 375COMMAND 376${ CMAKE_OBJCOPY } 377--add-gnu-debuglink= $ <TARGET_FILE: ${ target } >.dwarf 378$ <TARGET_FILE: ${ target } > 379WORKING_DIRECTORY ${ output_dir } 380VERBATIM 381) 382endif () 383endif () 384endif () 385 386set_target_properties ( 387${ target } 388PROPERTIES EXCLUDE_FROM_ALL ${ ARG_EXCLUDE_FROM_ALL } 389) 390 391set_target_properties ( 392${ target } 393PROPERTIES WIN32_EXECUTABLE ${ ARG_WIN32_EXECUTABLE } 394) 395 396if ( DEFINED ARG_OUTPUT_NAME) 397set_target_properties ( 398${ target } 399PROPERTIES OUTPUT_NAME ${ ARG_OUTPUT_NAME } 400) 401endif () 402 403if ( DEFINED ARG_FOLDER) 404set_target_properties ( $ { target } PROPERTIES FOLDER ${ ARG_FOLDER }) 405endif () 406 407if ( DEFINED ARG_DEBUG_DIR) 408set_target_properties ( 409${ target } 410PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ ARG_DEBUG_DIR } 411) 412endif () 413 414# 415# Link and include from dependencies 416# 417if ( CMAKE_VERSIONVERSION_GREATER_EQUAL "3.26" ) 418target_link_libraries ( 419${ target } 420PRIVATE $ <BUILD_LOCAL_INTERFACE: ${ ARG_LINK_WITH_PRIVATE } > 421) 422else () 423# Expand the list manually to work around a bug in cmake 3.22.1 424# See: https://github.com/shader-slang/slang/issues/8335 425foreach ( lib IN LISTS ARG_LINK_WITH_PRIVATE) 426target_link_libraries ( $ { target } PRIVATE $ <BUILD_INTERFACE: ${ lib } > ) 427endforeach () 428endif () 429 430target_link_libraries ( $ { target } PUBLIC ${ ARG_LINK_WITH_PUBLIC }) 431 432if ( CMAKE_SYSTEM_NAMEMATCHES "Darwin" ) 433foreach ( link_framework${ ARG_LINK_WITH_FRAMEWORK }) 434target_link_libraries ( 435${ target } 436PRIVATE "-framework ${ link_framework } " 437) 438endforeach () 439endif () 440 441foreach ( include_from${ ARG_INCLUDE_FROM_PRIVATE }) 442target_include_directories ( 443${ target } 444PRIVATE 445$ < $ <BOOL: ${ include_from } >: $ <TARGET_PROPERTY: ${ include_from } ,INTERFACE_INCLUDE_DIRECTORIES>> 446) 447endforeach () 448foreach ( include_from${ ARG_INCLUDE_FROM_PUBLIC }) 449target_include_directories ( 450${ target } 451PUBLIC 452$ < $ <BOOL: ${ include_from } >: $ <TARGET_PROPERTY: ${ include_from } ,INTERFACE_INCLUDE_DIRECTORIES>> 453) 454endforeach () 455 456# 457# Set our exported include directories 458# 459foreach ( inc${ ARG_INCLUDE_DIRECTORIES_PUBLIC }) 460get_filename_component ( inc_abs ${ inc } ABSOLUTE ) 461target_include_directories ( 462${ target } 463PUBLIC 464" $ <BUILD_INTERFACE: ${ inc_abs } >" 465" $ <INSTALL_INTERFACE: ${ CMAKE_INSTALL_INCLUDEDIR } >" 466) 467endforeach () 468foreach ( inc${ ARG_INCLUDE_DIRECTORIES_PRIVATE }) 469get_filename_component ( inc_abs ${ inc } ABSOLUTE ) 470if ( CMAKE_VERSIONVERSION_GREATER_EQUAL "3.26" ) 471target_include_directories ( 472${ target } 473PRIVATE " $ <BUILD_LOCAL_INTERFACE: ${ inc_abs } >" 474) 475else () 476target_include_directories ( 477${ target } 478PRIVATE " $ <BUILD_INTERFACE: ${ inc_abs } >" 479) 480endif () 481endforeach () 482 483# 484# Set up export macros 485# 486get_target_property ( target_type ${ target } TYPE ) 487if ( DEFINED ARG_EXPORT_MACRO_PREFIX) 488if ( 489 target_typeSTREQUAL SHARED_LIBRARY 490OR target_typeSTREQUAL MODULE_LIBRARY 491OR ARG_EXPORT_TYPE_ASSTREQUAL SHARED 492OR ARG_EXPORT_TYPE_ASSTREQUAL MODULE 493) 494target_compile_definitions ( 495${ target } 496PUBLIC " ${ ARG_EXPORT_MACRO_PREFIX } _DYNAMIC" 497PRIVATE " ${ ARG_EXPORT_MACRO_PREFIX } _DYNAMIC_EXPORT" 498) 499elseif ( 500 target_typeSTREQUAL STATIC_LIBRARY 501OR ARG_EXPORT_TYPE_ASSTREQUAL STATIC 502) 503target_compile_definitions ( 504${ target } 505PUBLIC " ${ ARG_EXPORT_MACRO_PREFIX } _STATIC" 506) 507else () 508message ( 509WARNING 510"unhandled case in slang_add_target while setting export macro" 511) 512endif () 513endif () 514 515# 516# Other dependencies 517# 518foreach ( requirer${ ARG_REQUIRED_BY }) 519add_dependencies ( $ { requirer } ${ target }) 520endforeach () 521 522if ( DEFINED ARG_REQUIRES) 523add_dependencies ( $ { target } ${ ARG_REQUIRES }) 524endif () 525 526foreach ( required${ ARG_OPTIONAL_REQUIRES }) 527if ( TARGET ${ required }) 528add_dependencies ( $ { target } ${ required }) 529endif () 530endforeach () 531 532# 533# Other preprocessor defines and options 534# 535if ( ARG_EXTRA_COMPILE_DEFINITIONS_PRIVATE) 536target_compile_definitions ( 537${ target } 538PRIVATE ${ ARG_EXTRA_COMPILE_DEFINITIONS_PRIVATE } 539) 540endif () 541if ( ARG_EXTRA_COMPILE_DEFINITIONS_PUBLIC) 542target_compile_definitions ( 543${ target } 544PUBLIC ${ ARG_EXTRA_COMPILE_DEFINITIONS_PUBLIC } 545) 546endif () 547if ( ARG_EXTRA_COMPILE_OPTIONS_PRIVATE) 548target_compile_options ( 549${ target } 550PRIVATE ${ ARG_EXTRA_COMPILE_OPTIONS_PRIVATE } 551) 552endif () 553 554# 555# Since we do a lot of dynamic loading, unconditionally set the build rpath 556# to find our libraries. Ordinarily CMake would sort this out, but we do 557# have libraries which at build time don't depend on any other shared 558# libraries of ours but which do load them at runtime, hence the need to do 559# this explicitly here. 560# 561if ( CMAKE_SYSTEM_NAMEMATCHES "Darwin" ) 562set ( ORIGIN "@loader_path" ) 563else () 564set ( ORIGIN " $ ORIGIN" ) 565endif () 566set_property ( 567TARGET ${ target } 568APPEND 569PROPERTY BUILD_RPATH " ${ ORIGIN } /../ ${ library_subdir } ; ${ ORIGIN } " 570) 571set_property ( 572TARGET ${ target } 573APPEND 574PROPERTY INSTALL_RPATH " ${ ORIGIN } /../ ${ library_subdir } ; ${ ORIGIN } " 575) 576 577# On the same topic, give everything a dylib suffix on Mac OS 578if ( CMAKE_SYSTEM_NAMEMATCHES "Darwin" AND typeSTREQUAL "MODULE" ) 579set_property ( TARGET ${ target } PROPERTY SUFFIX ".dylib" ) 580endif () 581 582# 583# Mark headers for installation 584# 585if ( ARG_PUBLIC_HEADERS) 586if ( NOT ARG_INSTALL) 587message ( 588WARNING 589" ${ target } was declared with PUBLIC_HEADERS but without INSTALL, the former will do nothing" 590) 591endif () 592 593glob_append ( public_headers ${ ARG_PUBLIC_HEADERS }) 594if ( NOT public_headers) 595message ( WARNING " ${ target } 's PUBLIC_HEADER globs found no matches" ) 596else () 597set_target_properties ( 598${ target } 599PROPERTIES PUBLIC_HEADER " ${ public_headers } " 600) 601endif () 602endif () 603 604# 605# Mark for installation 606# 607macro ( i ) 608if ( ARG_EXPORT_SET_NAME) 609set ( export_args EXPORT ${ ARG_EXPORT_SET_NAME }) 610else () 611if ( typeMATCHES "^(EXECUTABLE|SHARED|MODULE) $ " ) 612message ( 613WARNING 614"Target ${ target } is set to be INSTALLED but EXPORT_SET_NAME wasn't specified" 615) 616endif () 617set ( export_args ) 618endif () 619install ( 620TARGETS ${ target } ${ export_args } 621ARCHIVE DESTINATION ${ archive_subdir } 622${ ARGN } 623LIBRARY DESTINATION ${ library_subdir } 624${ ARGN } 625RUNTIME DESTINATION ${ runtime_subdir } 626${ ARGN } 627PUBLIC_HEADER DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } 628${ ARGN } 629) 630endmacro () 631 632if ( ARG_INSTALL_COMPONENT) 633i ( EXCLUDE_FROM_ALL COMPONENT ${ ARG_INSTALL_COMPONENT }) 634set ( debug_component " ${ ARG_INSTALL_COMPONENT } -debug-info" ) 635elseif ( ARG_INSTALL) 636i () 637set ( debug_component "debug-info" ) 638endif () 639 640if ( DEFINED ARG_DEBUG_INFO_INSTALL_COMPONENT) 641set ( debug_component " ${ ARG_DEBUG_INFO_INSTALL_COMPONENT } " ) 642endif () 643 644# Install debug info only if target is being installed 645if (( ARG_INSTALLOR ARG_INSTALL_COMPONENT) AND generate_split_debug_info) 646if ( typeSTREQUAL "EXECUTABLE" OR WIN32) 647set ( debug_dest ${ runtime_subdir }) 648else () 649set ( debug_dest ${ library_subdir }) 650endif () 651 652if ( MSVC) 653set ( debug_file $ <TARGET_PDB_FILE: ${ target } > ) 654else () 655set ( debug_file " $ <TARGET_FILE: ${ target } >.dwarf" ) 656endif () 657 658install ( 659FILES ${ debug_file } 660DESTINATION ${ debug_dest } 661COMPONENT ${ debug_component } 662EXCLUDE_FROM_ALL 663OPTIONAL 664) 665endif () 666endfunction () 667 668# Ideally we'd use CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_RUNTIMEDIR here, 669# however some Slang functionality (specifically generating executables on 670# Linux systems) relies on runtime libraries being at "$ORIGIN/../lib". This 671# could be improved by setting at configure-time that path to be the relative 672# path from CM_I_RD to CM_I_LD. 673set ( library_subdir lib ) 674set ( runtime_subdir bin ) 675 676# On Windows, because there's no RPATH, place modules in bin, next to the 677# executables which load them (by deault, CMAKE will place them in lib and 678# expect the application to seek them out there) 679# 680# This variable is used in the above function as and elsewhere for installing 681# an imported module (slang-llvm from binary), hence why it's defined here. 682if ( CMAKE_SYSTEM_NAMESTREQUAL "Windows" ) 683set ( module_subdir ${ runtime_subdir }) 684else () 685set ( module_subdir ${ library_subdir }) 686endif ()