From: guigues Date: Fri, 26 Sep 2008 14:09:55 +0000 (+0000) Subject: Initial revision X-Git-Tag: start~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=596488a9529ffbedea2e6693e32e9b19f042b7e7;p=crea.git Initial revision --- 596488a9529ffbedea2e6693e32e9b19f042b7e7 diff --git a/AdditionalUsecrea.cmake.in b/AdditionalUsecrea.cmake.in new file mode 100644 index 0000000..78876a5 --- /dev/null +++ b/AdditionalUsecrea.cmake.in @@ -0,0 +1,4 @@ + +INCLUDE(${crea_CMAKE_DIR}/Macros.cmake) +INCLUDE(${crea_CMAKE_DIR}/creaResolveOptions.cmake) + diff --git a/AdditionalcreaConfig.cmake.in b/AdditionalcreaConfig.cmake.in new file mode 100644 index 0000000..5cfe716 --- /dev/null +++ b/AdditionalcreaConfig.cmake.in @@ -0,0 +1,26 @@ +#----------------------------------------------------------------------------- +SET(crea_CMAKE_REL_PATH @crea_CMAKE_REL_PATH@) +SET(crea_CMAKE_DIR ${crea_DIR}/${crea_CMAKE_REL_PATH}) +#----------------------------------------------------------------------------- +SET(crea_COMPILE_MESSAGES @crea_COMPILE_MESSAGES@) +SET(crea_COMPILE_DEBUG_MESSAGES @crea_COMPILE_DEBUG_MESSAGES@) +SET(crea_COMPILE_WARNING_MESSAGES @crea_COMPILE_WARNING_MESSAGES@) +SET(crea_COMPILE_ERROR_MESSAGES @crea_COMPILE_ERROR_MESSAGES@) +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +IF(crea_VERBOSE_FIND_LIBRARY) +# MESSAGE(STATUS "* crea_BUILT_WITH_WX = ${crea_BUILT_WITH_WX}") + MESSAGE(STATUS "* crea_CMAKE_DIR = ${crea_CMAKE_DIR}") + MESSAGE(STATUS "* crea_COMPILE_MESSAGES = ${crea_COMPILE_MESSAGES}") + MESSAGE(STATUS "* crea_COMPILE_WARNING_MESSAGES = ${crea_COMPILE_WARNING_MESSAGES}") + MESSAGE(STATUS "* crea_COMPILE_ERROR_MESSAGES = ${crea_COMPILE_ERROR_MESSAGES}") + MESSAGE(STATUS "* crea_COMPILE_DEBUG_MESSAGES = ${crea_COMPILE_DEBUG_MESSAGES}") +ENDIF(crea_VERBOSE_FIND_LIBRARY) +#----------------------------------------------------------------------------- + +# If bbtk was compiled with WxWidget then have to find it +#IF(crea_BUILT_WITH_WX) +# INCLUDE(${crea_CMAKE_DIR}/creaWxWidgets.cmake) +# crea_FIND_WXWIDGETS() +#ENDIF(crea_BUILT_WITH_WX) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a0ef9e8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,95 @@ +PROJECT(crea) + +SET(crea_CMAKE_REL_PATH cmake) +SET(crea_CMAKE_DIR ${PROJECT_SOURCE_DIR}/${crea_CMAKE_REL_PATH}) + +INCLUDE(${crea_CMAKE_DIR}/PreventInSourceBuild.cmake) + +INCLUDE(Version.cmake) + +INCLUDE(${crea_CMAKE_DIR}/Macros.cmake) + +SET(USE_VTK ON) +SET(USE_BOOST ON) +SET(USE_WXWIDGETS ON) + +INCLUDE(${crea_CMAKE_DIR}/FindAndUseLibraries.cmake) + +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) +MARK_AS_ADVANCED( + CMAKE_BACKWARDS_COMPATIBILITY + EXECUTABLE_OUTPUT_PATH + LIBRARY_OUTPUT_PATH + ) +#----------------------------------------------------------------------------- +# messages compilation options +OPTION ( crea_COMPILE_DEBUG_MESSAGES "Compile crea debug messages ?" OFF) +OPTION ( crea_COMPILE_ERROR_MESSAGES "Compile crea error messages ?" ON) +OPTION ( crea_COMPILE_MESSAGES "Compile crea messages ?" ON) +OPTION ( crea_COMPILE_WARNING_MESSAGES "Compile crea warning messages ?" ON) +#----------------------------------------------------------------------------- + +INCLUDE(${crea_CMAKE_DIR}/creaResolveOptions.cmake) + +SUBDIRS(cmake) +SUBDIRS(src) + +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/src) + +#----------------------------------------------------------------------------- +OPTION( BUILD_SAMPLES "Build samples ?" OFF) +IF(BUILD_SAMPLES) + SUBDIRS(samples) +ENDIF(BUILD_SAMPLES) +#----------------------------------------------------------------------------- + + +#----------------------------------------------------------------------------- +# Code installing the files needed to find the library +# with the cmake command FIND_PACKAGE +# Uses crea_INSTALL_LIBRARY_FOR_CMAKE macro +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# - Set the variable LIBRARY_NAME to the name of your library +SET(LIBRARY_NAME crea) + +SET(${LIBRARY_NAME}_INSTALL_FOLDER crea) +SET(${LIBRARY_NAME}_LIBRARIES crea) + +SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS src) + +IF(UNIX) + SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS + ${EXECUTABLE_OUTPUT_REL_PATH}) +ELSE(UNIX) + SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS + ${EXECUTABLE_OUTPUT_REL_PATH}/Debug + ${EXECUTABLE_OUTPUT_REL_PATH}/Release) +ENDIF(UNIX) + +SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/crea) +SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib) + +# OPTIONAL +# - Set the version of your library +# SET YOUR LIB VERSION +#SET(${LIBRARY_NAME}_MAJOR_VERSION 1) +#SET(${LIBRARY_NAME}_MINOR_VERSION 0) +#SET(${LIBRARY_NAME}_BUILD_VERSION 0) +# REQUIRED BUILD FLAGS +#SET(${LIBRARY_NAME}_REQUIRED_C_FLAGS "") +#SET(${LIBRARY_NAME}_REQUIRED_CXX_FLAGS "") +#SET(${LIBRARY_NAME}_REQUIRED_LINK_FLAGS "") +# ADDITIONAL CONFIG FILE +SET(${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE) +SET(${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE + ${PROJECT_SOURCE_DIR}/AdditionalcreaConfig.cmake.in) +SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE + ${PROJECT_SOURCE_DIR}/AdditionalUsecrea.cmake.in) + +# Invoke the macro +crea_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME}) +#----------------------------------------------------------------------------- diff --git a/Version.cmake b/Version.cmake new file mode 100644 index 0000000..f076797 --- /dev/null +++ b/Version.cmake @@ -0,0 +1,3 @@ +SET(crea_MAJOR_VERSION 1) +SET(crea_MINOR_VERSION 0) +SET(crea_BUILD_VERSION 0) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 0000000..3acc754 --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,19 @@ +FILE(GLOB crea_CMAKE_FILES "*.cmake" "*.in") +#MESSAGE(STATUS "cmake files = ${crea_CMAKE_FILES}") +FOREACH(file ${crea_CMAKE_FILES}) + GET_FILENAME_COMPONENT(filename "${file}" NAME) + CONFIGURE_FILE( + ${file} + ${CMAKE_CURRENT_BINARY_DIR}/${filename} + COPYONLY + ) +ENDFOREACH(file ${crea_CMAKE_FILES}) + +IF(UNIX) + SET(PREFIX lib/crea/) +ENDIF(UNIX) + +INSTALL( + FILES ${crea_CMAKE_FILES} + DESTINATION ${PREFIX}${crea_CMAKE_REL_PATH} + ) diff --git a/cmake/FindAndUseLibraries.cmake b/cmake/FindAndUseLibraries.cmake new file mode 100644 index 0000000..c738438 --- /dev/null +++ b/cmake/FindAndUseLibraries.cmake @@ -0,0 +1,210 @@ + + +#----------------------------------------------------------------------------- +IF(USE_VTK) + # Search VTK + FIND_PACKAGE(VTK) + # If vtk found + IF(VTK_FOUND) + MESSAGE ( STATUS "Looking for VTK... found") + MESSAGE ( STATUS "* Dir = ${VTK_DIR}") + MESSAGE ( STATUS "* Version = ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}") + INCLUDE(${VTK_USE_FILE}) + crea_DEFINE( USE_VTK ) + SET(VTK_LIBRARIES + vtkImaging vtkGraphics vtkRendering vtkFiltering vtkCommon vtkWidgets + vtkVolumeRendering + # LG : removed vtkIO because conflict with itktiff lib in ITKIO + ) + IF(NOT USE_ITK) + SET(VTK_LIBRARIES ${VTK_LIBRARIES} vtkIO) + ENDIF(NOT USE_ITK) + MARK_AS_ADVANCED(VTK_DIR) + ELSE(VTK_FOUND) + message(FATAL_ERROR "VTK_DIR not found") + ENDIF(VTK_FOUND) +ENDIF(USE_VTK) +#----------------------------------------------------------------------------- + + +#----------------------------------------------------------------------------- +IF(USE_ITK) + # Search ITK + FIND_PACKAGE(ITK) + # If itk found + IF(ITK_FOUND) + MESSAGE ( STATUS "Looking for ITK... found") + MESSAGE ( STATUS "* Dir = ${ITK_DIR}") + MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}") + INCLUDE(${ITK_USE_FILE}) + crea_DEFINE( USE_ITK ) + SET(ITK_LIBRARIES + ITKCommon ITKIO ITKBasicFilters ITKAlgorithms + ) + MARK_AS_ADVANCED(ITK_DIR) + # images compilation option + OPTION ( itk_IMAGE_DIM_2 "itk : Compile 2D images" ON) + OPTION ( itk_IMAGE_DIM_3 "itk : Compile 3D images" ON) + OPTION ( itk_IMAGE_DIM_4 "itk : Compile 4D images" ON) + OPTION ( itk_IMAGE_TYPE_CHAR "itk : Compile char images" ON) + OPTION ( itk_IMAGE_TYPE_UCHAR "itk : Compile unsigned char images" ON) + OPTION ( itk_IMAGE_TYPE_SHORT "itk : Compile short images" ON) + OPTION ( itk_IMAGE_TYPE_USHORT "itk : Compile unsigned short images" ON) + OPTION ( itk_IMAGE_TYPE_INT "itk : Compile int images" ON) + OPTION ( itk_IMAGE_TYPE_UINT "itk : Compile unsigned int images" ON) + OPTION ( itk_IMAGE_TYPE_FLOAT "itk : Compile float images" ON) + OPTION ( itk_IMAGE_TYPE_DOUBLE "itk : Compile double images" ON) + + IF ( itk_IMAGE_DIM_2 ) + crea_DEFINE( BBTK_ITK_IMAGE_DIM_2 ) + ENDIF ( itk_IMAGE_DIM_2 ) + + IF ( itk_IMAGE_DIM_3 ) + crea_DEFINE( BBTK_ITK_IMAGE_DIM_3 ) + ENDIF ( itk_IMAGE_DIM_3 ) + + IF ( itk_IMAGE_DIM_4 ) + crea_DEFINE( BBTK_ITK_IMAGE_DIM_4 ) + ENDIF ( itk_IMAGE_DIM_4 ) + + IF ( itk_IMAGE_TYPE_CHAR ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_int8_t ) + ENDIF ( itk_IMAGE_TYPE_CHAR ) + + IF ( itk_IMAGE_TYPE_UCHAR ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_uint8_t ) + ENDIF ( itk_IMAGE_TYPE_UCHAR ) + + IF ( itk_IMAGE_TYPE_SHORT ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_int16_t ) + ENDIF ( itk_IMAGE_TYPE_SHORT ) + + IF ( itk_IMAGE_TYPE_USHORT ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_uint16_t ) + ENDIF ( itk_IMAGE_TYPE_USHORT ) + + IF ( itk_IMAGE_TYPE_INT ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_int32_t ) + ENDIF ( itk_IMAGE_TYPE_INT ) + + IF ( itk_IMAGE_TYPE_UINT ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_uint32_t ) + ENDIF ( itk_IMAGE_TYPE_UINT ) + + IF ( itk_IMAGE_TYPE_FLOAT ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_float ) + ENDIF ( itk_IMAGE_TYPE_FLOAT ) + + IF ( itk_IMAGE_TYPE_DOUBLE ) + crea_DEFINE( BBTK_ITK_IMAGE_TYPE_double ) + ENDIF ( itk_IMAGE_TYPE_DOUBLE ) + ELSE(ITK_FOUND) + message(FATAL_ERROR "ITK_DIR not found") + ENDIF(ITK_FOUND) +ENDIF(USE_ITK) +#----------------------------------------------------------------------------- + + +#----------------------------------------------------------------------------- +IF(USE_GDCM) + # Search GDCM + FIND_PACKAGE(GDCM) + # If gdcm found + IF(GDCM_FOUND) + INCLUDE(${GDCM_USE_FILE}) + crea_DEFINE( USE_GDCM ) + + MESSAGE ( STATUS "Looking for GDCM... found") + MESSAGE ( STATUS "* Dir = ${GDCM_DIR}") + MESSAGE ( STATUS "* Version = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}") + MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}") + + # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with + # embedded gdcm in ITK and will result in hard seg faults ! + IF(USE_ITK) + IF (GDCM_NAME_SPACE STREQUAL "gdcm") + MESSAGE(FATAL_ERROR "GDCM_NAME_SPACE value is 'gdcm' which conflicts with ITK embededd gdcm namespace : rebuild gdcm with another GDCM_NAME_SPACE value") + ENDIF (GDCM_NAME_SPACE STREQUAL "gdcm") + ENDIF(USE_ITK) + + MARK_AS_ADVANCED(GDCM_DIR) + + SET(GDCM_LIBRARIES + ${GDCM_LIBRARIES} + ) + +# TODO : Test that GDCM was built with option "vtkgdcm" + IF(USE_GDCM_VTK) + IF(USE_VTK) + SET(GDCM_LIBRARIES + ${GDCM_LIBRARIES} + vtkgdcm + ) + ENDIF(USE_VTK) + ENDIF(USE_GDCM_VTK) + + ENDIF(GDCM_FOUND) +ENDIF(USE_GDCM) + +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +IF(USE_WXWIDGETS) + INCLUDE(${crea_CMAKE_DIR}/wxWidgetsMacros.cmake) + crea_FIND_WXWIDGETS() + crea_USE_WXWIDGETS() +ENDIF(USE_WXWIDGETS) +#----------------------------------------------------------------------------- + + + +#----------------------------------------------------------------------------- +IF(USE_DOXYGEN) + FIND_PACKAGE(Doxygen REQUIRED) +# MESSAGE(STATUS "Looking for doxygen... - found ${DOXYGEN}") + # IF(DOXYGEN) +# +# ELSE(DOXYGEN) +# MESSAGE(FATAL_ERROR "Doxygen not found. Required to build the doxygen documentation") +# ENDIF(DOXYGEN) +ENDIF(USE_DOXYGEN) +#----------------------------------------------------------------------------- + + +#----------------------------------------------------------------------------- +IF(USE_LATEX) + FIND_PACKAGE(LATEX REQUIRED) + MESSAGE(STATUS "Looking for latex... - found ${LATEX_COMPILER}") +ENDIF(USE_LATEX) +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +IF(USE_TTH) + FIND_FILE(LATEX_tth_CONVERTER NAME tth tth.exe PATHS . $ENV{CREATIS}/tth_exe/ ~/Creatis/tth ~/Creatis/tth_linux) + IF (NOT LATEX_tth_CONVERTER) + MESSAGE(FATAL_ERROR "TTH not found (LATEX_tth_CONVERTER). Required to build the HTML documentation from tex source") + ELSE (NOT LATEX_tth_CONVERTER) + MESSAGE(STATUS "Looking for tth... - found ${LATEX_tth_CONVERTER}") + ENDIF(NOT LATEX_tth_CONVERTER) + MARK_AS_ADVANCED(LATEX_tth_CONVERTER) +ENDIF(USE_TTH) +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +IF(USE_BOOST) + FIND_PACKAGE(Boost REQUIRED) + MARK_AS_ADVANCED(Boost_INCLUDE_DIR) + IF(Boost_FOUND) + MESSAGE(STATUS "Looking for boost C++ library... - found in ${Boost_INCLUDE_DIR}") + INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) + LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS} ) + crea_DEFINE( USE_BOOST ) + SET(BOOST_LIBRARIES + boost_signals + boost_filesystem + ) + ELSE(Boost_FOUND) + MESSAGE(FATAL_ERROR "boost C++ library not found - Set Boost_INCLUDE_DIR to the directory containing boost headers") + ENDIF(Boost_FOUND) +ENDIF(USE_BOOST) +#----------------------------------------------------------------------------- diff --git a/cmake/FindGTK2.cmake b/cmake/FindGTK2.cmake new file mode 100644 index 0000000..dcd23fe --- /dev/null +++ b/cmake/FindGTK2.cmake @@ -0,0 +1,331 @@ + +IF (GTK2_LIBRARIES AND GTK2_INCLUDE_DIRS) + # in cache already + SET(GTK2_FOUND TRUE) +ELSE (GTK2_LIBRARIES AND GTK2_INCLUDE_DIRS) + IF(UNIX) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + INCLUDE(UsePkgConfig) + + PKGCONFIG(gtk-2.0 _GTK22IncDir _GTK22LinkDir _GTK22LinkFlags _GTK22Cflags) + + FIND_PATH(GTK2_GTK_INCLUDE_PATH gtk/gtk.h + $ENV{GTK2_HOME} + ${_GTK22IncDir} + /usr/include/gtk-2.0 + /usr/local/include/gtk-2.0 + /opt/include/gtk-2.0 + /opt/gnome/include/gtk-2.0 + /sw/include/gtk-2.0 + ) + + # Some Linux distributions (e.g. Red Hat) have glibconfig.h + # and glib.h in different directories, so we need to look + # for both. + # - Atanas Georgiev + PKGCONFIG(glib-2.0 _GLIB2IncDir _GLIB2inkDir _GLIB2LinkFlags _GLIB2Cflags) + PKGCONFIG(gmodule-2.0 _GMODULE2IncDir _GMODULE2inkDir _GMODULE2LinkFlags _GMODULE2Cflags) + SET(GDIR /opt/gnome/lib/glib-2.0/include) + + FIND_PATH(GTK2_GLIBCONFIG_INCLUDE_PATH glibconfig.h + ${_GLIB2IncDir} + /opt/gnome/lib64/glib-2.0/include + /opt/gnome/lib/glib-2.0/include + /opt/lib/glib-2.0/include + /usr/lib64/glib-2.0/include + /usr/lib/glib-2.0/include + /sw/lib/glib-2.0/include + ) + #MESSAGE(STATUS "DEBUG: GTK2_GLIBCONFIG_INCLUDE_PATH = ${GTK2_GLIBCONFIG_INCLUDE_PATH}") + + FIND_PATH(GTK2_GLIB_INCLUDE_PATH glib.h + ${_GLIB2IncDir} + /opt/include/glib-2.0 + /opt/gnome/include/glib-2.0 + /usr/include/glib-2.0 + /sw/include/glib-2.0 + ) + #MESSAGE(STATUS "DEBUG: GTK2_GLIBCONFIG_INCLUDE_PATH = ${GTK2_GLIBCONFIG_INCLUDE_PATH}") + + FIND_PATH(GTK2_GTKGL_INCLUDE_PATH gtkgl/gtkglarea.h + ${_GLIB2IncDir} + /usr/include + /usr/local/include + /usr/openwin/share/include + /opt/gnome/include + /opt/include + /sw/include + ) + + PKGCONFIG(pango _PANGOIncDir _PANGOinkDir _PANGOLinkFlags _PANGOCflags) + + FIND_PATH(GTK2_PANGO_INCLUDE_PATH pango/pango.h + ${_PANGOIncDir} + /opt/gnome/include/pango-1.0 + /opt/include/pango-1.0 + /usr/include/pango-1.0 + /sw/include/pango-1.0 + ) + + PKGCONFIG(gdk-2.0 _GDK2IncDir _GDK2inkDir _GDK2LinkFlags _GDK2Cflags) + + FIND_PATH(GTK2_GDKCONFIG_INCLUDE_PATH gdkconfig.h + ${_GDK2IncDir} + /opt/gnome/lib/gtk-2.0/include + /opt/gnome/lib64/gtk-2.0/include + /opt/lib/gtk-2.0/include + /usr/lib/gtk-2.0/include + /usr/lib64/gtk-2.0/include + /sw/lib/gtk-2.0/include + ) + + # Dave: + FIND_PATH(GTK2_GDK_INCLUDE_PATH gdk.h + ${_GDK2IncDir} + /usr/include/gtk-2.0 + /usr/include/gtk-2.0/gdk + ) + #MESSAGE(STATUS "DEBUG: GTK2_GLIBCONFIG_INCLUDE_PATH = ${GTK2_GLIBCONFIG_INCLUDE_PATH}") + + PKGCONFIG(cairo _CAIROIncDir _CAIROinkDir _CAIROLinkFlags _CAIROCflags) + + FIND_PATH(GTK2_CAIRO_INCLUDE_PATH cairo.h + ${_CAIROIncDir} + /opt/gnome/include/cairo + /usr/include + /usr/include/cairo + /opt/include + /opt/include/cairo + /sw/include + /sw/include/cairo + ) + #MESSAGE(STATUS "DEBUG: GTK2_CAIRO_INCLUDE_PATH = ${GTK2_CAIRO_INCLUDE_PATH}") + + PKGCONFIG(atk _ATKIncDir _ATKinkDir _ATKLinkFlags _ATKCflags) + + FIND_PATH(GTK2_ATK_INCLUDE_PATH atk/atk.h + ${_ATKIncDir} + /opt/gnome/include/atk-1.0 + /usr/include/atk-1.0 + /opt/include/atk-1.0 + /sw/include/atk-1.0 + ) + #MESSAGE(STATUS "DEBUG: GTK2_ATK_INCLUDE_PATH = ${GTK2_ATK_INCLUDE_PATH}") + + FIND_LIBRARY(GTK2_GTKGL_LIBRARY + NAMES + gtkgl + PATHS + ${_GTK22IncDir} + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_GTK_LIBRARY + NAMES + gtk-x11-2.0 + PATHS + ${_GTK22LinkDir} + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_GDK_LIBRARY + NAMES + gdk-x11-2.0 + PATHS + ${_GDK2LinkDir} + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_GMODULE_LIBRARY + NAMES + gmodule-2.0 + PATHS + ${_GMODULE2inkDir} + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_GLIB_LIBRARY + NAMES + glib-2.0 + PATHS + ${_GLIB2inkDir} + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_Xi_LIBRARY + NAMES + Xi + PATHS + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + FIND_LIBRARY(GTK2_GTHREAD_LIBRARY + NAMES + gthread-2.0 + PATHS + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + + FIND_LIBRARY(GTK2_GOBJECT_LIBRARY + NAMES + gobject-2.0 + PATHS + /usr/lib + /usr/local/lib + /usr/openwin/lib + /usr/X11R6/lib + /opt/gnome/lib + /opt/lib + /sw/lib + ) + + IF(GTK2_GTK_INCLUDE_PATH) + IF(GTK2_GLIBCONFIG_INCLUDE_PATH) + IF(GTK2_GLIB_INCLUDE_PATH) + IF(GTK2_GTK_LIBRARY) + IF(GTK2_GLIB_LIBRARY) + IF(GTK2_PANGO_INCLUDE_PATH) + IF(GTK2_ATK_INCLUDE_PATH) + IF(GTK2_CAIRO_INCLUDE_PATH) + # Assume that if gtk and glib were found, the other + # supporting libraries have also been found. + + SET(GTK2_FOUND TRUE) + + SET(GTK2_INCLUDE_DIRS + ${GTK2_GTK_INCLUDE_PATH} + ${GTK2_GLIBCONFIG_INCLUDE_PATH} + ${GTK2_GLIB_INCLUDE_PATH} + ${GTK2_PANGO_INCLUDE_PATH} + ${GTK2_GDKCONFIG_INCLUDE_PATH} + # Dave: + ${GTK2_GDK_INCLUDE_PATH} + ${GTK2_ATK_INCLUDE_PATH} + ${GTK2_CAIRO_INCLUDE_PATH} + ) + + SET(GTK2_LIBRARIES + ${GTK2_GTK_LIBRARY} + ${GTK2_GDK_LIBRARY} + ${GTK2_GLIB_LIBRARY} + ) + #${GTK2_GOBJECT_LIBRARY}) + + IF(GTK2_GMODULE_LIBRARY) + SET(GTK2_LIBRARIES + ${GTK2_LIBRARIES} + ${GTK2_GMODULE_LIBRARY} + ) + ENDIF(GTK2_GMODULE_LIBRARY) + + IF(GTK2_GTHREAD_LIBRARY) + SET(GTK2_LIBRARIES + ${GTK2_LIBRARIES} + ${GTK2_GTHREAD_LIBRARY} + ) + SET(GTK2_LIBRARIES ${GTK2_LIBRARIES}) + ENDIF(GTK2_GTHREAD_LIBRARY) + ELSE(GTK2_CAIRO_INCLUDE_PATH) + MESSAGE(STATUS "Can not find cairo") + ENDIF(GTK2_CAIRO_INCLUDE_PATH) + ELSE(GTK2_ATK_INCLUDE_PATH) + MESSAGE(STATUS "Can not find atk") + ENDIF(GTK2_ATK_INCLUDE_PATH) + ELSE(GTK2_PANGO_INCLUDE_PATH) + MESSAGE(STATUS "Can not find pango includes") + ENDIF(GTK2_PANGO_INCLUDE_PATH) + ELSE(GTK2_GLIB_LIBRARY) + MESSAGE(STATUS "Can not find glib lib") + ENDIF(GTK2_GLIB_LIBRARY) + ELSE(GTK2_GTK_LIBRARY) + MESSAGE(STATUS "Can not find gtk lib") + ENDIF(GTK2_GTK_LIBRARY) + ELSE(GTK2_GLIB_INCLUDE_PATH) + MESSAGE(STATUS "Can not find glib includes") + ENDIF(GTK2_GLIB_INCLUDE_PATH) + ELSE(GTK2_GLIBCONFIG_INCLUDE_PATH) + MESSAGE(STATUS "Can not find glibconfig") + ENDIF(GTK2_GLIBCONFIG_INCLUDE_PATH) + ELSE (GTK2_GTK_INCLUDE_PATH) + MESSAGE(STATUS "Can not find gtk includes") + ENDIF (GTK2_GTK_INCLUDE_PATH) + + IF (GTK2_FOUND) + IF (NOT GTK2_FIND_QUIETLY) + MESSAGE(STATUS "Looking for gtk2... - found ${GTK2_LIBRARIES}") + ENDIF (NOT GTK2_FIND_QUIETLY) + ELSE (GTK2_FOUND) + IF (GTK2_FIND_REQUIRED) + MESSAGE(SEND_ERROR "Could NOT find GTK2") + ENDIF (GTK2_FIND_REQUIRED) + ENDIF (GTK2_FOUND) + + MARK_AS_ADVANCED( + GTK2_GDK_LIBRARY + GTK2_GLIB_INCLUDE_PATH + GTK2_GLIB_LIBRARY + GTK2_GLIBCONFIG_INCLUDE_PATH + GTK2_GMODULE_LIBRARY + GTK2_GTHREAD_LIBRARY + GTK2_Xi_LIBRARY + GTK2_GTK_INCLUDE_PATH + GTK2_GTK_LIBRARY + GTK2_GTKGL_INCLUDE_PATH + GTK2_GTKGL_LIBRARY + GTK2_ATK_INCLUDE_PATH + GTK2_GDKCONFIG_INCLUDE_PATH + # Dave: + GTK2_GDK_INCLUDE_PATH + #GTK2_GOBJECT_LIBRARY + GTK2_PANGO_INCLUDE_PATH + # LG : + GTK2_CAIRO_INCLUDE_PATH + GTK2_GOBJECT_LIBRARY + ) + ENDIF(UNIX) +ENDIF (GTK2_LIBRARIES AND GTK2_INCLUDE_DIRS) + diff --git a/cmake/FindWxWidgetsWin32.cmake b/cmake/FindWxWidgetsWin32.cmake new file mode 100644 index 0000000..a03d731 --- /dev/null +++ b/cmake/FindWxWidgetsWin32.cmake @@ -0,0 +1,573 @@ +# +# FindwxW.cmake +# v1.06 2006-03-27 +# Jerry Fath 2005 +# Based on work by Jorgen Bodde +# +# This module finds if wxWindows is installed and determines where the +# include files and libraries are. It also determines what the name of +# the library is. This code sets the following variables: +# +# WXWIDGETS_FOUND = wxWidgets was found +# WXWIDGETS_ROOT_DIR = base wxWidgets directory +# WXWIDGETS_LINK_DIRECTORIES = link directories, useful for rpath on Unix +# WXWIDGETS_LIBRARIES = all the wxWindows libraries ( and linker flags on unix ) +# WXWIDGETS_CXX_FLAGS = compiler flags for building wxWindows +# WXWIDGETS_EXE_LINKER_FLAGS = compiler flags for building wxWindows +# WXWIDGETS_INCLUDE_DIR = all include path of wxWindows +# WXWIDGETS_DEFINITIONS = all flags of wxWindows +# +# WXWIDGETS_RELEASE_LIBRARIES = release wxWindows libraries (Win32 only) +# WXWIDGETS_DEBUG_LIBRARIES = debug wxWindows libraries (Win32 only) +# WXWIDGETS_COMMON_LIBRARIES = libraries common to Release and Debug (Win32 only) + +# NOTE: This module REQUIRES that an environment variable named WXWIN +# be set to the base wxWidgets installation directory. +# Under Unix, you must also set and environment variable named WXWINCFG +# to the name of the active build subdirectory (eg buildgtk). As an alternative +# to the WXWINCFG environment variable, you can set a sym link in the wxWidgets +# root directory called wx-config which points to the active build subdirectory. +# + +# These variable should be set before including this module +# +# WXWIDGETS_FILE_VERSION (26) +# WXWIDGETS_VERSION (2.6) +# +# + +####################### EXAMPLE CMakeLists.txt ################### +# +##Required project specific settings +#PROJECT( myprojectname ) +#SET(PROJECT_SOURCE_FILES myfile.cpp myfile2.cpp) +#IF( WIN32) +# SET(PROJECT_RC_FILE myresfile.rc) +#ELSE( WIN32) +# SET(PROJECT_RC_FILE "") +#ENDIF( WIN32) +# +##Optional project specific settings +#SET(PROJECT_DEFINITIONS -D_MYPROJECT_ -D_MYPROJECT2_) +#SET(PROJECT_INCLUDE_PATH e:/myproject/include e:/myproject2/include) +#SET(PROJECT_LINK_DIRECTORIES e:/myproject/lib e:/myproject2/lib) +#SET(PROJECT_LIBRARIES myprojectlib myproject2lib) +# +##wxWidgets build related stuff +#SET(WXW_USE_DEBUG OFF) +#SET(WXW_USE_UNICODE OFF) +#SET(WXW_USE_SHARED OFF) +#SET(WXW_USE_UNIV OFF) +#SET(WXW_USE_MONO OFF) +#SET(WXW_FILE_VERSION "26") +#SET(WXW_VERSION "2.6") +# +#INCLUDE (FindwxW) +#INCLUDE (UsewxW) +# +####################### END EXAMPLE CMakeLists.txt ################### + +# +# Set WX_USE vars in CMakeLists if you don't want to default to all off +# +SET(WXWIDGETS_USE_DEBUG ${WXW_USE_DEBUG} CACHE BOOL "Use Debug versions of wxWindows libraries") +SET(WXWIDGETS_USE_UNICODE ${WXW_USE_UNICODE} CACHE BOOL "Use Unicode versions of wxWindows libraries") +SET(WXWIDGETS_USE_SHARED ${WXW_USE_SHARED} CACHE BOOL "Use shared versions of wxWindows libraries") +SET(WXWIDGETS_USE_UNIV ${WXW_USE_UNIV} CACHE BOOL "Use Universal versions of wxWindows libraries") +SET(WXWIDGETS_USE_MONO ${WXW_USE_MONO} CACHE BOOL "Use monolithic versions of wxWindows libraries") + +# +# Style can be non-Win32 even under Windows when using MinGW +# +IF(WIN32) + SET(WIN32_STYLE_FIND 1) +ENDIF(WIN32) +IF(MINGW) + SET(WIN32_STYLE_FIND 0) + SET(UNIX_STYLE_FIND 1) +ENDIF(MINGW) +IF(UNIX) + SET(UNIX_STYLE_FIND 1) +ENDIF(UNIX) + +# +# Versions should be set before this file is included. If not, +# default to 2.6 +# +IF(WXW_FILE_VERSION) + SET( WXVERSIONSUFFIX ${WXW_FILE_VERSION}) +ELSE(WXW_FILE_VERSION) + SET( WXVERSIONSUFFIX "26") +ENDIF(WXW_FILE_VERSION) + +IF(WXW_VERSION) + SET( WXVERSION ${WXW_VERSION}) +ELSE(WXW_VERSION) + SET( WXVERSION "2.6") +ENDIF(WXW_VERSION) + +# +# Find the base wxWidgets install path +# NOTE: WXWIN must be set +# +FIND_PATH( WXWIDGETS_ROOT_DIR + wx-config.in + $ENV{WXWIN} +) +IF(WXWIDGETS_ROOT_DIR STREQUAL "WXWIDGETS_ROOT_DIR-NOTFOUND") + MESSAGE( FATAL_ERROR "FATAL_ERROR: wx-config.in NOT found. Set WXWIN") +ENDIF(WXWIDGETS_ROOT_DIR STREQUAL "WXWIDGETS_ROOT_DIR-NOTFOUND") +SET(WXWIDGETS_CONFIG_PATH ${WXWIDGETS_ROOT_DIR}) + +# +# Find library path (platform specific) +# +IF( WIN32_STYLE_FIND ) + + IF( WXWIDGETS_USE_SHARED ) + SET(WXWIDGETS_LIB_PATH "${WXWIDGETS_ROOT_DIR}/lib/vc_dll" ) + ELSE( WXWIDGETS_USE_SHARED ) + SET(WXWIDGETS_LIB_PATH "${WXWIDGETS_ROOT_DIR}/lib/vc_lib" ) + ENDIF( WXWIDGETS_USE_SHARED ) + SET( WXWIDGETS_LINK_DIRECTORIES ${WXWIDGETS_LIB_PATH} ) + +ELSE( WIN32_STYLE_FIND ) + IF (UNIX_STYLE_FIND) + + # + # Unix uses a config specific directory under the install path + # specified in the WXWINCFG environment variable. + # If the WXWINCFG variable isn't set, we try a sym link within + # the WX root dir called wx-config, or the current PATH + # + FIND_PROGRAM( WX_WXCONFIG_EXECUTABLE + wx-config + "${WXWIDGETS_ROOT_DIR}/$ENV{WXWINCFG}" + "${WXWIDGETS_ROOT_DIR}/wx-config" ) + # + # Check wether wx-config can be found + # + IF(NOT EXISTS ${WX_WXCONFIG_EXECUTABLE}) + # we really need wx-config... + MESSAGE(FATAL_ERROR "FATAL_ERROR: Cannot find wx-config. Set WXWIN and WXWINCFG environment variables.") + ENDIF(NOT EXISTS ${WX_WXCONFIG_EXECUTABLE}) + + GET_FILENAME_COMPONENT( WXWIDGETS_CONFIG_PATH + WX_WXCONFIG_EXECUTABLE + PATH ) + + SET(WXWIDGETS_LIB_PATH "${WXWIDGETS_CONFIG_PATH}/lib" ) + SET( WXWIDGETS_LINK_DIRECTORIES ${WXWIDGETS_LIB_PATH} ) + + ELSE(UNIX_STYLE_FIND) + MESSAGE(FATAL_ERROR "FATAL_ERROR: FindwxWindows.cmake: Platform unsupported by FindwxW.cmake. It's neither WIN32 nor UNIX") + ENDIF(UNIX_STYLE_FIND) +ENDIF( WIN32_STYLE_FIND ) + +# +# Check options against installed libraries +# +SET(WX_CONFIG_ARGS "") +SET( LIBRARYWANT "${WXWIDGETS_LIB_PATH}/msw" ) + +IF( WXWIDGETS_USE_UNIV ) + SET( LIBRARYWANT "${LIBRARYWANT}univ") + SET( PFUNIV "univ" ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --universal=yes") +ELSE( WXWIDGETS_USE_UNIV ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --universal=no") +ENDIF( WXWIDGETS_USE_UNIV ) + +IF( WXWIDGETS_USE_UNICODE ) + SET( LIBRARYWANT "${LIBRARYWANT}u" ) + SET( PFUNICODE "u" ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --unicode=yes") +ELSE( WXWIDGETS_USE_UNICODE ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --unicode=no") +ENDIF( WXWIDGETS_USE_UNICODE ) + +IF( WXWIDGETS_USE_DEBUG ) + SET( PFDEBUG "d" ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --debug=yes") +ELSE( WXWIDGETS_USE_DEBUG ) + SET( PFDEBUG "" ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --debug=no") +ENDIF( WXWIDGETS_USE_DEBUG ) + +IF( WXWIDGETS_USE_SHARED ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --static=no") +ELSE( WXWIDGETS_USE_SHARED ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS} --static=yes") +ENDIF( WXWIDGETS_USE_SHARED ) + +# Not sure how to check this yet!!!!! +IF( WXWIDGETS_USE_MONO ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS}") +ELSE( WXWIDGETS_USE_MONO ) + SET(WX_CONFIG_ARGS "${WX_CONFIG_ARGS}") +ENDIF( WXWIDGETS_USE_MONO ) + +SET(WX_CONFIG_ARGS_LIBS "${WX_CONFIG_ARGS} --libs") + +# +# Platform specific method for testing installed wx Builds +# +IF( WIN32_STYLE_FIND ) + + # + # See if we have both release and debug wx versions + # + SET ( WX_DEBUGANDRELEASE FALSE ) + IF( EXISTS "${LIBRARYWANT}/wx/setup.h" ) + IF( EXISTS "${LIBRARYWANT}d/wx/setup.h" ) + SET ( WX_DEBUGANDRELEASE TRUE ) + ENDIF( EXISTS "${LIBRARYWANT}d/wx/setup.h" ) + ENDIF( EXISTS "${LIBRARYWANT}/wx/setup.h" ) + + SET( LIBRARYWANT "${LIBRARYWANT}${PFDEBUG}" ) + IF( NOT EXISTS "${LIBRARYWANT}/wx/setup.h" ) + MESSAGE( SEND_ERROR "ERROR: WXWidgets config NOT found ${WX_CONFIG_ARGS}") + ENDIF( NOT EXISTS "${LIBRARYWANT}/wx/setup.h" ) + +ELSE( WIN32_STYLE_FIND ) + + EXEC_PROGRAM(${WX_WXCONFIG_EXECUTABLE} + ARGS ${WX_CONFIG_ARGS_LIBS} + OUTPUT_VARIABLE WXWIDGETS_LIBRARIES + RETURN_VALUE BAD_WXCONFIG ) + IF(BAD_WXCONFIG) + MESSAGE( SEND_ERROR "ERROR: WXWidgets config NOT found ${WX_CONFIG_ARGS}") + ENDIF(BAD_WXCONFIG) + +ENDIF( WIN32_STYLE_FIND ) + +# +# Get compiler flags +# +IF( WIN32_STYLE_FIND ) + # Not used for Windows + SET( WXWIDGETS_CXX_FLAGS "" ) +ELSE( WIN32_STYLE_FIND ) + # + # Get CXXFLAGS from wx-config + # + EXEC_PROGRAM(${WX_WXCONFIG_EXECUTABLE} + ARGS "--cxxflags" + OUTPUT_VARIABLE WXWIDGETS_CXX_FLAGS + RETURN_VALUE BAD_WXCONFIG ) + IF (BAD_WXCONFIG) + MESSAGE( SEND_ERROR "ERROR: wx-config --cxxflags returned an error") + ENDIF (BAD_WXCONFIG) +ENDIF( WIN32_STYLE_FIND ) + +# +# Find include directories (platform specific) +# +IF( WIN32_STYLE_FIND ) + # + # Set non-build specific include directories + # + SET ( WX_INCLUDE_PATH ${WXWIDGETS_ROOT_DIR}/include ) + SET ( WXWIDGETS_INCLUDE_DIR ${WX_INCLUDE_PATH} ) + SET( WXWIDGETS_INCLUDE_DIR ${WXWIDGETS_INCLUDE_DIR} ${WXWIDGETS_INCLUDE_DIR}/../contrib/include ) + # + # Append the build specific include dir for wx/setup.h: + # + IF ( EXISTS ${LIBRARYWANT}/wx/setup.h ) + SET( WX_INCLUDE_LIB_PATH ${LIBRARYWANT}) + SET( WXWIDGETS_INCLUDE_DIR ${WXWIDGETS_INCLUDE_DIR} ${LIBRARYWANT} ) + ELSE ( EXISTS ${LIBRARYWANT}/wx/setup.h ) + SET( WX_INCLUDE_LIB_PATH, "") + MESSAGE(SEND_ERROR "ERROR: Can't find ${LIBRARYWANT}/wx/setup.h") + ENDIF ( EXISTS ${LIBRARYWANT}/wx/setup.h ) + +ELSE( WIN32_STYLE_FIND ) + + # Pull out -I options + # evaluate wx-config output to separate include dirs + SET(WX_INCLUDE_DIR ${WXWIDGETS_CXX_FLAGS}) + # extract include dirs (-I) + # use regular expression to match wildcard equivalent "-I*" + # with is a space or a semicolon + STRING(REGEX MATCHALL "[-][I]([^ ;])+" WX_INCLUDE_DIRS_WITH_PREFIX "${WX_INCLUDE_DIR}" ) + # remove prefix -I because we need the pure directory + IF(WX_INCLUDE_DIRS_WITH_PREFIX) + STRING(REGEX REPLACE "[-][I]" ";" WXWIDGETS_INCLUDE_DIR ${WX_INCLUDE_DIRS_WITH_PREFIX} ) + ENDIF(WX_INCLUDE_DIRS_WITH_PREFIX) + # replace space separated string by semicolon separated vector + SEPARATE_ARGUMENTS(WXWIDGETS_INCLUDE_DIR) + # Remove the -I options from the CXX_FLAGS no need to duplicate + STRING(REGEX REPLACE "[-][I]([^ ;])+" "" WXWIDGETS_CXX_FLAGS ${WXWIDGETS_CXX_FLAGS} ) + + # + # Find XWindows + # + IF( NOT CYGWIN OR MINGW ) + INCLUDE( ${CMAKE_ROOT}/Modules/FindX11.cmake ) + SET( WXWIDGETS_INCLUDE_DIR ${WXWIDGETS_INCLUDE_DIR} ${X11_INCLUDE_DIR} ) + ENDIF( NOT CYGWIN OR MINGW ) +ENDIF( WIN32_STYLE_FIND ) + +# +# Find library list (platform specific) +# +IF( WIN32_STYLE_FIND ) + # + #Misc vars used to build lib names + # + SET( PFLIBEXT ${CMAKE_STATIC_LIBRARY_SUFFIX} ) + SET( WXPF "${WXPF}${WXVERSIONSUFFIX}" ) + SET( PFVERSION ${WXVERSIONSUFFIX} ) + SET( PFCOMPILER "" ) + + # + # Build the libraries list + # + SET( WX_TOKEN_LIBS "" ) + SET( WX_MULTI_LIBRARIES "" ) + SET( WX_MONO_LIBRARIES "" ) + SET( WX_DEBUG_TOKEN "@1" ) + + #start filling library string with needed libraries for the choosen configuration. + #note we use tokens for debug/release and the debug suffix so we can replace later + SET( WXPF "${PFVERSION}${PFUNICODE}${WX_DEBUG_TOKEN}" ) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxbase${WXPF}${PFCOMPILER}${PFLIBEXT} + wxbase${WXPF}_net${PFCOMPILER}${PFLIBEXT} + wxbase${WXPF}_xml${PFCOMPILER}${PFLIBEXT} + ) + + SET( WXPF "${PFVERSION}${PFUNICODE}${WX_DEBUG_TOKEN}" ) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxmsw${WXPF}_adv${PFCOMPILER}${PFLIBEXT} + wxmsw${WXPF}_core${PFCOMPILER}${PFLIBEXT} + wxmsw${WXPF}_html${PFCOMPILER}${PFLIBEXT} + wxmsw${WXPF}_xrc${PFCOMPILER}${PFLIBEXT} + ) + IF (WXWIDGETS_USE_MEDIA) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxmsw${WXPF}_media${PFCOMPILER}${PFLIBEXT} + ) + ENDIF (WXWIDGETS_USE_MEDIA) + + IF( NOT WXWIDGETS_USE_SHARED ) + SET( WXPF "${PFVERSION}${PFUNICODE}${WX_DEBUG_TOKEN}" ) + IF (WXWIDGETS_USE_ODBC) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxbase${WXPF}_odbc${PFCOMPILER}${PFLIBEXT} + ) + ENDIF (WXWIDGETS_USE_ODBC) + + SET( WXPF "${PFVERSION}${PFUNICODE}${WX_DEBUG_TOKEN}" ) + IF (WXWIDGETS_USE_DBGRID) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxmsw${WXPF}_dbgrid${PFLIBEXT} + ) + ENDIF (WXWIDGETS_USE_DBGRID) + IF (WXWIDGETS_USE_GL) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxmsw${WXPF}_gl${PFCOMPILER}${PFLIBEXT} + ) + ENDIF (WXWIDGETS_USE_GL) + ENDIF( NOT WXWIDGETS_USE_SHARED ) + + IF ( WXWIDGETS_USE_UNIV ) + SET( WXPF "${PFUNIV}${PFVERSION}${PFUNICODE}${WX_DEBUG_TOKEN}" ) + SET(WX_MULTI_LIBRARIES ${WX_MULTI_LIBRARIES} + wxmsw${WXPF}_core${PFCOMPILER}${PFLIBEXT} + ) + ENDIF ( WXWIDGETS_USE_UNIV ) + + SET(WX_MONO_LIBRARIES ${WX_MONO_LIBRARIES} + wxmsw${WXPF}${PFCOMPILER}${PFLIBEXT} + ) + + IF ( WXWIDGETS_USE_MONO ) + SET(WX_TOKEN_LIBS ${WX_TOKEN_LIBS} ${WX_MONO_LIBRARIES}) + ELSE ( WXWIDGETS_USE_MONO ) + SET(WX_TOKEN_LIBS ${WX_TOKEN_LIBS} ${WX_MULTI_LIBRARIES}) + ENDIF ( WXWIDGETS_USE_MONO ) + + SET( WXPF "${PFUNICODE}${WX_DEBUG_TOKEN}" ) + SET(WX_TOKEN_LIBS ${WX_TOKEN_LIBS} + wxregex${WXPF}.lib + ) + + SET( WXPF "${WX_DEBUG_TOKEN}" ) + SET(WX_TOKEN_LIBS ${WX_TOKEN_LIBS} + wxexpat${WXPF}.lib + wxpng${WXPF}.lib + wxtiff${WXPF}.lib + wxjpeg${WXPF}.lib + wxzlib${WXPF}.lib + ) + + + SET( WXWIDGETS_COMMON_LIBRARIES + comctl32${PFLIBEXT} wsock32${PFLIBEXT} rpcrt4${PFLIBEXT} + ) + # + #Build release/debug lists by replacing tokens + # + SET( WXWIDGETS_RELEASE_LIBRARIES "" ) + FOREACH(LOOPLIB ${WX_TOKEN_LIBS}) + SET(WX_TMPLIB ${LOOPLIB}) + STRING(REGEX REPLACE "[@][1]" "" WX_TMPLIB ${WX_TMPLIB} ) + SET( WXWIDGETS_RELEASE_LIBRARIES ${WXWIDGETS_RELEASE_LIBRARIES} + ${WX_TMPLIB} + ) + ENDFOREACH(LOOPLIB ${WX_TOKEN_LIBS}) + SET( WXWIDGETS_DEBUG_LIBRARIES "" ) + FOREACH(LOOPLIB ${WX_TOKEN_LIBS}) + SET(WX_TMPLIB ${LOOPLIB}) + STRING(REGEX REPLACE "[@][1]" "d" WX_TMPLIB ${WX_TMPLIB} ) + SET( WXWIDGETS_DEBUG_LIBRARIES ${WXWIDGETS_DEBUG_LIBRARIES} + ${WX_TMPLIB} + ) + ENDFOREACH(LOOPLIB ${WX_TOKEN_LIBS}) + + # + # Set full lib list to requested type + # + IF( WXWIDGETS_USE_DEBUG ) + SET( WXWIDGETS_LIBRARIES ${WXWIDGETS_COMMON_LIBRARIES} + ${WXWIDGETS_DEBUG_LIBRARIES} + ) + ELSE( WXWIDGETS_USE_DEBUG ) + SET( WXWIDGETS_LIBRARIES ${WXWIDGETS_COMMON_LIBRARIES} + ${WXWIDGETS_RELEASE_LIBRARIES} + ) + ENDIF( WXWIDGETS_USE_DEBUG ) + + #Not used under Windows + SET( WXWIDGETS_EXE_LINKER_FLAGS "" ) + +ELSE( WIN32_STYLE_FIND ) + # + # Get Library list from wx-config + # + # do we need additionial wx GL stuff like GLCanvas ? + IF(WXWIDGETS_USE_GL) + SET(WX_CONFIG_ARGS_LIBS "${WX_CONFIG_ARGS_LIBS} --gl-libs" ) + ENDIF(WXWIDGETS_USE_GL) + + EXEC_PROGRAM(${WX_WXCONFIG_EXECUTABLE} + ARGS ${WX_CONFIG_ARGS_LIBS} + OUTPUT_VARIABLE WX_CONFIGARGS + RETURN_VALUE BAD_WXCONFIG ) + IF (BAD_WXCONFIG) + MESSAGE( SEND_ERROR "ERROR: Specified WXWidgets config NOT found") + ENDIF (BAD_WXCONFIG) + + #Pull lib dirs, linker opts, and libs from wx-config --libs return + SET(WXWIDGETS_LINK_DIRECTORIES "") + SET(WXWIDGETS_EXE_LINKER_FLAGS "") + SET(WXWIDGETS_LIBRARIES "") + SEPARATE_ARGUMENTS(WX_CONFIGARGS) + FILE( WRITE "${PROJECT_BINARY_DIR}/findwxw-args.log" "WXWIDGETS ARGS\n" ) + FOREACH(WXARG ${WX_CONFIGARGS}) + FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw-args.log" "WXARG: ${WXARG}\n" ) + IF(WXARG MATCHES "^-L") + SET(WXWIDGETS_LINK_DIRECTORIES ${WXWIDGETS_LINK_DIRECTORIES} ${WXARG}) + ELSE(WXARG MATCHES "^-L") + IF(WXARG MATCHES "^-l") + SET(WXWIDGETS_LIBRARIES "${WXWIDGETS_LIBRARIES} ${WXARG}") + ELSE(WXARG MATCHES "^-l") + IF(WXARG MATCHES "^-") + SET(WXWIDGETS_EXE_LINKER_FLAGS "${WXWIDGETS_EXE_LINKER_FLAGS} ${WXARG}") + ELSE(WXARG MATCHES "^-") + SET(WXWIDGETS_LIBRARIES "${WXWIDGETS_LIBRARIES} ${WXARG}") + ENDIF(WXARG MATCHES "^-") + ENDIF(WXARG MATCHES "^-l") + ENDIF(WXARG MATCHES "^-L") + ENDFOREACH(WXARG ${WX_CONFIGARGS}) + + #Separate library names with ; + SEPARATE_ARGUMENTS(WXWIDGETS_LIBRARIES) + + # remove prefix -L because we need the pure directory for LINK_DIRECTORIES + # replace -L by ; because the separator seems to be lost otherwise (bug or + # feature?) + SET(WX_LINK_DIRECTORIES_WITH_PREFIX ${WXWIDGETS_LINK_DIRECTORIES}) + IF(WX_LINK_DIRECTORIES_WITH_PREFIX) + STRING(REGEX REPLACE "[-][L]" ";" WXWIDGETS_LINK_DIRECTORIES ${WX_LINK_DIRECTORIES_WITH_PREFIX} ) + #MESSAGE("DBG WXWIDGETS_LINK_DIRECTORIES=${WXWIDGETS_LINK_DIRECTORIES}") + ENDIF(WX_LINK_DIRECTORIES_WITH_PREFIX) + # replace space separated string by semicolon separated vector to make it + # work with LINK_DIRECTORIES + SEPARATE_ARGUMENTS(WXWIDGETS_LINK_DIRECTORIES) + + + # + # Unix puts all the libs in the WXWIDGETS_LIBRARIES var + # We don't know debug/release libs under unix, so we set the + # common var to full set as well and leave debug/release sets blank + # + SET( WXWIDGETS_RELEASE_LIBRARIES "" ) + SET( WXWIDGETS_DEBUG_LIBRARIES "" ) + SET(WXWIDGETS_COMMON_LIBRARIES ${WXWIDGETS_LIBRARIES}) + +ENDIF( WIN32_STYLE_FIND ) + + +# +# Find wx.rc +# +SET( WXWIDGETS_RC ${WXWIDGETS_ROOT_DIR}/include/wx/msw/wx.rc ) +IF( NOT WIN32_STYLE_FIND ) + IF( NOT CYGWIN OR MINGW ) + SET( WXWIDGETS_RC "" ) + ENDIF( NOT CYGWIN OR MINGW ) +ENDIF( NOT WIN32_STYLE_FIND ) + +# +# Set preprocessor defs +# +STRING(TOUPPER ${CMAKE_SYSTEM_NAME} WX_SYSNAME) +SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} "-D${WX_SYSNAME}" ) + +IF(WIN32_STYLE_FIND) + SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} -DWIN32 -D__WXMSW__ ) +ELSE(WIN32_STYLE_FIND) + IF( CYGWIN ) + SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} -D__GNUWIN32__ -O2 -D_WIN32_IE=0x400 -MMD -Wall ) + ENDIF( CYGWIN ) +ENDIF(WIN32_STYLE_FIND) + +IF( WXWIDGETS_USE_SHARED ) + SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} -DWXUSINGDLL ) +ENDIF( WXWIDGETS_USE_SHARED ) + +IF( WXWIDGETS_USE_DEBUG ) + SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} -D_DEBUG_ -D__WXDEBUG__ -DWXDEBUG=1 ) +ENDIF( WXWIDGETS_USE_DEBUG ) + +IF ( WXWIDGETS_USE_UNICODE ) + SET( WXWIDGETS_DEFINITIONS ${WXWIDGETS_DEFINITIONS} -DwxUSE_UNICODE ) +ENDIF ( WXWIDGETS_USE_UNICODE ) + +# +# Set the WXWIDGETS_FOUND var +# +IF(WXWIDGETS_LIBRARIES AND WXWIDGETS_INCLUDE_DIR) + SET(WXWIDGETS_FOUND 1) +ENDIF(WXWIDGETS_LIBRARIES AND WXWIDGETS_INCLUDE_DIR) + +# +# Mark advanced vars +# +MARK_AS_ADVANCED(WXWIDGETS_ROOT_DIR) + +# +# Log results +# +FILE( WRITE "${PROJECT_BINARY_DIR}/findwxw.log" "FindwxW.cmake version 1.06\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_FOUND: ${WXWIDGETS_FOUND}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_LINK_DIRECTORIES: ${WXWIDGETS_LINK_DIRECTORIES}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_LIBRARIES: ${WXWIDGETS_LIBRARIES}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_RELEASE_LIBRARIES: ${WXWIDGETS_RELEASE_LIBRARIES}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_DEBUG_LIBRARIES: ${WXWIDGETS_DEBUG_LIBRARIES}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_CXX_FLAGS: ${WXWIDGETS_CXX_FLAGS}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_EXE_LINKER_FLAGS: ${WXWIDGETS_EXE_LINKER_FLAGS}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_INCLUDE_DIR: ${WXWIDGETS_INCLUDE_DIR}\n" ) +FILE( APPEND "${PROJECT_BINARY_DIR}/findwxw.log" "WXWIDGETS_DEFINITIONS: ${WXWIDGETS_DEFINITIONS}\n" ) diff --git a/cmake/InstallLibraryForCMakeMacro.cmake b/cmake/InstallLibraryForCMakeMacro.cmake new file mode 100644 index 0000000..c2aadb7 --- /dev/null +++ b/cmake/InstallLibraryForCMakeMacro.cmake @@ -0,0 +1,286 @@ +#----------------------------------------------------------------------------- +# Macro crea_INSTALL_LIBRARY_FOR_CMAKE +# Creates and install the cmake files which allow +# to find a library by the cmake command FIND_PACKAGE. +# +# Inputs : +# -------- +# LIBRARY_NAME : name of the library to find +# +# The following variables **MUST** have been set previously : +# +# * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS +# The list of include paths +# when someone uses a *BUILD TREE* version of ${LIBRARY_NAME}. +# NB : +# THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE PROJECT **SOURCES** ! +# Assume your project architecture is : +# install/ : directory in which the macro is invoked +# src/part1/include/ : first include dir +# src/part2/include/ : second include dir +# Then you should set the var with : +# SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS +# src/part1/include +# src/part2/include ) +# Which will result in actual include paths : +# ${PROJECT_SOURCE_DIR}/src/part1/include; +# ${PROJECT_SOURCE_DIR}/src/part2/include +# * ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS +# Like the previous var but for the library paths. +# NB : +# THE PATHS *MUST BE RELATIVE* TO THE ROOT DIR OF THE **BUILD TREE** +# THAT IS POINT TO THE FOLDERS WHERE THE LIBS WILL BE BUILD +# Assume that your project architecture is : +# src/part1/src/ : first source dir, in which the lib 'part1' is built +# src/part2/src/ : first source dir, in which the lib 'part2' is built +# Then you should set the var with +# SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS +# src/part1/src +# src/part2/src +# ) +# Which will result in actual library paths : +# ${PROJECT_BINARY_DIR}/src/part1/src +# ${PROJECT_BINARY_DIR}/src/part2/src +# * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS +# The list of include paths +# when someone uses an *INSTALLED* version of ${LIBRARY_NAME} +# The paths *MUST BE RELATIVE* to INSTALL_PREFIX +# # A typical example is "include/${LIBRARY_NAME}" +# * ${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS +# Like the previous var but for library paths. +# A typical example is ".." +# * ${LIBRARY_NAME}_LIBRARIES +# The list of libraries to link against when using ${LIBRARY_NAME} +# +# The following variables can be set optionally : +# +# * ${LIBRARY_NAME}_REQUIRED_C_FLAGS +# * ${LIBRARY_NAME}_REQUIRED_CXX_FLAGS +# * ${LIBRARY_NAME}_REQUIRED_LINK_FLAGS +# * ${LIBRARY_NAME}_MAJOR_VERSION +# * ${LIBRARY_NAME}_MINOR_VERSION +# * ${LIBRARY_NAME}_BUILD_VERSION +# * ${LIBRARY_NAME}_INSTALL_FOLDER : if set then install the stuff +# in INSTALL_PREFIX/lib/${LIBRARY_NAME}_INSTALL_FOLDER +# instead of INSTALL_PREFIX/lib/${LIBRARY_NAME} +# +# +# To provide a user defined +# couple of Config/Use file (in addition to the standard one) use : +# SET( ${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE TRUE ) +# and store the *ABSOLUTE* paths to the additional files in the vars : +# ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE +# ${LIBRARY_NAME}_ADDITIONAL_USE_FILE +# (e.g. ${CMAKE_CURRENT_SOURCE_DIR}/MyConfig.cmake) +# +# Outputs : +# -------- +# At cmake run-time, the macro creates the following files +# in the current dir of the build tree (where the macro is invoked) : +# Use${LIBRARY_NAME}.cmake +# ${LIBRARY_NAME}Config.cmake +# ${LIBRARY_NAME}BuildSettings.cmake +# And if the vars ${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE and +# ${LIBRARY_NAME}_ADDITIONAL_USE_FILE are set, it also creates : +# Additional${LIBRARY_NAME}Config.cmake +# AdditionalUse${LIBRARY_NAME}.cmake +# +# At install-time, the same files are installed +# in INSTALL_PREFIX/lib/${LIBRARY_NAME} +# and the file : +# Find${LIBRARY_NAME}.cmake +# is installed in ${CMAKE_ROOT}/Modules/ +# +# +#----------------------------------------------------------------------------- + +MACRO(crea_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME) + + #--------------------------------------------------------------------------- + # Sets the common values to build tree and install tree configs + SET(CILC_LIB_REQUIRED_C_FLAGS ${${LIBRARY_NAME}_REQUIRED_C_FLAGS}) + SET(CILC_LIB_REQUIRED_CXX_FLAGS ${${LIBRARY_NAME}_REQUIRED_CXX_FLAGS}) + SET(CILC_LIB_REQUIRED_LINK_FLAGS ${${LIBRARY_NAME}_REQUIRED_LINK_FLAGS}) + SET(CILC_LIB_MAJOR_VERSION ${${LIBRARY_NAME}_MAJOR_VERSION}) + SET(CILC_LIB_MINOR_VERSION ${${LIBRARY_NAME}_MINOR_VERSION}) + SET(CILC_LIB_BUILD_VERSION ${${LIBRARY_NAME}_BUILD_VERSION}) + SET(CILC_LIB_VERSION + ${CILC_LIB_MAJOR_VERSION}.${CILC_LIB_MINOR_VERSION}.${CILC_LIB_BUILD_VERSION}) + SET(CILC_LIB_LIBRARIES ${${LIBRARY_NAME}_LIBRARIES}) + IF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE) + SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE TRUE) + ELSE (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE) + SET(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE FALSE) + ENDIF (${LIBRARY_NAME}_HAS_ADDITIONAL_CONFIG_FILE) + #--------------------------------------------------------------------------- + + + #--------------------------------------------------------------------------- + #-- BUILD TREE configuration + SET(CILC_BUILD_TREE_CONFIGURATION TRUE) + # UseLIBRARY_NAME.cmake + CONFIGURE_FILE( + ${crea_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in + ${PROJECT_BINARY_DIR}/Use${LIBRARY_NAME}.cmake + @ONLY IMMEDIATE + ) + # LIBRARY_NAMEConfig.cmake + SET(CILC_LIB_RELATIVE_INCLUDE_PATHS + ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS}) + SET(CILC_LIB_RELATIVE_LIBRARY_PATHS + ${${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS}) + CONFIGURE_FILE( + ${crea_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in + ${PROJECT_BINARY_DIR}/${LIBRARY_NAME}Config.cmake + @ONLY IMMEDIATE + ) + # LIBRARY_NAMEBuildSettings.cmake : + # Save the compiler settings so another project can import them. + INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake) + CMAKE_EXPORT_BUILD_SETTINGS(${PROJECT_BINARY_DIR}/${LIBRARY_NAME}BuildSettings.cmake) + # Additional Config and Use files + IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE) + CONFIGURE_FILE( + ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE} + ${PROJECT_BINARY_DIR}/Additional${LIBRARY_NAME}Config.cmake + @ONLY IMMEDIATE + ) + CONFIGURE_FILE( + ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE} + ${PROJECT_BINARY_DIR}/AdditionalUse${LIBRARY_NAME}.cmake + @ONLY IMMEDIATE + ) + ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE) + #--------------------------------------------------------------------------- + + + #--------------------------------------------------------------------------- + #-- INSTALL TREE configuration + SET(CILC_BUILD_TREE_CONFIGURATION FALSE) + # Create work directory to put the configured files because + # if the user invoked the macro at the root of the build tree the files + # would overwrite those configured for the build tree + SET(CILC_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/InstallLibraryForCMake_tmp) + IF(NOT IS_DIRECTORY ${CILC_WORK_DIR}) + FILE(MAKE_DIRECTORY ${CILC_WORK_DIR}) + ENDIF(NOT IS_DIRECTORY ${CILC_WORK_DIR}) + + #---------------------------------------------------------------------------- + #INSTALLATION PATH + IF(WIN32) + SET(INSTALL_PATH .) + ELSE(WIN32) + IF(${LIBRARY_NAME}_INSTALL_FOLDER) + SET(INSTALL_PATH lib/${${LIBRARY_NAME}_INSTALL_FOLDER}) + ELSE(${LIBRARY_NAME}_INSTALL_FOLDER) + SET(INSTALL_PATH lib/${LIBRARY_NAME}) + ENDIF(${LIBRARY_NAME}_INSTALL_FOLDER) + ENDIF(WIN32) + + + # UseLIBRARY_NAME.cmake + CONFIGURE_FILE( + ${crea_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in + ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake + @ONLY IMMEDIATE + ) + INSTALL( + FILES + ${CILC_WORK_DIR}/Use${LIBRARY_NAME}.cmake + DESTINATION ${INSTALL_PATH} + ) + # LIBRARY_NAMEConfig.cmake + SET(CILC_LIB_RELATIVE_INCLUDE_PATHS + ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS}) + SET(CILC_LIB_RELATIVE_LIBRARY_PATHS + ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS}) + CONFIGURE_FILE( + ${crea_CMAKE_DIR}/InstallLibraryForCMake_LibraryConfig.cmake.in + ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake + @ONLY IMMEDIATE + ) + INSTALL( + FILES + ${CILC_WORK_DIR}/${LIBRARY_NAME}Config.cmake + DESTINATION ${INSTALL_PATH} + ) + # LIBRARY_NAMEBuildSettings.cmake : + CMAKE_EXPORT_BUILD_SETTINGS(${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake) + INSTALL( + FILES + ${CILC_WORK_DIR}/${LIBRARY_NAME}BuildSettings.cmake + DESTINATION ${INSTALL_PATH} + ) + # Additional Config and Use files + IF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE) + CONFIGURE_FILE( + ${${LIBRARY_NAME}_ADDITIONAL_CONFIG_FILE} + ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake + @ONLY IMMEDIATE + ) + INSTALL( + FILES + ${CILC_WORK_DIR}/Additional${LIBRARY_NAME}Config.cmake + DESTINATION ${INSTALL_PATH} + ) + CONFIGURE_FILE( + ${${LIBRARY_NAME}_ADDITIONAL_USE_FILE} + ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake + @ONLY IMMEDIATE + ) + INSTALL( + FILES + ${CILC_WORK_DIR}/AdditionalUse${LIBRARY_NAME}.cmake + DESTINATION ${INSTALL_PATH} + ) + ENDIF(CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE) + # Specific to install tree + # FindLIBRARY_NAME.cmake in CMake/Modules dir + CONFIGURE_FILE( + ${crea_CMAKE_DIR}/InstallLibraryForCMake_FindLibrary.cmake.in + ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake + @ONLY IMMEDIATE + ) + INSTALL( + FILES ${CILC_WORK_DIR}/Find${LIBRARY_NAME}.cmake + DESTINATION ${CMAKE_ROOT}/Modules + ) + #--------------------------------------------------------------------------- + + + + +ENDMACRO(crea_INSTALL_LIBRARY_FOR_CMAKE) +#----------------------------------------------------------------------------- + + + + +#----------------------------------------------------------------------------- +MACRO(crea_DEFAULT_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME) + + SET(${LIBRARY_NAME}_INSTALL_FOLDER ${LIBRARY_NAME}) + SET(${LIBRARY_NAME}_LIBRARIES ${LIBRARY_NAME}) + + FILE(RELATIVE_PATH + ${LIBRARY_NAME}_BUILD_TREE_RELATIVE_INCLUDE_PATHS + ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} + ) + + IF(UNIX) + SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS + ${EXECUTABLE_OUTPUT_REL_PATH}) + ELSE(UNIX) + SET(${LIBRARY_NAME}_BUILD_TREE_RELATIVE_LIBRARY_PATHS + ${EXECUTABLE_OUTPUT_REL_PATH}/Debug + ${EXECUTABLE_OUTPUT_REL_PATH}/Release) + ENDIF(UNIX) + SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS include/${LIBRARY_NAME}) + SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib) + + # Invoke the macro + crea_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME}) + + +ENDMACRO(crea_DEFAULT_INSTALL_LIBRARY_FOR_CMAKE) +#----------------------------------------------------------------------------- diff --git a/cmake/InstallLibraryForCMake_FindLibrary.cmake.in b/cmake/InstallLibraryForCMake_FindLibrary.cmake.in new file mode 100644 index 0000000..182c9e7 --- /dev/null +++ b/cmake/InstallLibraryForCMake_FindLibrary.cmake.in @@ -0,0 +1,106 @@ +# - Find a library installation or build tree. +# +# The following variables are set if @LIBRARY_NAME@ is found. +# If @LIBRARY_NAME@ is not found, @LIBRARY_NAME@_FOUND is set to false. +# @LIBRARY_NAME@_FOUND - Set to true when @LIBRARY_NAME@ is found. +# @LIBRARY_NAME@_USE_FILE - CMake file to use @LIBRARY_NAME@. +# @LIBRARY_NAME@_MAJOR_VERSION - The @LIBRARY_NAME@ major version number. +# @LIBRARY_NAME@_MINOR_VERSION - The @LIBRARY_NAME@ minor version number +# (odd non-release). +# @LIBRARY_NAME@_BUILD_VERSION - The @LIBRARY_NAME@ patch level +# (meaningless for odd minor). +# @LIBRARY_NAME@_INCLUDE_DIRS - Include directories for @LIBRARY_NAME@ +# @LIBRARY_NAME@_LIBRARY_DIRS - Link directories for @LIBRARY_NAME@ libraries +# @LIBRARY_NAME@_LIBRARIES - List of libraries to link against +# +# The following cache entries must be set by the user to locate @LIBRARY_NAME@: +# @LIBRARY_NAME@_DIR - The directory containing @LIBRARY_NAME@Config.cmake. +# This is either the root of the build tree, +# or the lib/@LIBRARY_NAME@ directory. This is the +# only cache entry. + + +# Construct consitent error messages for use below. +SET(@LIBRARY_NAME@_DIR_DESCRIPTION "directory containing @LIBRARY_NAME@Config.cmake. This is either the root of the build tree, or PREFIX/lib/@LIBRARY_NAME@ for an installation.") +SET(@LIBRARY_NAME@_NOT_FOUND_MESSAGE "@LIBRARY_NAME@ not found. Set the @LIBRARY_NAME@_DIR cmake cache entry to the ${@LIBRARY_NAME@_DIR_DESCRIPTION}") + +# Search only if the location is not already known. +IF(NOT @LIBRARY_NAME@_DIR) + # Get the system search path as a list. + IF(UNIX) + STRING(REGEX MATCHALL "[^:]+" @LIBRARY_NAME@_DIR_SEARCH1 "$ENV{PATH}") + ELSE(UNIX) + STRING(REGEX REPLACE "\\\\" "/" @LIBRARY_NAME@_DIR_SEARCH1 "$ENV{PATH}") + ENDIF(UNIX) + STRING(REGEX REPLACE "/;" ";" @LIBRARY_NAME@_DIR_SEARCH2 "${@LIBRARY_NAME@_DIR_SEARCH1}") + + # Construct a set of paths relative to the system search path. + SET(@LIBRARY_NAME@_DIR_SEARCH "") + FOREACH(dir ${@LIBRARY_NAME@_DIR_SEARCH2}) + SET(@LIBRARY_NAME@_DIR_SEARCH ${@LIBRARY_NAME@_DIR_SEARCH} + ${dir}/../lib/@INSTALL_PATH@ + ) + ENDFOREACH(dir) + + # + # Look for an installation or build tree. + # + FIND_PATH(@LIBRARY_NAME@_DIR Use@LIBRARY_NAME@.cmake + # Look for an environment variable @LIBRARY_NAME@_DIR. + $ENV{@LIBRARY_NAME@_DIR} + + # Look in places relative to the system executable search path. + ${@LIBRARY_NAME@_DIR_SEARCH} + + # Look in standard WIN install locations. + "$ENV{ProgramFiles}/@LIBRARY_NAME@" + + # Look in standard UNIX install locations. + /usr/local/@INSTALL_PATH@ + /usr/@INSTALL_PATH@ + + # Read from the CMakeSetup registry entries. It is likely that + # @LIBRARY_NAME@ will have been recently built. + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10] + + # Help the user find it if we cannot. + DOC "The ${@LIBRARY_NAME@_DIR_DESCRIPTION}" + ) +ENDIF(NOT @LIBRARY_NAME@_DIR) + +# If @LIBRARY_NAME@ was found, load the configuration file to get the rest of the +# settings. +IF(@LIBRARY_NAME@_DIR) + # Make sure the @LIBRARY_NAME@Config.cmake file exists in the directory provided. + IF(EXISTS ${@LIBRARY_NAME@_DIR}/@LIBRARY_NAME@Config.cmake) + + # We found @LIBRARY_NAME@. Load the settings. + SET(@LIBRARY_NAME@_FOUND 1) + INCLUDE(${@LIBRARY_NAME@_DIR}/@LIBRARY_NAME@Config.cmake) + + ENDIF(EXISTS ${@LIBRARY_NAME@_DIR}/@LIBRARY_NAME@Config.cmake) +ELSE(@LIBRARY_NAME@_DIR) + # We did not find @LIBRARY_NAME@. + SET(@LIBRARY_NAME@_FOUND 0) +ENDIF(@LIBRARY_NAME@_DIR) + +#----------------------------------------------------------------------------- +IF(NOT @LIBRARY_NAME@_FOUND) + # @LIBRARY_NAME@ not found, explain to the user how to specify its location. + IF(NOT @LIBRARY_NAME@_FIND_QUIETLY) + MESSAGE(FATAL_ERROR ${@LIBRARY_NAME@_NOT_FOUND_MESSAGE}) + ELSE(NOT @LIBRARY_NAME@_FIND_QUIETLY) + IF(@LIBRARY_NAME@_FIND_REQUIRED) + MESSAGE(FATAL_ERROR ${@LIBRARY_NAME@_NOT_FOUND_MESSAGE}) + ENDIF(@LIBRARY_NAME@_FIND_REQUIRED) + ENDIF(NOT @LIBRARY_NAME@_FIND_QUIETLY) +ENDIF(NOT @LIBRARY_NAME@_FOUND) diff --git a/cmake/InstallLibraryForCMake_LibraryConfig.cmake.in b/cmake/InstallLibraryForCMake_LibraryConfig.cmake.in new file mode 100644 index 0000000..d442bd2 --- /dev/null +++ b/cmake/InstallLibraryForCMake_LibraryConfig.cmake.in @@ -0,0 +1,126 @@ +#----------------------------------------------------------------------------- +# +# @LIBRARY_NAME@Config.cmake - CMake configuration file for external projects. +# This file was automatically generated by the cmake macro +# crea_INSTALL_LIBRARY_FOR_CMAKE of the package crea +# +# This file is configured by cmake and used by the +# Use@LIBRARY_NAME@.cmake module to load the lib settings +# for an external project. + +# Build tree config ? +SET(CILC_BUILD_TREE_CONFIGURATION @CILC_BUILD_TREE_CONFIGURATION@) + + +IF(UNIX) +SET(GOTO_INSTALL_PREFIX /../..) +ENDIF(UNIX) + + +# The @LIBRARY_NAME@ include file *RELATIVE* directories. +SET(CILC_RELATIVE_INCLUDE_PATHS "@CILC_LIB_RELATIVE_INCLUDE_PATHS@") +# Compute the prefix for include and library paths +IF(CILC_BUILD_TREE_CONFIGURATION) + # In build tree + # the include paths are relative to the source tree *AND* the binary tree + # for generated files + SET(CILC_INCLUDE_PATH_PREFIX @PROJECT_SOURCE_DIR@) + # Build the *ABSOLUTE* directories + FOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) + SET(@LIBRARY_NAME@_INCLUDE_DIRS + ${@LIBRARY_NAME@_INCLUDE_DIRS} + ${CILC_INCLUDE_PATH_PREFIX}/${path} + ) + ENDFOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) + SET(CILC_INCLUDE_PATH_PREFIX @PROJECT_BINARY_DIR@) + # Build the *ABSOLUTE* directories + FOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) + SET(@LIBRARY_NAME@_INCLUDE_DIRS + ${@LIBRARY_NAME@_INCLUDE_DIRS} + ${CILC_INCLUDE_PATH_PREFIX}/${path} + ) + ENDFOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) +ELSE(CILC_BUILD_TREE_CONFIGURATION) + # In install tree + # the include paths are relative to install prefix + # On unix , GOTO_INSTALL_PREFIX allows to get back to the + # installation prefix from @LIBRARY_NAME@_DIR + SET(CILC_INCLUDE_PATH_PREFIX ${@LIBRARY_NAME@_DIR}${GOTO_INSTALL_PREFIX}) + # Build the *ABSOLUTE* directories + FOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) + SET(@LIBRARY_NAME@_INCLUDE_DIRS + ${@LIBRARY_NAME@_INCLUDE_DIRS} + ${CILC_INCLUDE_PATH_PREFIX}/${path} + ) + ENDFOREACH(path ${CILC_RELATIVE_INCLUDE_PATHS}) +ENDIF(CILC_BUILD_TREE_CONFIGURATION) + + + +# Compute the prefix for library paths +IF(CILC_BUILD_TREE_CONFIGURATION) + # In build tree + # the library paths are relative to the binary tree + SET(CILC_LIBRARY_PATH_PREFIX @PROJECT_BINARY_DIR@) +ELSE(CILC_BUILD_TREE_CONFIGURATION) + # In install tree + # the library paths are relative to install prefix + SET(CILC_LIBRARY_PATH_PREFIX ${@LIBRARY_NAME@_DIR}${GOTO_INSTALL_PREFIX}) +ENDIF(CILC_BUILD_TREE_CONFIGURATION) +# The @LIBRARY_NAME@ library file *RELATIVE* directories. +SET(CILC_RELATIVE_LIBRARY_PATHS "@CILC_LIB_RELATIVE_LIBRARY_PATHS@") +# Build the *ABSOLUTE* directories +FOREACH(path ${CILC_RELATIVE_LIBRARY_PATHS}) + SET(@LIBRARY_NAME@_LIBRARY_DIRS + ${@LIBRARY_NAME@_LIBRARY_DIRS} + ${CILC_LIBRARY_PATH_PREFIX}/${path} + ) +ENDFOREACH(path ${CILC_RELATIVE_LIBRARY_PATHS}) + +# Set the "prefix path" +SET(@LIBRARY_NAME@_INSTALL_PREFIX ${CILC_LIBRARY_PATH_PREFIX}) + +# The C and C++ flags added by @LIBRARY_NAME@ to the cmake-configured flags. +SET(@LIBRARY_NAME@_REQUIRED_C_FLAGS "@CILC_LIB_REQUIRED_C_FLAGS@") +SET(@LIBRARY_NAME@_REQUIRED_CXX_FLAGS "@CILC_LIB_REQUIRED_CXX_FLAGS@") +SET(@LIBRARY_NAME@_REQUIRED_LINK_FLAGS "@CILC_LIB_REQUIRED_LINK_FLAGS@") + +# The @LIBRARY_NAME@ version +SET(@LIBRARY_NAME@_MAJOR_VERSION @CILC_LIB_MAJOR_VERSION@) +SET(@LIBRARY_NAME@_MINOR_VERSION @CILC_LIB_MINOR_VERSION@) +SET(@LIBRARY_NAME@_BUILD_VERSION @CILC_LIB_BUILD_VERSION@) +SET(@LIBRARY_NAME@_VERSION @CILC_LIB_VERSION@) + +# The location of the Use@LIBRARY_NAME@.cmake file. +SET(@LIBRARY_NAME@_USE_FILE "${@LIBRARY_NAME@_DIR}/Use@LIBRARY_NAME@.cmake") + +# The build settings file. +SET(@LIBRARY_NAME@_BUILD_SETTINGS_FILE + "${@LIBRARY_NAME@_DIR}/@LIBRARY_NAME@BuildSettings.cmake") + +# A list of all libraries for @LIBRARY_NAME@. Those listed here should +# automatically pull in their dependencies. +SET(@LIBRARY_NAME@_LIBRARIES @CILC_LIB_LIBRARIES@) + +# Messages +IF(crea_VERBOSE_FIND_LIBRARY) + MESSAGE(STATUS "Looking for @LIBRARY_NAME@... found - configuration :") + MESSAGE(STATUS "* @LIBRARY_NAME@_DIR = ${@LIBRARY_NAME@_DIR}") + MESSAGE(STATUS "* @LIBRARY_NAME@_VERSION = ${@LIBRARY_NAME@_VERSION}") + MESSAGE(STATUS "* @LIBRARY_NAME@_USE_FILE = ${@LIBRARY_NAME@_USE_FILE}") + + MESSAGE(STATUS "* @LIBRARY_NAME@_INCLUDE_DIRS = ${@LIBRARY_NAME@_INCLUDE_DIRS}") + MESSAGE(STATUS "* @LIBRARY_NAME@_LIBRARY_DIRS = ${@LIBRARY_NAME@_LIBRARY_DIRS}") + MESSAGE(STATUS "* @LIBRARY_NAME@_LIBRARIES = ${@LIBRARY_NAME@_LIBRARIES}") +ENDIF(crea_VERBOSE_FIND_LIBRARY) + +# Does the library has an additional config file (user provided) ? +SET(@LIBRARY_NAME@_HAS_ADDITIONAL_CONFIG_FILE @CILC_LIB_HAS_ADDITIONAL_CONFIG_FILE@) + +IF (@LIBRARY_NAME@_HAS_ADDITIONAL_CONFIG_FILE) + IF(crea_VERBOSE_FIND_LIBRARY) + MESSAGE(STATUS "Reading @LIBRARY_NAME@ additional configuration file") + ENDIF(crea_VERBOSE_FIND_LIBRARY) + # Include it + INCLUDE(${@LIBRARY_NAME@_DIR}/Additional@LIBRARY_NAME@Config.cmake) +ENDIF (@LIBRARY_NAME@_HAS_ADDITIONAL_CONFIG_FILE) diff --git a/cmake/InstallLibraryForCMake_UseLibrary.cmake.in b/cmake/InstallLibraryForCMake_UseLibrary.cmake.in new file mode 100644 index 0000000..5d51633 --- /dev/null +++ b/cmake/InstallLibraryForCMake_UseLibrary.cmake.in @@ -0,0 +1,35 @@ +# This is an implementation detail for using @LIBRARY_NAME@ with the +# Find@LIBRARY_NAME@.cmake module. Do not include directly by name. +# This should be included only when Find@LIBRARY_NAME@.cmake sets +# the @LIBRARY_NAME@_USE_FILE variable to point here. + +IF(crea_VERBOSE_FIND_LIBRARY) + MESSAGE(STATUS "Using @LIBRARY_NAME@") +ENDIF(crea_VERBOSE_FIND_LIBRARY) + +# Load the compiler settings used for @LIBRARY_NAME@. +IF(@LIBRARY_NAME@_BUILD_SETTINGS_FILE) + INCLUDE(CMakeImportBuildSettings) + CMAKE_IMPORT_BUILD_SETTINGS(${@LIBRARY_NAME@_BUILD_SETTINGS_FILE}) +ENDIF(@LIBRARY_NAME@_BUILD_SETTINGS_FILE) + +# Add compiler flags needed to use @LIBRARY_NAME@. +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${@LIBRARY_NAME@_REQUIRED_C_FLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${@LIBRARY_NAME@_REQUIRED_CXX_FLAGS}") +SET(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${@LIBRARY_NAME@_REQUIRED_LINK_FLAGS}") + +# Add include directories needed to use @LIBRARY_NAME@. +INCLUDE_DIRECTORIES(${@LIBRARY_NAME@_INCLUDE_DIRS}) + +# Add link directories needed to use @LIBRARY_NAME@. +LINK_DIRECTORIES(${@LIBRARY_NAME@_LIBRARY_DIRS}) + +# Set the version +# Already done in bbtkConfigure.h +#ADD_DEFINITIONS( -D@LIBRARY_NAME@_VERSION="\"${@LIBRARY_NAME@_VERSION}\"" ) + +# Additional use file +IF (@LIBRARY_NAME@_HAS_ADDITIONAL_CONFIG_FILE) + # Include it + INCLUDE(${@LIBRARY_NAME@_DIR}/AdditionalUse@LIBRARY_NAME@.cmake) +ENDIF (@LIBRARY_NAME@_HAS_ADDITIONAL_CONFIG_FILE) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake new file mode 100644 index 0000000..8215c47 --- /dev/null +++ b/cmake/Macros.cmake @@ -0,0 +1,51 @@ + +#----------------------------------------------------------------------------- +# MACRO TO ADD A COMPILER DEFINITION WHICH ADDS ALSO THE DEF +# INTO DOXYGEN PREDEFINED VAR +# (OTHERWISE DOXYGEN WOULD NOT PARSE THE FILES BLOCKED) +MACRO(crea_DEFINE DEF) + MESSAGE(STATUS "* Added definition -D${DEF}") + ADD_DEFINITIONS( -D${DEF} ) + SET(DOXYGEN_DOC_PREDEFINED + ${DOXYGEN_DOC_PREDEFINED};${DEF} + CACHE + STRING + "" + FORCE) + MARK_AS_ADVANCED(DOXYGEN_DOC_PREDEFINED) +ENDMACRO(crea_DEFINE) +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# MACRO TO ADD A COMPILER DEFINITION WITH VALUE WHICH ADDS ALSO THE DEF +# INTO DOXYGEN PREDEFINED VAR +# (OTHERWISE DOXYGEN WOULD NOT PARSE THE FILES BLOCKED) +MACRO(crea_DEFINE_WITH_VAL DEF VAL) + MESSAGE(STATUS "* Added definition -D${DEF}=\"${VAL}\"") + ADD_DEFINITIONS( -D${DEF}="${VAL}" ) + SET(DOXYGEN_DOC_PREDEFINED + ${DOXYGEN_DOC_PREDEFINED};${DEF}=${VAL} + CACHE + STRING + "" + FORCE) + MARK_AS_ADVANCED(DOXYGEN_DOC_PREDEFINED) +ENDMACRO(crea_DEFINE_WITH_VAL) +#----------------------------------------------------------------------------- + + +#======================================================================== +# Creates a directory if it does not exist +MACRO(crea_MKDIR DIR) + IF(NOT IS_DIRECTORY ${DIR}) + MESSAGE(STATUS "* Creating directory '${DIR}'") + FILE(MAKE_DIRECTORY ${DIR}) + ENDIF(NOT IS_DIRECTORY ${DIR}) +ENDMACRO(crea_MKDIR) +#======================================================================== + + +#======================================================================== +INCLUDE( ${crea_CMAKE_DIR}/InstallLibraryForCMakeMacro.cmake ) +#======================================================================== + diff --git a/cmake/PreventInSourceBuild.cmake b/cmake/PreventInSourceBuild.cmake new file mode 100644 index 0000000..8126ce8 --- /dev/null +++ b/cmake/PreventInSourceBuild.cmake @@ -0,0 +1,9 @@ +IF(NOT ALLOW_IN_SOURCE_BUILD) + #--------------------------------------------------------------------------- + # Building in the source tree is forbidden ! + # (except if ALLOW_IN_SOURCE_BUILD is set, e.g. for packaging with rpmbuild) + IF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) + MESSAGE(FATAL_ERROR "Building in the source tree is not allowed !! Quit; remove the file 'CMakeCache.txt' and the folder 'CMakeFiles' and build outside the sources") + ENDIF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR}) + #--------------------------------------------------------------------------- +ENDIF(NOT ALLOW_IN_SOURCE_BUILD) diff --git a/cmake/creaResolveOptions.cmake b/cmake/creaResolveOptions.cmake new file mode 100644 index 0000000..ee36f38 --- /dev/null +++ b/cmake/creaResolveOptions.cmake @@ -0,0 +1,16 @@ +# messages compilation options +IF (crea_COMPILE_MESSAGES) + crea_DEFINE( crea_COMPILE_MESSAGES ) +ENDIF (crea_COMPILE_MESSAGES) + +IF (crea_COMPILE_DEBUG_MESSAGES) + crea_DEFINE( crea_COMPILE_DEBUG_MESSAGES ) +ENDIF (crea_COMPILE_DEBUG_MESSAGES) + +IF (crea_COMPILE_WARNING_MESSAGES) + crea_DEFINE( crea_COMPILE_WARNING_MESSAGES ) +ENDIF (crea_COMPILE_WARNING_MESSAGES) + +IF (crea_COMPILE_ERROR_MESSAGES) + crea_DEFINE( crea_COMPILE_ERROR_MESSAGES ) +ENDIF (crea_COMPILE_ERROR_MESSAGES) diff --git a/cmake/wxWidgetsMacros.cmake b/cmake/wxWidgetsMacros.cmake new file mode 100644 index 0000000..d2bdf6f --- /dev/null +++ b/cmake/wxWidgetsMacros.cmake @@ -0,0 +1,83 @@ +#======================================================================= +# Looks for WxWidgets +#======================================================================= +MACRO(crea_FIND_WXWIDGETS) + IF(WIN32) + # Search WXWIDGETS + + # WXWINDOWS_LIBRARY = full path to the wxWindows library and linker flags on unix + # CMAKE_WX_CXX_FLAGS = compiler flags for building wxWindows + # WXWINDOWS_INCLUDE_PATH = include path of wxWindows + SET(WXWINDOWS_USE_GL 1) + + #wxWidgets build related stuff + SET(WXW_USE_DEBUG ON) + SET(WXW_USE_UNICODE OFF) + SET(WXW_USE_SHARED ON) + SET(WXW_USE_UNIV OFF) + SET(WXW_USE_MONO OFF) + SET(WXW_FILE_VERSION "28") + SET(WXW_VERSION "2.8") + + #CMake Options + # Why forcing verbosity ? + # SET(CMAKE_VERBOSE_MAKEFILE TRUE) + + INCLUDE (${crea_CMAKE_DIR}/FindWxWidgetsWin32.cmake) + # + + ELSE(WIN32) + # GTK2 + INCLUDE(${crea_CMAKE_DIR}/FindGTK2.cmake) + # WX + # LG : Do not force but use what is installed ! + # SET(wxWidgets_USE_LIBS base core gl) + FIND_PACKAGE( wxWidgets REQUIRED) + # + IF(wxWidgets_FOUND) + MESSAGE(STATUS "Looking for wxWidgets... found ${wxWidgets_CONFIG_EXECUTABLE}") + ENDIF(wxWidgets_FOUND) + ENDIF(WIN32) + + + +ENDMACRO(crea_FIND_WXWIDGETS) +#======================================================================= + +#======================================================================= +MACRO(crea_USE_WXWIDGETS) + # Preprocessor settings + crea_DEFINE( USE_WXWIDGETS ) + # + IF(WIN32) + # Clean ? + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${WXWIDGETS_CXX_FLAGS}") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}${WXWIDGETS_EXE_LINKER_FLAGS}") + # + ADD_DEFINITIONS( ${WXWIDGETS_DEFINITIONS} ) + # + INCLUDE_DIRECTORIES(${WXWIDGETS_INCLUDE_DIR}) + LINK_DIRECTORIES( ${WXWIDGETS_LINK_DIRECTORIES} ) + SET(WXWIDGETS_LIBRARIES + ${WXWIDGETS_LIBRARIES} + ${WXWIDGETS_LIBRARIES} wxmsw28d_aui + debug msvcrtd + debug msvcprtd + optimized msvcrt + optimized msvcprt + ) + ELSE(WIN32) + # GTK2 + INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS}) + LINK_DIRECTORIES(${GTK2_LIBRARY_DIRS}) + LINK_LIBRARIES(${GTK2_LIBRARIES}) + # WX + INCLUDE( ${wxWidgets_USE_FILE} ) + MARK_AS_ADVANCED(wxWidgets_CONFIG_EXECUTABLE) + SET(WXWIDGETS_LIBRARIES + ${GTK2_LIBRARIES} + ${wxWidgets_LIBRARIES} + ) + ENDIF(WIN32) +ENDMACRO(crea_USE_WXWIDGETS) +#======================================================================= diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt new file mode 100644 index 0000000..7d503d3 --- /dev/null +++ b/samples/CMakeLists.txt @@ -0,0 +1,2 @@ +SUBDIRS(creaSample_MessageManager) +SUBDIRS(creaSample_preprocessor) diff --git a/samples/creaSample_MessageManager/CMakeLists.txt b/samples/creaSample_MessageManager/CMakeLists.txt new file mode 100644 index 0000000..da55c61 --- /dev/null +++ b/samples/creaSample_MessageManager/CMakeLists.txt @@ -0,0 +1,2 @@ +ADD_EXECUTABLE(creaSample_MessageManager main) +TARGET_LINK_LIBRARIES(creaSample_MessageManager crea) diff --git a/samples/creaSample_MessageManager/main.cxx b/samples/creaSample_MessageManager/main.cxx new file mode 100644 index 0000000..7a90e6b --- /dev/null +++ b/samples/creaSample_MessageManager/main.cxx @@ -0,0 +1,22 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + std::cout << "** creaSample_MessageManager : begin of main "< + +int main(int argc, char* argv[]) +{ + std::cout << "** creaSample_preprocessor : begin of main "< + +namespace crea +{ + + inline std::string bbGetObjectDescription() { return(""); } + + class CREA_EXPORT Exception : public std::exception + { + public: + Exception(const std::string& object, + const std::string& source_file, + const std::string& message) throw() + : mObject(object), + mSourceFile(source_file), + mMessage(message) + {} + ~Exception() throw() {} + void Print() throw() + { + std::cerr << "* ERROR : " << mMessage < 0) { + std::cerr << "* OBJECT : " <mMessageLevel[key] = default_level; + GetInstance()->mMessageHelp[key] = help; + if (GetInstance()->mMaxMessageLengthmMaxMessageLength = key.length(); + } + + + + void MessageManager::SetMessageLevel(std::string key, + unsigned char level) + { + std::map::iterator i; + i = GetInstance()->mMessageLevel.find(key); + if (i!=GetInstance()->mMessageLevel.end()) + { + (*i).second = level; + } + else + { + creaWarning("MessageManager::SetMessageLevel : message type=<" + < unregistered"); + } + + } + + + + int MessageManager::GetMessageLevel(std::string key) + { + int l = GetInstance()->mMessageLevel["all"]; + std::map::iterator i = + GetInstance()->mMessageLevel.find(key); + if (i!=GetInstance()->mMessageLevel.end()) { + if ( (*i).second > l ) l = (*i).second; + } + int m = GetInstance()->mMessageLevel["max"]; + if (l>m) l=m; + return l; + } + + + + void MessageManager::PrintInfo() + { + creaMessage("info",1,"================ Messages =================" + << creaendl); + creaMessage("info",1, "Kind"); + for (int k=0; + k<(int)(GetInstance()->mMaxMessageLength-2); + k++) + { + creaMessageCont("info",1," "); + } + creaMessageCont("info",1,"Level Nature" << creaendl); + std::map::iterator i; + std::map::iterator j; + for (i=GetInstance()->mMessageLevel.begin(), + j=GetInstance()->mMessageHelp.begin(); + i!=GetInstance()->mMessageLevel.end();++i,++j) { + creaMessage("info",1, (*i).first); + for (int k=0; + k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length()); + k++) { + creaMessageCont("info",1," "); + } + creaMessageCont("info",1, (*i).second << "\t" + << (*j).second << creaendl); + } + creaMessage("info",1,"===========================================" + << creaendl); + } + + +} diff --git a/src/creaMessageManager.h b/src/creaMessageManager.h new file mode 100644 index 0000000..246d7e1 --- /dev/null +++ b/src/creaMessageManager.h @@ -0,0 +1,422 @@ + +/*! \file + + \brief Class creaMessageManager and Macros for outputing messages in crea + + There are 4 kinds of messages : + - Messages (normal messages) + - Debug messages (not compiled in release) + - Warnings + - Errors + There are also "types" of messages which are strings which identify the nature of the message + (for example : "Kernel" messages are generated by the core classes of the library, there can be a type of + message for each type of Node, and so on...) + A type of message must be declared by registering it into the MessageManager. This is done by a line like : + crea::MessageManager::RegisterMessageType("Kernel","Messages generated by the core classes of the library",5); + where : + -The first string is the type of the message (the category which will be used to generate a message of this type) + -The second string is help string + -The integer is the initial level for the messages of this type (see below). + + To generate a message of a known type then use one of the macros : + creaMessage, creaDebugMessage, creaWarning, creaError or their variants. + + example : + + creaMessage("Kernel",4,"problem with "< +#include +#include +#include + +// Comment out these symbols to prevent compilation +//#define crea_COMPILE_MESSAGES +//#define crea_COMPILE_DEBUG_MESSAGES +//#define crea_COMPILE_WARNING_MESSAGES +//#define crea_COMPILE_ERROR_MESSAGES + + +#define creaOnMessageLevel(key,value) \ + int __creaOnMessageLevelVariable = \ + crea::MessageManager::GetMessageLevel(key); \ + if ( __creaOnMessageLevelVariable<0) \ + { \ + creaWarning("message type '"<0) \ + { \ + std::cerr << "!! WARNING !! " << MESSAGE << std::endl; \ + if (lev >1) \ + { \ + std::cerr << "!! WARNING !! In file '"<<__FILE__ \ + <<"' ; Line "<<__LINE__< mMessageLevel; + std::map mMessageHelp; + unsigned int mMaxMessageLength; + }; + //=========================================================== + +} + +#include "creaException.h" + +#endif diff --git a/src/creaRTTI.cxx b/src/creaRTTI.cxx new file mode 100644 index 0000000..73b781c --- /dev/null +++ b/src/creaRTTI.cxx @@ -0,0 +1,80 @@ +#include "creaRTTI.h" +#include "creaMessageManager.h" + + + +namespace crea +{ + // Adapted from https://savannah.cern.ch/support/download.php?file_id=1972 + + // Something to which we can cast the void*s, to allow finding the + // dynamic typeid. + struct Dummy { + virtual ~Dummy() {} + }; + + + void* run_time_up_or_down_cast( const std::type_info& target_type, + const std::type_info& source_type, + const void* source_pointer + ) + { + return run_time_up_or_down_cast(target_type, + source_type, + const_cast(source_pointer)); + } + + void* run_time_up_or_down_cast( const std::type_info& target_type, + const std::type_info& source_type, + void* source_pointer + ) + { + creaDebugMessage("info",5, + "run_time_up_or_down_cast : Casting pointer to '" + << TypeName(typeid(*(Dummy*)source_pointer)) + << "' from " << TypeName(source_type) + << " to " << TypeName(target_type) << std::endl); + + void* target_pointer = 0; +#if __GNUC__ > 3 || \ + (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \ + (__GNUC_MINOR__ == 1 && \ + __GNUC_PATCHLEVEL__ > 0))) + + const abi::__class_type_info* targetTI = + (const abi::__class_type_info *)( &(target_type)); + + creaDebugMessage("info",7," * source = "< + +//----------------------------------------------------------------------------- +// RRTI type_info.name() demangling +// For type_info.name() demangling (gcc >= 3.1, see http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/namespaceabi.html) +// Test for GCC > 3.1.0 // +#if __GNUC__ > 3 || \ + (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \ + (__GNUC_MINOR__ == 1 && \ + __GNUC_PATCHLEVEL__ > 0))) +#include +#include +namespace crea +{ + inline std::string demangle_type_name(const char* name) + { + int status; + char* dem = abi::__cxa_demangle(name, 0, 0, &status); + std::string demangled(dem); + free(dem); + if (!status) return demangled; + return name; + } + +} + +#define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME) + +//========================================================================== +#elif defined(_WIN32) +// WIN32 +//#include "Windows.h" +//#include "stdafx.h" +#include +#include +// include the right library in the linker stage +#pragma comment( lib, "imagehlp.lib" ) + +namespace crea +{ + + + + + inline std::string demangle_type_name(const char* name) + { + char demangled[513]; + if (UnDecorateSymbolName(name, demangled, + sizeof(name), UNDNAME_COMPLETE)) + { + return name; //demangled; + } + else + { + return name; + } + } +} +#define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME) + +#else +// OTHER +#define CREA_DEMANGLE_TYPE_NAME(NAME) NAME +#endif + +#define CREA_GET_CURRENT_OBJECT_NAME \ + CREA_DEMANGLE_TYPE_NAME(typeid(*this).name()) + +#define CREA_GET_TYPE_NAME(A) \ + CREA_DEMANGLE_TYPE_NAME(typeid(A).name()) +//----------------------------------------------------------------------------- + + +namespace crea +{ + /// Template method which returns the name of a type + template + inline std::string TypeName() + { return CREA_DEMANGLE_TYPE_NAME(typeid(T).name()); } + /// Template method which returns the name of the type of a variable + template + inline std::string TypeName(const T& t) + { return CREA_DEMANGLE_TYPE_NAME(typeid(t).name()); } + /// Specialisation of TypeName when the type passed is already a type_info : + /// The user does not want to know the type of the type_info class but of + /// the class whose type_info is passed ! + template <> + inline std::string TypeName(const std::type_info& t) + { return CREA_DEMANGLE_TYPE_NAME(t.name()); } + + /// Template method which returns the human readable name of a type + template + inline std::string HumanTypeName() + { return TypeName(); } + /// Template method which returns the human readable name of the type of a variable + template + inline std::string HumanTypeName(const T& t) + { return TypeName(t); } + /// Specialisation of TypeName when the type passed is already a type_info : + /// The user does not want to know the type of the type_info class but of + /// the class whose type_info is passed ! + template <> + inline std::string HumanTypeName(const std::type_info& t) + { return TypeName(t); } + /// Macro to specialise the template function TypeName for certain types + /// (typically highly template types, such as STL types) + /// in order to return a **really** human readable string +#define CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(TYPE,NAME) \ + template <> inline std::string HumanTypeName< TYPE >() \ + { return NAME; } \ + template <> inline std::string HumanTypeName< TYPE >(const TYPE&) \ + { return NAME; } + + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(std::string,"String"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed char,"Char"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed short,"Short"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed int,"Int"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned char,"UChar"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned short,"UShort"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned int,"UInt"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(float,"Float"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(double,"Double"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(bool,"Bool"); + CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(long,"Long"); + + // Human readable strings for std::vector +#define CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(TYPE) \ + template <> inline std::string HumanTypeName< std::vector >() \ + { return "Vector"+HumanTypeName(); } \ + template <> inline std::string HumanTypeName< std::vector > \ + (const std::vector&) { return "Vector"+HumanTypeName(); } + + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int8_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint8_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int16_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint16_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int32_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint32_t); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(long); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(float); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(double); + CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(std::string); + +/// The crea::TypeInfo type is a const ref on std::type_info (which can only be manipulated as such (because typeid returns const std::type_info& and type_info has all constructors private)) + typedef const std::type_info& TypeInfo; + + + CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type, + const std::type_info& source_type, + void* source_pointer + ); + CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type, + const std::type_info& source_type, + const void* source_pointer + ); + + +} + +#endif + diff --git a/src/creaSystem.cxx b/src/creaSystem.cxx new file mode 100644 index 0000000..73bd4ac --- /dev/null +++ b/src/creaSystem.cxx @@ -0,0 +1,16 @@ +#include "creaSystem.h" + +namespace crea +{ + +#ifdef _WIN32 + int System::HasTTY() { return false; } +#else +#include + int System::HasTTY() + { + return isatty(fileno(stdin)); + } +#endif + +} // namespace crea diff --git a/src/creaSystem.h b/src/creaSystem.h new file mode 100644 index 0000000..d011190 --- /dev/null +++ b/src/creaSystem.h @@ -0,0 +1,243 @@ +/*========================================================================= + + Program: crea + Module: $RCSfile: creaSystem.h,v $ + Language: C++ + Date: $Date: 2008/09/26 14:09:55 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/creatools/license.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +/** + *\file + *\brief contains all the OS depending stuff + */ +#ifndef __creaSystem_h__ +#define __creaSystem_h__ + +#include "creaConfigure.h" + +// We try for Visual 6..???? +//#pragma warning( disable : 4786) + + + +//----------------------------------------------------------------------------- +//This is needed when compiling in debug mode +#ifdef _MSC_VER +// 'identifier' : class 'type' needs to have dll-interface to be used by +// clients of class 'type2' +#pragma warning ( disable : 4251 ) +// non dll-interface class 'type' used as base for dll-interface class 'type2' +#pragma warning ( disable : 4275 ) +// 'identifier' : identifier was truncated to 'number' characters in the +// debug information +#pragma warning ( disable : 4786 ) +//'identifier' : decorated name length exceeded, name was truncated +#pragma warning ( disable : 4503 ) +// C++ exception specification ignored except to indicate a +// function is not __declspec(nothrow) +#pragma warning ( disable : 4290 ) +// signed/unsigned mismatch +#pragma warning ( disable : 4018 ) +// return type for 'identifier' is '' (ie; not a UDT or reference to UDT. Will +// produce errors if applied using infix notation +#pragma warning ( disable : 4284 ) +// 'type' : forcing value to bool 'true' or 'false' (performance warning) +// //#pragma warning ( disable : 4800 ) +#endif //_MSC_VER + + +#include // for printf, ... +#include // for cout, endl, ... + +#ifdef _MSC_VER +// Micro$oft related stuff +#pragma once +#include +#include +#else +//#include // for getch +#endif //_MSC_VER + +//----------------------------------------------------------------------------- +// Micro$oft shared library related stuff +// +// all the classes that must be visible outside the crea library +// should be defined as : +// class CREA_EXPORT ClassName +// instead of : +// class ClassName + + +/* +// Useless ? +#if defined(_WIN32) +//&& defined(BUILD_SHARED_LIBS) + #ifdef CREA_EXPORTS2 + #define CREA_EXPORT2 export + #else + #define CREA_EXPORT2 + #endif +#else + #define CREA_EXPORT2 +#endif // defined(_WIN32) && defined(BUILD_SHARED_LIBS) +*/ +//#define TEST toto + + + +#if defined(_WIN32) && defined(CREA_BUILD_SHARED) +//#include "WWW.h" + #ifdef CREA_EXPORT_SYMBOLS + #define CREA_EXPORT __declspec( dllexport ) + #else + #define CREA_EXPORT __declspec( dllimport ) + #endif + #define CREA_CDECL __cdecl +#else + #define CREA_EXPORT + #define CREA_CDECL +#endif // defined(_WIN32) && defined(CREA_BUILD_SHARED) + + +#ifdef __BORLANDC__ +#include +#endif //__BORLANDC__ + + + +// ---------------------------------------------------------------------------- +// wx headers +// ---------------------------------------------------------------------------- +//#include "creaWx.h" + +/* +#ifdef _USE_WXWIDGETS_ +#include "wx/wxprec.h" +#include +#ifndef WX_PRECOMP +# include +#endif //WX_PRECOMP + +#include + +#ifdef __WXGTK__ +# include +#endif //__WXGTK__ + +#endif //_USE_WXWIDGETS_ +*/ +//----------------------------------------------------------------------------- + + + + +//----------------------------------------------------------------------------- +// Version +#include + +namespace crea +{ +#define CREA_STRINGIFY(A) #A +#define CREA_STRINGIFY_SYMBOL(A) CREA_STRINGIFY(A) + + extern "C" + { + CREA_EXPORT inline const std::string& CREA_CDECL GetVersion() + { + static const std::string v(CREA_STRINGIFY_SYMBOL(CREA_VERSION)); + return v; + } + } + +} +//----------------------------------------------------------------------------- + + + + +//----------------------------------------------------------------------------- +/* +#ifdef _WIN32 +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#else +#include +#include +#endif +*/ + +#ifdef CMAKE_HAVE_STDINT_H + #include +#else +#ifdef CMAKE_HAVE_INTTYPES_H + // Old system only have this + #include // For uint8_t uint16_t and uint32_t +#else + //#include "XXX.h" +// Broken plateforms do not respect C99 and do not provide those typedef +// Special case for recent Borland compiler, comes with stdint.h +#if defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560) \ + || defined(__MINGW32__) +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; + +/// \todo Find a clever way to deal with int64_t, uint64_t + +#else +#error "Sorry your plateform is not supported" +#endif // defined(_MSC_VER) || defined(__BORLANDC__) && (__BORLANDC__ < 0x0560) || defined(__MINGW32__) +#endif // CMAKE_HAVE_INTTYPES_H +#endif // CMAKE_HAVE_STDINT_H + +// Basically for VS6 and bcc 5.5.1: +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + + + +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +namespace crea +{ + + /// System related stuff + struct System + { + /// returns true iff the program has a tty + static int HasTTY(); + }; + +} // namespace crea +//----------------------------------------------------------------------------- + + // file separator +#if defined(_WIN32) +#define VALID_FILE_SEPARATOR "\\" +#define INVALID_FILE_SEPARATOR "/" +#else +#define INVALID_FILE_SEPARATOR "\\" +#define VALID_FILE_SEPARATOR "/" +#endif + +#endif diff --git a/src/creaWx.h b/src/creaWx.h new file mode 100644 index 0000000..3a7d6bb --- /dev/null +++ b/src/creaWx.h @@ -0,0 +1,77 @@ + +#ifndef __creaWx_h__INCLUDED__ +#define __creaWx_h__INCLUDED__ + +//=========================================================================== +// Wx headers +#ifdef USE_WXWIDGETS +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" +#include + + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#ifdef __WXGTK__ +# include +#endif //__WXGTK__ +// EO Wx headers +//=========================================================================== +#else // USE_WXWIDGETS +// define wxWindow as void hence wxWindow* are void* +typedef void wxWindow; +#endif // EO USE_WXWIDGETS +//=========================================================================== + + + + + + +//=========================================================================== +#ifdef USE_WXWIDGETS + +namespace crea +{ + //================================================================== + /// Conversion std::string to wxString + inline wxString std2wx(const std::string& s){ + wxString wx; + const char* my_string=s.c_str(); + wxMBConvUTF8 *wxconv= new wxMBConvUTF8(); + wx=wxString(wxconv->cMB2WC(my_string),wxConvUTF8); + delete wxconv; + // test if conversion works of not. In case it fails convert from Ascii + if(wx.length()==0) + wx=wxString(wxString::FromAscii(s.c_str())); + return wx; + } + //================================================================== + + //================================================================== + /// Conversion wxString to std::string + inline std::string wx2std(const wxString& s){ + std::string s2; + if(s.wxString::IsAscii()) { + s2=s.wxString::ToAscii(); + } else { + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(s); + const char *tmp_str = (const char*) tmp_buf; + s2=std::string(tmp_str, strlen(tmp_str)); + } + return s2; + } + //================================================================== + + +} + +#endif // EO USE_WXWIDGETS + +#endif diff --git a/src/wxVTKRenderWindowInteractor.cxx b/src/wxVTKRenderWindowInteractor.cxx new file mode 100644 index 0000000..e6c0161 --- /dev/null +++ b/src/wxVTKRenderWindowInteractor.cxx @@ -0,0 +1,742 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: wxVTKRenderWindowInteractor.cxx,v $ + Language: C++ + Date: $Date: 2008/09/26 14:09:55 $ + Version: $Revision: 1.1 $ + + Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#include "wxVTKRenderWindowInteractor.h" + +//This is needed for vtk 3.1 : +#ifndef VTK_MAJOR_VERSION +# include "vtkVersion.h" +#endif + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +# include "vtkCommand.h" +#else +# include "vtkInteractorStyle.h" +#endif + + + + //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0 +#if (!wxCHECK_VERSION(2, 4, 0)) + wxWindow* wxGetTopLevelParent(wxWindow *win) + { + while ( win && !win->IsTopLevel() ) + win = win->GetParent(); + return win; + } +#endif + +//======================================================================= + +// To access objc calls on cocoa +#ifdef __WXCOCOA__ +#ifdef VTK_USE_COCOA +#import +// This trick is no longer need in VTK CVS, should get rid of that: +#define id Id +#else +#error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work +#endif //VTK_USE_COCOA +#endif //__WXCOCOA__ + +#ifdef __WXGTK__ +# include // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0 +# include "gdk/gdkprivate.h" +#ifdef __WXGTK20__ +#include +#else +#include +#endif +#define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \ + GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \ + GDK_WINDOW_XWINDOW((wxwin)->m_widget->window) +#endif + +#ifdef __WXX11__ +#include "wx/x11/privx.h" +#define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle()) +#endif + + +//For more info on this class please go to: +//http://wxvtk.sf.net +//This hack is for some buggy wxGTK version: +#if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__) +# define WX_USE_X_CAPTURE 0 +#else +# define WX_USE_X_CAPTURE 1 +#endif + +#define ID_wxVTKRenderWindowInteractor_TIMER 1001 + +namespace crea +{ + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas) +#else +IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow) +#endif //__WXGTK__ + +//--------------------------------------------------------------------------- +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas) +#else +BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow) +#endif //__WXGTK__ + //refresh window by doing a Render + EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint) + EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground) + EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion) + + //Bind the events to the event converters + EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown) + EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp) + EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp) + EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp) +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) + EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter) + EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave) + EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel) +// If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions +// of all characters are always returned. EVT_CHAR also performs +// other necessary keyboard-dependent translations. + //EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown) + EVT_CHAR (wxVTKRenderWindowInteractor::OnKeyDown) + EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp) +#endif + EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer) + EVT_SIZE (wxVTKRenderWindowInteractor::OnSize) +END_EVENT_TABLE() + +//--------------------------------------------------------------------------- +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxGLCanvas() +#else +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxWindow() +#endif //__WXGTK__ + , timer(this, ID_wxVTKRenderWindowInteractor_TIMER) + , ActiveButton(wxEVT_NULL) + , RenderAllowed(0) + , Stereo(0) + , Handle(0) + , Created(true) + , RenderWhenDisabled(1) + , UseCaptureMouse(0) +{ + + this->RenderWindow = NULL; + this->SetRenderWindow(vtkRenderWindow::New()); + this->RenderWindow->Delete(); + + //this->SetBackgroundColour( wxColour(255,0,255) ); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + long style, + const wxString &name) +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + : vtkRenderWindowInteractor(), wxGLCanvas(parent, id, pos, size, style, name) +#else + : vtkRenderWindowInteractor(), wxWindow(parent, id, pos, size, style, name) +#endif //__WXGTK__ + , timer(this, ID_wxVTKRenderWindowInteractor_TIMER) + , ActiveButton(wxEVT_NULL) + , RenderAllowed(0) + , Stereo(0) + , Handle(0) + , Created(true) + , RenderWhenDisabled(1) + , UseCaptureMouse(0) +{ + + this->RenderWindow = NULL; + this->SetRenderWindow(vtkRenderWindow::New()); + this->RenderWindow->Delete(); + + // this->SetBackgroundColour( wxColour(255,0,0) ); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor() +{ + // LG : trompe la mort ! + SetRenderWindow(NULL); + SetReferenceCount(0); +} +//--------------------------------------------------------------------------- +wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New() +{ + // we don't make use of the objectfactory, because we're not registered + return new wxVTKRenderWindowInteractor; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Initialize() +{ + int *size = RenderWindow->GetSize(); + // enable everything and start rendering + Enable(); + //RenderWindow->Start(); + + // set the size in the render window interactor + Size[0] = size[0]; + Size[1] = size[1]; + + // this is initialized + Initialized = 1; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Enable() +{ + // if already enabled then done + if (Enabled) + return; + + // that's it + Enabled = 1; +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + SetCurrent(); +#endif + Modified(); +} +//--------------------------------------------------------------------------- +bool wxVTKRenderWindowInteractor::Enable(bool enable) +{ +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) + return wxGLCanvas::Enable(enable); +#else + return wxWindow::Enable(enable); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Disable() +{ + // if already disabled then done + if (!Enabled) + return; + + // that's it (we can't remove the event handler like it should be...) + Enabled = 0; + Modified(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Start() +{ + // the interactor cannot control the event loop + vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() " + "interactor cannot control event loop."); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::UpdateSize(int x, int y) +{ + if( RenderWindow ) + { + // if the size changed tell render window + if ( x != Size[0] || y != Size[1] ) + { + // adjust our (vtkRenderWindowInteractor size) + Size[0] = x; + Size[1] = y; + // and our RenderWindow's size + RenderWindow->SetSize(x, y); + } + } +} +//--------------------------------------------------------------------------- +int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype)) +{ + // it's a one shot timer + if (!timer.Start(10, TRUE)) + assert(false); + + return 1; + +} +//--------------------------------------------------------------------------- +int wxVTKRenderWindowInteractor::DestroyTimer() +{ + // do nothing + return 1; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event)) +{ + if (!Enabled) + return; + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::TimerEvent, NULL); +#else + // old style + InteractorStyle->OnTimer(); +#endif +} + +//--------------------------------------------------------------------------- +// NOTE on implementation: +// Bad luck you ended up in the only tricky place of this code. +// A few note, wxWidgets still refuse to provide such convenient method +// so I have to maintain it myself, eventhough this is completely integrated +// in wxPython... +// Anyway if this happen to break for you then compare to a recent version of wxPython +// and look for the function long wxPyGetWinHandle(wxWindow* win) +// in wxPython/src/helpers.cpp +long wxVTKRenderWindowInteractor::GetHandleHack() +{ + //helper function to hide the MSW vs GTK stuff + long handle_tmp = 0; + +// __WXMSW__ is for Win32 +//__WXMAX__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available) +// __WXGTK__ is for both gtk 1.2.x and gtk 2.x +#if defined(__WXMSW__) || defined(__WXMAC__) + handle_tmp = (long)this->GetHandle(); +#endif //__WXMSW__ + +//__WXCOCOA__ stands for using the objective-c Cocoa API +#ifdef __WXCOCOA__ + // Here is how to find the NSWindow + wxTopLevelWindow* toplevel = dynamic_cast( + wxGetTopLevelParent( this ) ); + if (toplevel != NULL ) + { + handle_tmp = (long)toplevel->GetNSWindow(); + } + // The NSView will be deducted from + // [(NSWindow*)Handle contentView] + // if only I knew how to write that in c++ +#endif //__WXCOCOA__ + + // Find and return the actual X-Window. +#if defined(__WXGTK__) || defined(__WXX11__) + return (long)GetXWindow(this); +#endif + +//#ifdef __WXMOTIF__ +// handle_tmp = (long)this->GetXWindow(); +//#endif + + return handle_tmp; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event)) +{ + + //must always be here + wxPaintDC pDC(this); + + //do it here rather than in the cstor: this is safer. + if(!Handle) + { + Handle = GetHandleHack(); + RenderWindow->SetWindowId(reinterpret_cast(Handle)); +#ifdef __WXMSW__ + RenderWindow->SetParentId(reinterpret_cast(this->GetParent()->GetHWND())); +#endif //__WXMSW__ + } + // get vtk to render to the wxWindows + //bbtkDebugMessage("Wx",9,"wxVTKRenderWindowInteractor::OnPaint"< 0) + InvokeEvent(vtkCommand::ConfigureEvent, NULL); +#endif + //this will check for Handle + //Render(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::MouseMoveEvent, NULL); +#else + InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) +void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::EnterEvent, NULL); +#else + // old style + InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + + InvokeEvent(vtkCommand::LeaveEvent, NULL); +#else + // old style + InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + int keycode = event.GetKeyCode(); + char key = '\0'; + if (keycode < 256) + { + // TODO: Unicode in non-Unicode mode ?? + key = (char)keycode; + } + + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), key, 0, NULL); + + InvokeEvent(vtkCommand::KeyPressEvent, NULL); + InvokeEvent(vtkCommand::CharEvent, NULL); +#else + InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), + event.GetKeyCode(), 1); +#endif + event.Skip(); +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + int keycode = event.GetKeyCode(); + char key = '\0'; + if (keycode < 256) + { + // TODO: Unicode in non-Unicode mode ?? + key = (char)keycode; + } + + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), key, 0, NULL); + InvokeEvent(vtkCommand::KeyReleaseEvent, NULL); +#else + InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), + event.GetKeyCode(), 1); +#endif + event.Skip(); +} +#endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) +{ + if (!Enabled || (ActiveButton != wxEVT_NULL)) + { + return; + } + ActiveButton = event.GetEventType(); + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); +#endif + + if(event.RightDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::RightButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(event.LeftDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(event.MiddleDown()) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL); +#else + // old style + InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + //save the button and capture mouse until the button is released + //Only if : + //1. it is possible (WX_USE_X_CAPTURE) + //2. user decided to. + if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse) + { + CaptureMouse(); + } +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) +{ + //EVT_xxx_DOWN == EVT_xxx_UP - 1 + //This is only needed if two mouse buttons are pressed at the same time. + //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or + //wxEVT_COMMAND_RIGHT_CLICK + if (!Enabled || (ActiveButton != (event.GetEventType()-1))) + { + return; + } + +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); +#endif + + if(ActiveButton == wxEVT_RIGHT_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(ActiveButton == wxEVT_LEFT_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + else if(ActiveButton == wxEVT_MIDDLE_DOWN) + { +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL); +#else + // old style + InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(), + event.GetX(), Size[1] - event.GetY() - 1); +#endif + } + //if the ActiveButton is realeased, then release mouse capture + if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse) + { + ReleaseMouse(); + } + ActiveButton = wxEVT_NULL; +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event) +{ +// Mouse wheel was only added after VTK 4.4 (I think...) +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) + // new style + //Set vtk event information ... The numebr of wheel rotations is stored in + //the x varible. y varible is zero + SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, + event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); + if(event.GetWheelRotation() > 0) + { + //Send event to VTK +// EED +// InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL); + } + else + { + //Send event to VTK +// EED +// InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL); + } +#endif + +} + +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::Render() +{ + RenderAllowed = 1; + if (!RenderWhenDisabled) + { + //the user doesn't want us to render when the toplevel frame + //is disabled - first find the top level parent + wxWindow *topParent = wxGetTopLevelParent(this); + if (topParent) + { + //if it exists, check whether it's enabled + //if it's not enabeld, RenderAllowed will be false + RenderAllowed = topParent->IsEnabled(); + } + } + + if (RenderAllowed) + { + if(Handle && (Handle == GetHandleHack()) ) + { + RenderWindow->Render(); + } +#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) + else if(GetHandleHack()) + { + //this means the user has reparented us; let's adapt to the + //new situation by doing the WindowRemap dance + //store the new situation + Handle = GetHandleHack(); + RenderWindow->SetNextWindowId(reinterpret_cast(Handle)); + RenderWindow->WindowRemap(); + RenderWindow->Render(); + } +#endif + } +} +//--------------------------------------------------------------------------- +void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue) +{ + //Change value of __RenderWhenDisabled ivar. + //If __RenderWhenDisabled is false (the default), this widget will not + //call Render() on the RenderWindow if the top level frame (i.e. the + //containing frame) has been disabled. + + //This prevents recursive rendering during wxSafeYield() calls. + //wxSafeYield() can be called during the ProgressMethod() callback of + //a VTK object to have progress bars and other GUI elements updated - + //it does this by disabling all windows (disallowing user-input to + //prevent re-entrancy of code) and then handling all outstanding + //GUI events. + + //However, this often triggers an OnPaint() method for wxVTKRWIs, + //resulting in a Render(), resulting in Update() being called whilst + //still in progress. + + RenderWhenDisabled = (bool)newValue; +} +//--------------------------------------------------------------------------- +// +// Set the variable that indicates that we want a stereo capable window +// be created. This method can only be called before a window is realized. +// +void wxVTKRenderWindowInteractor::SetStereo(int capable) +{ + if (Stereo != capable) + { + Stereo = capable; + RenderWindow->StereoCapableWindowOn(); + RenderWindow->SetStereoTypeToCrystalEyes(); + Modified(); + } +} + +//--------------------------------------------------------------------------- +// +// +void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); +} + + +#if defined(_WIN32) +const char * wxVTKRenderWindowInteractor::GetClassName() const +{ + return "wxVTKRenderWindowInteractor"; +} +#endif //_WIN32 + +} +// LG : EO namespace +//======================================================================= + diff --git a/src/wxVTKRenderWindowInteractor.h b/src/wxVTKRenderWindowInteractor.h new file mode 100644 index 0000000..913cb58 --- /dev/null +++ b/src/wxVTKRenderWindowInteractor.h @@ -0,0 +1,187 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: $RCSfile: wxVTKRenderWindowInteractor.h,v $ + Language: C++ + Date: $Date: 2008/09/26 14:09:55 $ + Version: $Revision: 1.1 $ + + Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +// .NAME wxVTKRenderWindowInteractor - class to enable VTK to render to +// and interact with wxWindow. +// .SECTION Description +// wxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class +// was completely rewrote to have the 'Look & Feel' of the python version: +// wxVTKRenderWindowInteractor.py +// .SECTION Caveats +// - There is a know bug that prevent this class to works for more info see +// WX_USE_X_CAPTURE. This bug only affect wxGTK from 2.3.2 to wxGTK 2.4.0. +// - Furthermore this class is tempated over either wxWindows or wxGLCanvas, +// in wxWindows 2.3.1 and earlier, the wxGLCanvas had scroll bars, you can avoid +// this effect by playing with WX_BASE_CLASS at your risk (you might end up with +// lot of flickering.) +// - This class might not be easily readable as it tried to work with VTK 3.2 +// and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier. +// .SECTION see also +// wxVTKRenderWindowInteractor.py wxVTKRenderWindow.py + +#ifndef _wxVTKRenderWindowInteractor_h_ +#define _wxVTKRenderWindowInteractor_h_ + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +# pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include +#endif + +#include +#include + +// vtk includes +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderWindow.h" + +// Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any +// other port): +#if (!wxCHECK_VERSION(2, 8, 0)) +#define USE_WXGLCANVAS +#endif + + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +# if wxUSE_GLCANVAS +# include +# else +# error "problem of wxGLCanvas, you need to build wxWidgets with opengl" +# endif //wxUSE_GLCANVAS +#endif //__WXGTK__ + +// Motif version (renamed into wxX11 for wxWindow 2.4 and newer) +#if defined(__WXMOTIF__) +# error This GUI is not supported by wxVTKRenderWindowInteractor for now +#endif + + +// wx forward declarations +class wxPaintEvent; +class wxMouseEvent; +class wxTimerEvent; +class wxKeyEvent; +class wxSizeEvent; + +//======================================================================= +// LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS +namespace crea +{ + + +#if defined(__WXGTK__) && defined(USE_WXGLCANVAS) +class VTK_RENDERING_EXPORT wxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor +#else +class /*VTK_RENDERING_EXPORT*/ wxVTKRenderWindowInteractor : public wxWindow, virtual public vtkRenderWindowInteractor +#endif //__WXGTK__ +{ + DECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor) + + public: + //constructors + wxVTKRenderWindowInteractor(); + + wxVTKRenderWindowInteractor(wxWindow *parent, + wxWindowID id, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE, + const wxString &name = wxPanelNameStr); + //vtk ::New() + static wxVTKRenderWindowInteractor * New(); + void PrintSelf(ostream& os, vtkIndent indent); + + //destructor + ~wxVTKRenderWindowInteractor(); + +#if defined(_WIN32) + const char * wxVTKRenderWindowInteractor::GetClassName() const; +#endif //_WIN32 + + + // vtkRenderWindowInteractor overrides + void Initialize(); + void Enable(); + bool Enable(bool enable); + void Disable(); + void Start(); + void UpdateSize(int x, int y); + int CreateTimer(int timertype); + int DestroyTimer(); + void TerminateApp() {}; + + // event handlers + void OnPaint(wxPaintEvent &event); + void OnEraseBackground (wxEraseEvent& event); + void OnMotion(wxMouseEvent &event); + + void OnButtonDown(wxMouseEvent &event); + void OnButtonUp(wxMouseEvent &event); +#if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) + void OnEnter(wxMouseEvent &event); + void OnLeave(wxMouseEvent &event); + void OnKeyDown(wxKeyEvent &event); + void OnKeyUp(wxKeyEvent &event); +#endif + void OnTimer(wxTimerEvent &event); + void OnSize(wxSizeEvent &event); + void OnMouseWheel(wxMouseEvent& event); + + void Render(); + void SetRenderWhenDisabled(int newValue); + + // Description: + // Prescribe that the window be created in a stereo-capable mode. This + // method must be called before the window is realized. Default if off. + vtkGetMacro(Stereo,int); + vtkBooleanMacro(Stereo,int); + virtual void SetStereo(int capable); + + // Description: + // As CaptureMouse could be a problem sometimes on a window box + // This method allow to set or not the CaptureMouse. + // This method actually will works only if WX_USE_X_CAPTURE was set to 1 + vtkSetMacro(UseCaptureMouse,int); + vtkBooleanMacro(UseCaptureMouse,int); + + protected: + wxTimer timer; + int ActiveButton; + int RenderAllowed; + long GetHandleHack(); + int Stereo; + + private: + long Handle; + bool Created; + int RenderWhenDisabled; + int UseCaptureMouse; + + DECLARE_EVENT_TABLE() +}; + +} +// LG : EO namespace crea +//====================================================================== + +#endif //_wxVTKRenderWindowInteractor_h_