[CMake] [SOLVED] RE: Get targets added in subdirectory

Robert Bielik Robert.Bielik at dirac.com
Sat Oct 8 13:41:55 EDT 2016


For reference, I ended up doing a special add_subdirectory_with_folder function, like so:

function (add_subdirectory_with_folder folder_name)
  function (add_library name type)
    _add_library (${ARGV})
    # Do not wrap creation of INTERFACE libraries
    if (type STREQUAL INTERFACE)
      return()
    endif()

    set_target_properties(${name}
      PROPERTIES
      FOLDER "${folder_name}"
    )
  endfunction()

  function (add_executable name)
    _add_executable (${ARGV})
    set_target_properties(${name}
      PROPERTIES
      FOLDER "${folder_name}"
    )
  endfunction()

  add_subdirectory (${ARGN})
endfunction()

#Usage
add_subdirectory_with_folder("My solution folder" <path to subdirectory>)

The nice thing is that it *seems* like the wrapper functions are scoped within the add_subdirectory_with_folder function, thus
not affecting targets defined later.

Regards
/R



>-----Original Message-----
>From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Robert Bielik
>Sent: den 8 oktober 2016 19:12
>To: Cmake at cmake.org
>Subject: [CMake] [SOLVED] RE: Get targets added in subdirectory
>
>I ended up solving this with the "wrapped cmake function" pattern, works
>nicely.
>
>/R
>
>>-----Original Message-----
>>From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Robert
>Bielik
>>Sent: den 8 oktober 2016 17:34
>>To: Cmake at cmake.org
>>Subject: [CMake] Get targets added in subdirectory
>>
>>Is there a way to get a list of targets added via add_subdirectory ? My
>>goal is to place all targets in a subdirectory in a special folder in the VS IDE...
>>
>>Regards
>>/Robert
>>
>>--
>>
>>Powered by www.kitware.com
>>
>>Please keep messages on-topic and check the CMake FAQ at:
>>http://www.cmake.org/Wiki/CMake_FAQ
>>
>>Kitware offers various services to support the CMake community. For
>>more information on each offering, please visit:
>>
>>CMake Support: http://cmake.org/cmake/help/support.html
>>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>>Visit other Kitware open-source projects at
>>http://www.kitware.com/opensource/opensource.html
>>
>>Follow this link to subscribe/unsubscribe:
>>http://public.kitware.com/mailman/listinfo/cmake
>--
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For more
>information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list