Commit 6a80480e authored by Jozef Legeny's avatar Jozef Legeny

core/cmake-modules:

+ added most common cmake modules



git-svn-id: svn://scm.gforge.inria.fr/svn/openvibe@3601 c330d7e9-fc0c-0410-a5b3-fd85c6f5aa8f
parent 18b59904
# ---------------------------------
# Finds third party boost
# Adds library to target
# Adds include path
# ---------------------------------
FIND_PATH(PATH_BOOST "include/boost/config/auto_link.hpp" PATHS ${OV_CUSTOM_DEPENDENCIES_PATH}/boost ${OV_CUSTOM_DEPENDENCIES_PATH} NO_DEFAULT_PATH)
FIND_PATH(PATH_BOOST "include/boost/config/auto_link.hpp" PATHS ${OV_CUSTOM_DEPENDENCIES_PATH}/boost)
IF(PATH_BOOST)
MESSAGE(STATUS " Found boost includes...")
INCLUDE_DIRECTORIES(${PATH_BOOST}/include)
ADD_DEFINITIONS(-DTARGET_HAS_Boost)
ELSE(PATH_BOOST)
MESSAGE(STATUS " FAILED to find boost includes...")
ENDIF(PATH_BOOST)
#
# Adds all directories as subdirectories to the CMake build, using the branch specified (if any) in the root CMakeList.txt or
# trunk otherwise.
#
# The branch variable name that is checked is made up from ${CURRENT_BRANCH_PREFIX}_${DIRNAMEUPPER}.
#
# The script also adds the directory to the global list of projects.
#
FUNCTION(OV_ADD_PROJECTS CURRENT_BRANCH_PREFIX)
FILE(GLOB FILENAMES "*")
FOREACH(FULLPATH ${FILENAMES})
IF(IS_DIRECTORY ${FULLPATH} AND NOT ${FULLPATH} MATCHES ".*\\.svn")
GET_FILENAME_COMPONENT(DIRNAME ${FULLPATH} NAME)
SET(OV_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${DIRNAME}")
STRING(TOUPPER ${DIRNAME} DIRNAMEUPPER)
SET(BRANCH_VARIABLE_NAME "${CURRENT_BRANCH_PREFIX}_${DIRNAMEUPPER}")
SET(SUBDIR "SUBDIR-NOTFOUND")
# MESSAGE(STATUS "Checking ${CURRENT_BRANCH_PREFIX}_${DIRNAMEUPPER} as branch var ${BRANCH_VARIABLE_NAME}")
IF(${BRANCH_VARIABLE_NAME})
SET(BRANCH ${${BRANCH_VARIABLE_NAME}})
IF("${BRANCH}" STREQUAL "__SKIPME")
MESSAGE(STATUS "Note: ${BRANCH_VARIABLE_NAME} has been disabled by setting it to __SKIPME")
ELSE("${BRANCH}" STREQUAL "__SKIPME")
SET(SUBDIR ${BRANCH})
ENDIF("${BRANCH}" STREQUAL "__SKIPME")
ELSE(${BRANCH_VARIABLE_NAME})
SET(SUBDIR ${OV_TRUNK})
ENDIF(${BRANCH_VARIABLE_NAME})
IF(SUBDIR)
#MESSAGE(STATUS "Inserting folder ${SUBDIR}")
# Add the dir to be parsed for documentation later. We need to do this before adding subdir, in case the subdir is the actual docs dir
GET_PROPERTY(OV_TMP GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS)
SET(OV_TMP "${OV_TMP};${FULLPATH}/${SUBDIR}")
SET_PROPERTY(GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS ${OV_TMP})
# MESSAGE(STATUS "BDIR ${OV_CURRENT_BINARY_DIR}/${SUBDIR}")
GET_PROPERTY(OV_TMP GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS_BUILD_DIR)
SET(OV_TMP "${OV_TMP};${OV_CURRENT_BINARY_DIR}/${SUBDIR}")
SET_PROPERTY(GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS_BUILD_DIR ${OV_TMP})
add_subdirectory(${FULLPATH}/${SUBDIR})
ENDIF(SUBDIR)
ENDIF(IS_DIRECTORY ${FULLPATH} AND NOT ${FULLPATH} MATCHES ".*\\.svn")
ENDFOREACH(FULLPATH ${FILENAMES})
ENDFUNCTION(OV_ADD_PROJECTS)
#
# This function is used to add a project to the build in the case where the current directory only contains
# 'branches', 'tags' and 'trunk' directories of a single project. The project will be added using the
# branch specified (if any) in the root CMakeList.txt or trunk otherwise.
#
# The branch variable name that is checked is made up from ${CURRENT_BRANCH_PREFIX}_${DIRNAMEUPPER}.
#
# The script also adds the directory to the global list of projects.
#
FUNCTION(OV_ADD_SINGLE_PROJECT CURRENT_BRANCH_PREFIX)
SET(BRANCH_VARIABLE_NAME "${CURRENT_BRANCH_PREFIX}")
# MESSAGE(STATUS "Parts ${CURRENT_BRANCH_PREFIX} Now ${BRANCH_VARIABLE_NAME}")
# MESSAGE(STATUS "Value ${${BRANCH_VARIABLE_NAME}}")
SET(SUBDIR "SUBDIR-NOTFOUND")
# MESSAGE(STATUS "Checking branch for ${BRANCH_VARIABLE_NAME}")
IF(${BRANCH_VARIABLE_NAME})
SET(BRANCH ${${BRANCH_VARIABLE_NAME}})
IF("${BRANCH}" STREQUAL "__SKIPME")
MESSAGE(STATUS "Note: ${BRANCH_VARIABLE_NAME} has been disabled by setting it to __SKIPME")
ELSE("${BRANCH}" STREQUAL "__SKIPME")
SET(SUBDIR "${BRANCH}")
ENDIF("${BRANCH}" STREQUAL "__SKIPME")
ELSE(${BRANCH_VARIABLE_NAME})
# MESSAGE(STATUS "Going for trunk...")
SET(SUBDIR "${OV_TRUNK}")
ENDIF(${BRANCH_VARIABLE_NAME})
IF(SUBDIR)
# MESSAGE(STATUS "Inserting folder ${SUBDIR}")
# Add the dir to be parsed for documentation later. We need to do this before adding subdir, in case the subdir is the actual docs dir.
GET_PROPERTY(OV_TMP GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS)
SET(OV_TMP "${OV_TMP};${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}")
SET_PROPERTY(GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS ${OV_TMP})
# MESSAGE(STATUS "BDIR ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIR}")
GET_PROPERTY(OV_TMP GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS_BUILD_DIR)
SET(OV_TMP "${OV_TMP};${CMAKE_CURRENT_BINARY_DIR}/${SUBDIR}")
SET_PROPERTY(GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS_BUILD_DIR ${OV_TMP})
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR})
ENDIF(SUBDIR)
ENDFUNCTION(OV_ADD_SINGLE_PROJECT)
#
# Creates launch script from a common OpenViBE template (in "cmake-modules/launchers/"), suitable for most apps
#
# The mandatory 1st argument SCRIPT_PREFIX specifies what the resulting script is called. A platform specific postfix will be added.
# The optional 2nd argument ARGV1 specifies some extra argument or switch that is given to the launched executable by the script
#
FUNCTION(OV_INSTALL_LAUNCH_SCRIPT SCRIPT_PREFIX)
IF(WIN32)
SET(SCRIPT_POSTFIX ".cmd")
ENDIF(WIN32)
IF(UNIX)
# Debian recommends that extensions such as .sh are not used; On Linux, scripts with such extensions shouldn't be packaged
SET(SCRIPT_POSTFIX ".sh")
ENDIF(UNIX)
# Extract the filename of the project executable, the variable in the script base will be replaced with it by CONFIGURE_FILE()
GET_TARGET_PROPERTY(TMP_PROJECT_TARGET_PATH ${PROJECT_NAME} LOCATION)
GET_FILENAME_COMPONENT(OV_CMD_EXECUTABLE ${TMP_PROJECT_TARGET_PATH} NAME)
SET(SCRIPT_NAME ${SCRIPT_PREFIX}${SCRIPT_POSTFIX})
# OV_CMD_ARGS, if present in the -base file, will be replaced by contents of ARGV1 (later by CONFIGURE_FILE)
IF(ARGC GREATER 1)
SET(OV_CMD_ARGS ${ARGV1})
ELSE(ARGC GREATER 1)
SET(OV_CMD_ARGS "")
ENDIF(ARGC GREATER 1)
CONFIGURE_FILE(${CMAKE_MODULE_PATH}/launchers/openvibe-launcher${SCRIPT_POSTFIX}-base ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT_NAME} @ONLY)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})
ENDFUNCTION(OV_INSTALL_LAUNCH_SCRIPT)
#
# Win32 only
#
# This concoction mainly exists to locate the boost libraries on WIN32 in the case where our dependency/ folder has only a
# truncated version of boost and we cannot use find_package(). The background story is that we wish to link explicitly
# instead of using automatic linking and specifying a generic boost path to linker before each project definition.
#
# The downside of this is that it assumes the boost library names to have a particular format and only works for VC90/VC100
#
# Function: Links specified boost library defined by COMPONENT and BOOST_VERSION to PROJECT_NAME.
#
FUNCTION(OV_LINK_BOOST_LIB BOOST_COMPONENT BOOST_VERSION)
IF(WIN32)
INCLUDE(CMakeDetermineVSServicePack)
DetermineVSServicePack( MSVC_SERVICE_PACK )
STRING(REGEX MATCH "vc90.*" MSVC_VER90 ${MSVC_SERVICE_PACK})
SET(LIB_BOOST "-NOTFOUND")
IF(MSVC_VER90)
SET(LIB_BOOST "libboost_${BOOST_COMPONENT}-vc90-mt-${BOOST_VERSION}.lib")
SET(LIB_BOOST_DEBUG "libboost_${BOOST_COMPONENT}-vc90-mt-gd-${BOOST_VERSION}.lib")
ENDIF(MSVC_VER90)
STRING(REGEX MATCH "vc100.*" MSVC_VER100 ${MSVC_SERVICE_PACK})
IF(MSVC_VER100)
SET(LIB_BOOST "libboost_${BOOST_COMPONENT}-vc100-mt-${BOOST_VERSION}.lib")
SET(LIB_BOOST_DEBUG "libboost_${BOOST_COMPONENT}-vc100-mt-gd-${BOOST_VERSION}.lib")
ENDIF(MSVC_VER100)
SET(LIB_BOOST_PATH "-NOTFOUND")
FIND_LIBRARY(LIB_BOOST_PATH NAMES ${LIB_BOOST} PATHS ${OV_CUSTOM_DEPENDENCIES_PATH}/boost/lib NO_DEFAULT_PATH)
IF(LIB_BOOST_PATH)
MESSAGE(STATUS " [ OK ] lib ${LIB_BOOST_PATH}")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} optimized ${LIB_BOOST_PATH})
ELSE(LIB_BOOST_PATH)
MESSAGE(STATUS " Unable to find boost ${LIB_BOOST}")
ENDIF(LIB_BOOST_PATH)
SET(LIB_BOOST_DEBUG_PATH "-NOTFOUND")
FIND_LIBRARY(LIB_BOOST_DEBUG_PATH NAMES ${LIB_BOOST_DEBUG} PATHS ${OV_CUSTOM_DEPENDENCIES_PATH}/boost/lib NO_DEFAULT_PATH)
IF(LIB_BOOST_DEBUG_PATH)
MESSAGE(STATUS " [ OK ] lib ${LIB_BOOST_DEBUG_PATH}")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} debug ${LIB_BOOST_DEBUG_PATH})
ELSE(LIB_BOOST_DEBUG_PATH)
MESSAGE(STATUS " Unable to find boost ${LIB_BOOST_DEBUG}")
ENDIF(LIB_BOOST_DEBUG_PATH)
ENDIF(WIN32)
ENDFUNCTION(OV_LINK_BOOST_LIB)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment