[CMake] Understanding directory structure
Michael Hertling
mhertling at online.de
Sun Sep 5 00:15:43 EDT 2010
On 09/05/2010 12:04 AM, Joshua Warner wrote:
> Hi,
>
> I have a small language (written in C++) I'd like to convert to cmake, but
> I'm having a hard time figuring out what to do in which CMakeLists.txt file.
>
> Basically, I have the following directory structure:
>
> nvm/
> --tools/
> ----compiler/
> ------(C++ source)
> ----generator/
> ------(C++ source)
> --n/
> ----(".n" source)
> --src/
> ----(C++ source)
>
> Roughly, a build should go like this:
nvm/CMakeLists.txt:
ADD_SUBDIRECTORY(tools/compiler)
ADD_SUBDIRECTORY(tools/generator)
ADD_SUBDIRECTORY(n)
ADD_SUBDIRECTORY(src)
> 1. Compile the compiler (nvm/tools/compiler/*.cpp)
nvm/tools/compiler/CMakeLists.txt:
ADD_EXECUTABLE(compiler src1.cpp src2.cpp ...)
> 2. Use compiler to compile standard library (nvm/n/.../*.n) to framework.nc
nvm/n/CMakeLists.txt:
SET(NSRCS src1.n src2.n ...)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/framework.nc
COMMAND compiler -o ${CMAKE_BINARY_DIR}/framework.nc ${NSRCS}
DEPENDS ${NSRCS})
> 3. Compile the generator (nvm/tools/generator/*.cpp)
nvm/tools/generator/CMakeLists.txt:
ADD_EXECUTABLE(generator src1.cpp src2.cpp ...)
> 4. Use generator to generate framework.cpp and framework.h, from the
> compiled standard library (framework.nc)
nvm/n/CMakeLists.txt:
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/framework.cpp
${CMAKE_BINARY_DIR}/framework.h
COMMAND generator -source ${CMAKE_BINARY_DIR}/framework.cpp
-header ${CMAKE_BINARY_DIR}/framework.h
${CMAKE_BINARY_DIR}/framework.nc
DEPENDS ${CMAKE_BINARY_DIR}/framework.nc)
ADD_CUSTOM_TARGET(framework ALL
DEPENDS ${CMAKE_BINARY_DIR}/framework.cpp
${CMAKE_BINARY_DIR}/framework.h)
> 5. Compile vm (src/*.cpp & framework.cpp)
nvm/src/CMakeLists.txt:
ADD_EXECUTABLE(vm src1.cpp src2.cpp ...
${CMAKE_BINARY_DIR}/framework.cpp ${CMAKE_BINARY_DIR}/framework.h)
ADD_DEPENDENCIES(vm framework)
> Right now, I'm a bit confused as to which CMakeLists.txt file the rules for
> steps 2 and 4 should go.
Here, the crucial moment is the use of the custom target as a custom
command's output cannot be referred to from another CMakeLists.txt.
Hope that helps.
Regards,
Michael
More information about the CMake
mailing list