Created
February 6, 2018 02:39
-
-
Save playmer/5259fad6a28742638ae1508892a78b73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(YTE_Source_Group aRoot aTarget) | |
get_target_property(targetBinaryDir ${aTarget} BINARY_DIR) | |
get_target_property(targetSourceDir ${aTarget} SOURCE_DIR) | |
get_target_property(targetSources ${aTarget} SOURCES) | |
# This will determine if the given files are in a folder or not and separate | |
# them on that alone. | |
foreach(aFile ${targetSources}) | |
file(TO_CMAKE_PATH ${aFile} resultFile) | |
get_filename_component(nameComponent ${resultFile} NAME) | |
get_filename_component(fullPath ${nameComponent} ABSOLUTE) | |
if(IS_ABSOLUTE ${aFile}) | |
# It's only safe to call RELATIVE_PATH if the path begins with our "root" dir. | |
string(FIND "${aFile}" "${targetSourceDir}" checkIfRelativeToSourceDir) | |
string(FIND "${aFile}" "${targetBinaryDir}" checkIfRelativeToBinaryDir) | |
if ("${checkIfRelativeToSourceDir}" EQUAL 0) | |
file(RELATIVE_PATH relativePath ${targetSourceDir} ${aFile}) | |
elseif ("${checkIfRelativeToBinaryDir}" EQUAL 0) | |
file(RELATIVE_PATH relativePath ${targetBinaryDir} ${aFile}) | |
set(fullPath ${targetBinaryDir}/${nameComponent}) | |
endif() | |
else() | |
set(relativePath ${aFile}) | |
endif() | |
if(EXISTS ${fullPath}) | |
set(notInAFolder ${notInAFolder} ${relativePath}) | |
else() | |
set(inAFolder ${inAFolder} ${relativePath}) | |
endif() | |
endforeach() | |
# We use a no space prefix with files from folders, otherwise the filters | |
# don't get made. | |
source_group(TREE ${${aRoot}} | |
PREFIX "" | |
FILES ${inAFolder}) | |
# We use a one space prefix with files not in folders, otherwise the files | |
# are put into "Source Files" and "Header Files" filters. | |
source_group(TREE ${${aRoot}} | |
PREFIX " " | |
FILES ${notInAFolder}) | |
endfunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment