naive231
naive231

Reputation: 1380

Add sources from other paths don't have CMakeLists.txt, and move output files to other path in CMake

My source tree:

/project
/project/src/<my sources>
/project/build/vs2008
/project/build/ubuntu

I want to put my CMakeLists.txt in vs2008 and ubuntu. I can accept put one CMakeLists.txt to each folder and put another global CMakeLists.txt on /project/build, but I just don't want any CMakeLists.txt in /project/src(So I can't use add_subdirectory command). I need my solution files of visual studio in /project/build/vs2008 and Makefile in /project/build/ubuntu. What commands I should know about?

Upvotes: 1

Views: 419

Answers (1)

atsui
atsui

Reputation: 1018

I think there's nothing special you would need to know -- you just need to specify paths to your source files relative to where your CMakeLists.txt is located, and your targets should build the same as if you had placed CMakeLists.txt in your src folder. For example, project/build/ubuntu/CMakeLists.txt could look like this:

set( SrcDir ../../src )
add_executable( MyApp
    ${SrcDir}/file1.cpp
    ${SrcDir}/file2.cpp
    # and so on
)

Upvotes: 1

Related Questions