I have a projects in which the sources file are organizes in a hierarchy of directories.
For example: - Src | - Folder A | - 1.cpp | - 1.hpp | - FolderA1 | - 2.cpp | - 2.hpp | - Folder B | - 3.cpp | - 3.hpp I wrote a CMakeLists.txt for generating a Visual Studio Projects (VS 2012). My goals are the following: - Preserve the directory structure - Allows other developer to add source files in the directory, by means of visual studio, without having to write CMakeLists.txt For doing that I wrote the following CMakeLists.txt cmake_minimum_required(VERSION 2.8.11) project(Common-library CXX) #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) #Specify my Include Directory set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src) # Boost configuration SET(Boost_USE_STATIC_LIBS ON) find_package(Boost REQUIRED COMPONENTS filesystem system thread REQUIRED) include_directories( ${Boost_INCLUDE_DIRS} ${ PROJECT_INCLUDE_DIR} ) # I used this for allowing CMake to include all the files, # also new ones, without having to touch the CMakeLists.txt file(GLOB_RECURSE PROJECT_SOURCE_FILES "*.h" "*.hpp" "*.cpp") # I then wrote this Macro, which organize the files in visual studio folders, # according to the organization in the file systems macro(GroupSources curdir) file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*) foreach(child ${children}) if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child}) GroupSources(${curdir}/${child}) else() string(REPLACE "/" "\\" groupname ${curdir}) # I would like to call the src root folder in a different name, only in visual studio (not mandatory requirement) string(REPLACE "src" "Common" groupname ${groupname}) source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child}) endif() endforeach() endmacro() # Execute the macro GroupSources(src) add_library(${PROJECT_NAME} ${ PROJECT_SOURCE_FILES}) The result is a Visual studio project which organizes the files as I desired. However when I try to create new files with visual studio they are not stored in the folder I select, but in the out-of-source build folder. I guess this is due to the fact that visual studio doesn't now the mapping between src folder and source group. How can I achieve both my goals? Thanks in advace!
-- 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://www.cmake.org/mailman/listinfo/cmake