AnyWave:PrepareCMake

From WikiMEG
Jump to: navigation, search

Basic CMake project

Create a folder that will be your plugin's project (for example MyPlugin).

Create the CMakeLists.txt file which is the CMake project file.
Here is an example of a CMakeLists.txt file:

# My plugin
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(MyPlugin)
# Build in release mode
SET(CMAKE_BUILD_TYPE "Release")
# Flags for gcc compiler and macro definitions 
ADD_DEFINITIONS("-fPIC -O3")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
 
# Check for SDK
SET(SDK_FOUND 0)
IF( "$ENV{AWSDK}" STREQUAL "" )
   MESSAGE(STATUS "AWSDK environment variable not set." )
   MESSAGE(STATUS "On Linux or Mac OS X this can be done in your user .bashrc file by appending the corresponding line, e.g:" )
   MESSAGE(STATUS "export AWSDK=/home/user/dev/SDK" )
   RETURN()
ELSE()
   SET(SDK_FOUND 1)
   SET(SDK_ROOT $ENV{AWSDK})
   MESSAGE(STATUS "AWSDK found: ${SDK_ROOT}")
ENDIF()
 
# Add the current folder as include directroy
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
 
# Link using SDK libraries
LINK_DIRECTORIES(${SDK_ROOT}/lib)
# Include SDK headers
INCLUDE_DIRECTORIES(${SDK_ROOT}/include)
# Include current source dir as header dir
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_DIR})
 
# Find Qt
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
# Add some definitions to point out that the project must build a Qt plugin
ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_SHARED)
 
# Define the output directory depending on platform
IF (APPLE)
   SET(LIBRARY_OUTPUT_PATH ${SDK_ROOT}/bin/Anywave_Plugins)
ELSE()
   SET(LIBRARY_OUTPUT_PATH ${SDK_ROOT}/bin/Plugins)
ENDIF()
 
 
# Plug-in specific part begins here
# Add source files for your project here:
# For example:
# SET(SRCS myplugin.cpp 
#   mylib.cpp)
 
# Add headers that need to be parse for Qt Signal and Slots mechanism.
# Those files need to be parse by the MOC tool of Qt to correctly compile signals and slots
# Example:
# SET(MOCS myplugin.h)
# Note that header files which are not describing Qt Objects won't be parse by the MOC tool.
 
 
# Depending on the plug-in type, your project may contain User Interfaces designed with the Qt Designer tool.
# To add UI files to your project, simply define a variable that will contain all the .ui files of your project.
# Example:
# SET(UIS myplugin.ui)
 
# Depending on the plug-in, your project may contain a Qt Resource file (.qrc)
# If so, add the file into a variable like this:
# QT4_ADD_RESOURCES(MyPlugin_QRC myplugin.qrc)
 
# Now call the MOC tool for header files
QT4_WRAP_CPP(MyPlugin_MOCS ${MOCS})
 
# If you have ui files, call the iuc tool:
# QT4_WRAP_UI(MyPlugin_UIS ${UIS})
 
# If your plug-in is using external libraries, you may define them here:
# Example of a plugin using the Qwt library
# SET(QWT_INCLUDE /home/dev/qwt/include)
# SET(QWT_LIB /home/dev/qwt/lib)
# INCLUDE_DIRECTORIES(${QWT_INCLUDE})
# LINK_DIRECTORIES(${QWT_LIB})
 
 
# define the library to build (the Qt Plugin)
ADD_LIBRARY(MyPlugin SHARED ${SRCS} ${MyPlugin_MOCS} ${MyPlugin_UIS} ${MyPlugin_QRC})
 
# remove ${MyPlugin_UIS} ${MyPlugin_QRC} if your project does not contain QRC or UI files
 
# Target
TARGET_LINK_LIBRARIES(MyPlugin AwCoreLib ${QT_LIBRARIES})
# This will tell cmake to link the plugin using AwCoreLib, which is the core library of AnyWave, and the Qt Libraries.
# Depending on your plug-in, extras libraries should be added.
# For example, if your plug-in is using graphics objects defined in the SDK, you must add AwGraphicsLib as a library.
# If the plug-in is a reader or a writer plug-in, you must add AwReadWriteLib
# If the plug-in is a signal processing plug-in, you must add AwProcessLib
 
# If your plugin must link with Qwt then the line should be:
#TARGET_LINK_LIBRARIES(MyPlugin AwCoreLib qwt ${QT_LIBRARIES})