[CMake] newbie q - where do I put what in which CMakeLists file? out of source build

Michael Wild themiwi at gmail.com
Wed Mar 9 10:22:50 EST 2011


On 03/09/2011 04:14 PM, Pierre Abbat wrote:
> On Wednesday 09 March 2011 05:19:42 Johannes Zarl wrote:
>>> configure_file(src/config.h.in config.h)
>>
>> In CMake, use of relative filenames is (mostly) discouraged. A robust
>> way to do this would be to write:
>>
>> configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in
>>                 ${CMAKE_CURRENT_BINARY_DIRECTORY}/include/config.h )
>>
>> include_directories( ${CMAKE_CURRENT_BINARY_DIRECTORY}/include )
> 
> I got it to work, typing "cmake ../src" and leaving ~/tone12/CMakeLists.txt 
> empty. "INCLUDE_DIRECTORIES" has to be in all caps (at least I didn't see it 
> add -I when I had it in lowercase) and it's CMAKE_CURRENT_BINARY_DIR 
> (with ...DIRECTORY it tried to write to /include).
> 
> I ran "make package_source" and get a tarball containing the following:
> 
> -rw-r--r--  0 phma   phma     2460 Mar  9 15:07 
> tone12-0.1.1-Source/riffwave.cpp
> -rw-r--r--  0 phma   phma       65 Mar  9 15:07 
> tone12-0.1.1-Source/config.h.in
> -rw-r--r--  0 phma   phma     2316 Mar  9 15:07 tone12-0.1.1-Source/midi.h
> -rw-r--r--  0 phma   phma      384 Mar  9 15:07 
> tone12-0.1.1-Source/CMakeLists.txt~
> -rw-r--r--  0 phma   phma     2303 Mar  9 15:07 tone12-0.1.1-Source/midi.cpp
> -rw-r--r--  0 phma   phma      384 Mar  9 15:07 
> tone12-0.1.1-Source/CMakeLists.txt
> -rw-r--r--  0 phma   phma    10551 Mar  9 15:07 
> tone12-0.1.1-Source/tonegen.cpp
> -rw-r--r--  0 phma   phma    14625 Mar  9 15:07 
> tone12-0.1.1-Source/tone12.cpp~
> -rw-r--r--  0 phma   phma     2322 Mar  9 15:07 tone12-0.1.1-Source/midi.h~
> -rw-r--r--  0 phma   phma    14625 Mar  9 15:07 tone12-0.1.1-Source/tone12.cpp
> -rw-r--r--  0 phma   phma     1455 Mar  9 15:07 tone12-0.1.1-Source/riffwave.h
> -rw-r--r--  0 phma   phma     4339 Mar  9 15:07 tone12-0.1.1-Source/tonegen.h
> 
> Those should be tone12-0.1.1-Source/src/midi.h etc. How can I fix this?
> 
> Pierre

Make the ~/tone12/CMakeLists.txt your main CMake file (i.e. put the
project() command in there and all other commands that apply to the
whole project) and add a "add_subdirectory(src)" call, and then call
CMake with "cmake .." instead.

Also, the built-in commands, function and macro names are AFAIK
case-insensitive since the 2.6 days. I always use include_directories().

Michael


More information about the CMake mailing list