[CMake] Using cmake first time..

John Drescher drescherjm at gmail.com
Thu Apr 30 08:17:45 EDT 2009


On Thu, Apr 30, 2009 at 12:46 AM, Usman Ajmal <uzmanajmal at gmail.com> wrote:
> Hi,
>
> I am not clear with this CMakeLists.txt as to how to create it automatically
> because i don't know the conventions related to it.
>
> I have a project named test.pro having following files
>
> treemap.cpp
> treemap.h
> main.cpp
>
> Libraries i am using are qt4, qt3support. The treemap.cpp comes from KDE
> sources so i will need to use some KDE libraries. Qmake is not working
> because it could not find kconfig.h, klocale.h and kdebug.h so i turned to
> cmake and now i don't now what CMakeLists.txt should be for my project.
>
> Any help will be a great relief for me.
>
How about an example. Last week I took the qt example simpletreemodel
and made a CMakeLists.txt file for it:

project(simpletreemodel)

cmake_minimum_required(VERSION 2.6)

FIND_PACKAGE( Qt4 REQUIRED )
INCLUDE( ${QT_USE_FILE} )

include_directories(Include)

SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all executables.")

SET( DEMO_SRCS
	./src/main.cpp
	./src/treemodel.cpp
	./src/treeitem.cpp
)

SET( DEMO_HDRS
	
)

SET( DEMO_MOC_HDRS
	./Include/treemodel.h
	./Include/treeitem.h
)

# some .ui files
SET( DEMO_UIS
)

# and finally an resource file
SET( DEMO_RCS
	./rc/simpletreemodel.qrc
)

# this command will generate rules that will run rcc on all files from DEMO_RCS
# in result DEMO_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( DEMO_RC_SRCS ${DEMO_RCS} )

# and finally this will run moc:
QT4_WRAP_CPP( DEMO_MOC_SRCS ${DEMO_MOC_HDRS} )

# this will run uic on .ui files:
QT4_WRAP_UI( DEMO_UI_HDRS ${DEMO_UIS} )

add_executable(simpletreemodel ${DEMO_SRCS}
    ${DEMO_MOC_SRCS}
	${DEMO_HDRS}
	${DEMO_MOC_HDRS}
	${DEMO_UI_HDRS}
	${DEMO_RC_SRCS}
)

target_link_libraries(simpletreemodel
	${QT_LIBRARIES}
)


More information about the CMake mailing list