CMakeMacroGenerateProject: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
mNo edit summary
(Replace content with link to new CMake community wiki)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[CMake_User_Contributed_Macros|Back]]
{{CMake/Template/Moved}}


This macro takes a list of files as input and generates source groups that follow the relative path of the files from the ProjectDir folder. This is strictly a cosmetic change, but it's nice if you're using the CMake generated projects also for development
This page has moved [https://gitlab.kitware.com/cmake/community/wikis/contrib/macros/GenerateProject here].
 
-----
 
  # create hierarchical source groups
  MACRO ( GenerateProject ProjectDir ProjectSources )
 
    FOREACH ( Source "${ProjectSources}" )
      STRING ( REGEX REPLACE "${ProjectDir}" "" RelativePath "${Source}" )
      STRING ( REGEX REPLACE "[\\\\/][^\\\\/]*$" "" RelativePath "${RelativePath}" )
      STRING ( REGEX REPLACE "^[\\\\/]" "" RelativePath "${RelativePath}" )
      STRING ( REGEX REPLACE "/" "\\\\\\\\" RelativePath "${RelativePath}" )
      SOURCE_GROUP ( "${RelativePath}" FILES ${Source} )
    ENDFOREACH ( Source )
  ENDMACRO ( GenerateProject)
 
-----
 
 
A typical use for this macro would be:
 
  GenerateProject ( src/MyLib ${MyLibSources} )
  ADD_LIBRARY (MyLib SHARED ${MyLibSources} )
 
 
[[CMake_User_Contributed_Macros|Back]]
 
{{CMake/Template/Footer}}

Latest revision as of 15:41, 30 April 2018


The CMake community Wiki has moved to the Kitware GitLab Instance.

This page has moved here.