16
Basics of CMake and Git for a Hello Qt Application :Dinesh

Basicsof c make and git for a hello qt application

Embed Size (px)

DESCRIPTION

These are the slides i have used for my talk in http://ayana.pes.edu/speakers/

Citation preview

Page 1: Basicsof c make and git for a hello qt application

Basics of CMake and Git for a Hello Qt Application

:Dinesh

Page 2: Basicsof c make and git for a hello qt application

Hello world#include <stdio.h>#include <stdlib.h>#include <math.h>int main (int argc, char *argv[]){ if (argc < 2) { printf("Usage: %s number\n",argv[0]); return 1; } double inputValue = atof(argv[1]); double outputValue = sqrt(inputValue); printf("The square root of %g is %g\n", inputValue, outputValue); return 0;} /* How to Compile?---------------------------------------------------------------------------------------$ gcc -c hello.c$ gcc -o hello hello.o -lm*/

Page 3: Basicsof c make and git for a hello qt application

A little flashback...

Page 4: Basicsof c make and git for a hello qt application

Hello CMakeCMakeLists.txt: cmake_minimum_required (VERSION 2.6)project (Hello)add_executable(Hello hello.c)target_link_libraries(Hello m) --------------------------------------------------------------------------------------------------------# What to do? :$ mkdir build$ cd build$ cmake ..$ make

Page 5: Basicsof c make and git for a hello qt application

Other nice little things with CMake?IF (UNIX) CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/libvsxu.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libvsxu.pc @ONLY) INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/libvsxu.pc DESTINATION ${VSXU_INSTALL_LIB_DIR}/pkgconfig)ENDIF (UNIX)##################### find_package( OpenCV )if(OpenCV_FOUND) add_subdirectory(src/video.camera)endif(OpenCV_FOUND) #########################################For the make install...install (TARGETS MathFunctions DESTINATION bin)install (FILES MathFunctions.h DESTINATION include)

Page 6: Basicsof c make and git for a hello qt application

Hello Qt #include <QApplication> #include <QLabel>

int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel *label = new QLabel("Hello Qt!"); label->show(); return app.exec(); }/* How to Compile?---------------------------------------------------------------------------------------$ g++ -I/usr/include/qt4/QtGui -I/usr/include/qt4/ -c helloqt.cpp $ g++ -o helloqt helloqt.o -L/usr/lib/i386-linux-gnu -lQtCore -lQtGui -lpthread */

Page 7: Basicsof c make and git for a hello qt application

CMake to the rescue...cmake_minimum_required (VERSION 2.6)project (Hello)#Find our needed librariesfind_package(Qt4 REQUIRED) #Tell our compiler to get the headers from the found headersinclude(${QT_USE_FILE}) #Tell the compiler how to compile our codeadd_executable(HelloQt helloqt.cpp) #Tell the compiler to link our code with the found librariestarget_link_libraries(HelloQt ${QT_LIBRARIES})

Page 8: Basicsof c make and git for a hello qt application

And other Qt Modules?QT_DONT_USE_QTCOREQT_DONT_USE_QTGUIQT_USE_QT3SUPPORTQT_USE_QTASSISTANTQT_USE_QAXCONTAINERQT_USE_QAXSERVERQT_USE_QTDESIGNERQT_USE_QTMOTIFQT_USE_QTMAINQT_USE_QTNETWORKQT_USE_QTNSPLUGINQT_USE_QTOPENGLQT_USE_QTSQLQT_USE_QTXMLQT_USE_QTSVGQT_USE_QTTESTQT_USE_QTUITOOLSQT_USE_QTDBUSQT_USE_QTSCRIPTQT_USE_QTASSISTANTCLIENTQT_USE_QTHELPQT_USE_QTWEBKITQT_USE_QTXMLPATTERNSQT_USE_PHONON

# set (QT_USE_QTOPENGL TRUE)

Page 9: Basicsof c make and git for a hello qt application

But moc?

SET(foo_MOC_HDRS Class1.h Class2.h Class3.h)

# After this call, foo_MOC_SRCS = moc_Class1.cxx moc_Class2.cxx moc_Class3.cxx.QT4_WRAP_CPP(foo_MOC_SRCS ${foo_MOC_HDRS})

ADD_EXECUTABLE(foo ${foo_SRCS} ${foo_MOC_SRCS})

Page 10: Basicsof c make and git for a hello qt application

and uic and rcc?SET(qtproject_UIS main_window.ui)SET(QtApp_RCCS application.qrc)QT4_ADD_RESOURCES(QtApp_RCC_SRCS ${QtApp_RCCS})QT4_WRAP_UI(qtproject_UIS_H ${qtproject_UIS})# Don't forget to include output directory, otherwise the UI file won't be wrapped!include_directories(${CMAKE_CURRENT_BINARY_DIR})

#Now add these generated files to the ADD_EXECUTABLE step# If this is NOT done, then the ui_*.h files will not be generated

add_executable( qtproject ${qtproject_SRCS} ${qtproject_UIS_H} ${QtApp_RCC_SRCS})

Page 11: Basicsof c make and git for a hello qt application

Hello GitBecause this is just too ridiculous!

Page 12: Basicsof c make and git for a hello qt application

The Git object model...

Page 13: Basicsof c make and git for a hello qt application

So... git?#Creating an empty repository$git init # Viewing changes$ git diff$ git status # Asking git to store files$ git add hello.c # Finally Saving a state$ git commit -m "Commit Message" # Listing all branches$ git branch #Creating a Local branch$ git branch mywork #Switching to a local branch$ git checkout mywork # deleting a branch$ git branch -d mywork

Page 14: Basicsof c make and git for a hello qt application

and now... git merge$ git checkout mywork$ git merge origin

Page 15: Basicsof c make and git for a hello qt application

and... git rebase$ git checkout mywork$ git rebase origin

Page 16: Basicsof c make and git for a hello qt application

Useful resources:● http://www.cmake.org/cmake/help/cmake_tutorial.html

● http://qtnode.net/wiki/Qt4_with_cmake

● http://qt.nokia.com/learning/education/course-materials

● http://book.git-scm.com/3_distributed_workflows.html

● http://www.tenouk.com/ModuleW.html