#-------------------------------------------------------------------------------- # This is an example project that uses CMake as a build system to compile a Qt4.x # based project. # To have CMake pick a Qt installation of your choice that won't be found # automatically, set the CMAKE_PREFIX_PATH environment variable. # For example: "export CMAKE_PREFIX_PATH=/usr/local/trolltech/qt4.3.5" # PROJECT (QtTest) cmake_minimum_required(VERSION 2.8) # ---------- Setup output Directories ------------------------- SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH "Single Directory for all Libraries" ) # --------- Setup the Executable output Directory ------------- SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH "Single Directory for all Executables." ) # --------- Setup the Executable output Directory ------------- SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH "Single Directory for all static libraries." ) SET (PROJECT_CODE_DIR ${PROJECT_SOURCE_DIR}/.) SET (PROJECT_RESOURCES_DIR ${PROJECT_SOURCE_DIR}/.) SET (PROJECT_PREFIX "xxx" CACHE STRING "The Prefix to be used for Preprocessor definitions") SET (EXE_DEBUG_EXTENSION "_debug") SET (PROJECT_INSTALL_HEADERS "0") SET (PROJECT_INSTALL_EXECUTABLES "1") #------------------------------------------------------------------------------- # Include the cmp project to perform all the basic configuration tests for the # project. #------------------------------------------------------------------------------- #set (CMP_HEADER_DIR ${AIMRepresentation_BINARY_DIR}/MXA) set (CMP_CONFIGURATION_FILE_NAME "CMPConfiguration.h") set (CMP_TYPES_FILE_NAME "CMPTypes.h") set (CMP_VERSION_HEADER_FILE_NAME "CMPVersion.h") set (CMP_EXTRA_CONFIGURATION_FILE "CMPConfiguration.h") set (CMP_PROJECT_NAMESPACE "CMP") set (CMP_PROJECT_NAME "QtTest") set (CMP_ENABLE_PLUGINS "0") set (CMP_LIB_SEARCH_DIRS "") INCLUDE (${PROJECT_RESOURCES_DIR}/cmp/cmpProject.cmake) #-------------------------------------------------------------------------------- # This is the list of source files that need to be compiled #-------------------------------------------------------------------------------- SET( QTTEST_SRCS main.cpp TestForm.cpp ) #-------------------------------------------------------------------------------- # another list, this time it includes all header files that should be treated with moc #-------------------------------------------------------------------------------- SET( QTTEST_MOC_HDRS TestForm.h ) #-------------------------------------------------------------------------------- # .ui files that are used in the project #-------------------------------------------------------------------------------- SET( QTTEST_UIS TestForm.ui ) #-------------------------------------------------------------------------------- # and finally any resource files. I do not have any in this example #-------------------------------------------------------------------------------- SET( QTTEST_RCS ) #-------------------------------------------------------------------------------- # This sets the windows build that will need the special winmain@16 call. Qt provides # this for us in the qtmain.lib file. Using this cmake code will ensure we have it # linked into our build. Not needed on Unix/OS X/Linux which is why we have the # IF(WIN32) conditional. IF (WIN32) SET (QT_USE_QTMAIN TRUE) ENDIF (WIN32) #-------------------------------------------------------------------------------- # this command finds Qt4 libraries and sets all required variables # note that it's Qt4, not QT4 or qt4 FIND_PACKAGE( Qt4 REQUIRED ) #-------------------------------------------------------------------------------- # QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to # a CMake script that sets up this directory for building with Qt4 INCLUDE( ${QT_USE_FILE} ) #-------------------------------------------------------------------------------- # this command will generate rules that will run rcc on all files from QTTEST_RCS # in result QTTEST_GEN_RCS variable will contain paths to files produced by rcc QT4_ADD_RESOURCES( QTTEST_GEN_RCS ${QTTEST_RCS} ) #-------------------------------------------------------------------------------- # this will run uic on .ui files: QT4_WRAP_UI( QTTEST_GEN_UIS ${QTTEST_UIS} ) #-------------------------------------------------------------------------------- # and finally this will run moc on the headers QT4_WRAP_CPP( QTTEST_GEN_MOC_HDRS ${QTTEST_MOC_HDRS} ) #-------------------------------------------------------------------------------- # we need this to be able to include headers produced by uic in our code # CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() # works just like INCLUDEPATH from qmake INCLUDE_DIRECTORIES ( # Look in the cmake build directory (some generated headers could be there) ${CMAKE_CURRENT_BINARY_DIR} ) #-------------------------------------------------------------------------------- # For Apple set the icns file containing icons IF(APPLE) # set how it shows up in the Info.plist file SET(MACOSX_BUNDLE_ICON_FILE QtTest.icns) # set where in the bundle to put the icns file SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/QtTest.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) # include the icns file in the target SET(QTTEST_SRCS ${QTTEST_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/QtTest.icns) if (0) ConfigureMacOSXBundlePlist(${PROJECT_NAME} ${EXE_DEBUG_EXTENSION} ${MACOSX_BUNDLE_ICON_FILE} "1.0.1" ) endif() ENDIF(APPLE) # file(READ ${PROJECT_BINARY_DIR}/Qt_Plugins.txt QT_PLUGINS) BuildQtAppBundle( TARGET ${PROJECT_NAME} SOURCES ${QTTEST_SRCS} ${QTTEST_GEN_MOC_HDRS} ${QTTEST_GEN_UIS} ${QTTEST_GEN_RCS} DEBUG_EXTENSION ${EXE_DEBUG_EXTENSION} ICON_FILE ${MACOSX_BUNDLE_ICON_FILE} VERSION_MAJOR ${CMP_VER_MAJOR} VERSION_MINOR ${CMP_VER_MINOR} VERSION_PATCH ${CMP_VER_PATCH} BINARY_DIR ${${PROJECT_NAME}_BINARY_DIR} LINK_LIBRARIES ${QT_LIBRARIES} LIB_SEARCH_DIRS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} # QT_PLUGINS ${QT_PLUGINS} # OTHER_PLUGINS ${OTHER_PLUGINS} COMPONENT Applications INSTALL_DEST "." ) #-------------------------------------------------------------------------------- # CMake's way of creating an executable #ADD_EXECUTABLE( QtTest MACOSX_BUNDLE WIN32 # ${QTTEST_SRCS} # ${QTTEST_GEN_MOC_HDRS} # ${QTTEST_GEN_UIS} # ${QTTEST_GEN_RCS} #) #-------------------------------------------------------------------------------- # Tell CMake which libraries we need to link our executable against. #TARGET_LINK_LIBRARIES ( QtTest ${QT_LIBRARIES} ) #-------------------------------------------------------------------------------- # Now the installation stuff below #-------------------------------------------------------------------------------- SET(plugin_dest_dir bin) SET(qtconf_dest_dir bin) SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/QtTest") IF(APPLE) SET(plugin_dest_dir QtTest.app/Contents/MacOS) SET(qtconf_dest_dir QtTest.app/Contents/Resources) SET(APPS "\${CMAKE_INSTALL_PREFIX}/QtTest.app") ENDIF(APPLE) IF(WIN32) SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/QtTest.exe") ENDIF(WIN32) #-------------------------------------------------------------------------------- # Install the QtTest application, on Apple, the bundle is at the root of the # install tree, and on other platforms it'll go into the bin directory. INSTALL(TARGETS QtTest BUNDLE DESTINATION . COMPONENT Runtime RUNTIME DESTINATION bin COMPONENT Runtime ) #-------------------------------------------------------------------------------- # Install needed Qt plugins by copying directories from the qt installation # One can cull what gets copied by using 'REGEX "..." EXCLUDE' INSTALL(DIRECTORY "${QT_PLUGINS_DIR}/imageformats" DESTINATION ${plugin_dest_dir}/plugins COMPONENT Runtime) #-------------------------------------------------------------------------------- # install a qt.conf file # this inserts some cmake code into the install script to write the file INSTALL(CODE " file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"\") " COMPONENT Runtime) #-------------------------------------------------------------------------------- # Use BundleUtilities to get all other dependencies for the application to work. # It takes a bundle or executable along with possible plugins and inspects it # for dependencies. If they are not system dependencies, they are copied. # directories to look for dependencies SET(DIRS ${QT_LIBRARY_DIRS}) # Now the work of copying dependencies into the bundle/package # The quotes are escaped and variables to use at install time have their $ escaped # An alternative is the do a configure_file() on a script and use install(SCRIPT ...). # Note that the image plugins depend on QtSvg and QtXml, and it got those copied # over. INSTALL(CODE " file(GLOB_RECURSE QTPLUGINS \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/plugins/*${CMAKE_SHARED_LIBRARY_SUFFIX}\") include(BundleUtilities) fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\") " COMPONENT Runtime) # To Create a package, one can run "cpack -G DragNDrop CPackConfig.cmake" on Mac OS X # where CPackConfig.cmake is created by including CPack # And then there's ways to customize this as well set(CPACK_BINARY_DRAGNDROP ON) include(CPack)