]> Creatis software - crea.git/commitdiff
* creaNewProject template_lib updated
authorguigues <guigues>
Tue, 30 Sep 2008 08:35:48 +0000 (08:35 +0000)
committerguigues <guigues>
Tue, 30 Sep 2008 08:35:48 +0000 (08:35 +0000)
* new macros : CREA_ADD_LIBRARY / CREA_MANAGE_SHARED_LIBRARY

CMakeLists.txt
appli/creaNewProject/NewProject/CMakeLists.txt.in
appli/creaNewProject/NewProject/lib/CMakeLists.txt [new file with mode: 0644]
appli/creaNewProject/NewProject/lib/template_lib/CMakeLists.txt [new file with mode: 0644]
cmake/CREAMacro_AddLibrary.cmake [new file with mode: 0644]
cmake/CREAMacro_InstallLibraryForCMake.cmake [moved from cmake/CREAMacro_InstallLibrary.cmake with 96% similarity]
cmake/CREAMacro_ManageSharedLibrary.cmake [new file with mode: 0644]
cmake/CREAMacros.cmake
cmake/LIBRARY_NAMEDLLImportExport.h.in [new file with mode: 0644]
src/CMakeLists.txt

index 609d97710e61fe34f199f7608f1c1d0764fb7bbb..85de6e08a54fb13218fb412ff13f812da740f390 100644 (file)
@@ -49,7 +49,7 @@ ENDIF(BUILD_SAMPLES)
 #-----------------------------------------------------------------------------
 # Code installing the files needed to find the library
 # with the cmake command FIND_PACKAGE
-# Uses CREA_ADVANCED_INSTALL_LIBRARY macro
+# Uses CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE macro
 #-----------------------------------------------------------------------------
 
 #-----------------------------------------------------------------------------
@@ -91,5 +91,5 @@ SET(${LIBRARY_NAME}_ADDITIONAL_USE_FILE
   ${PROJECT_SOURCE_DIR}/AdditionalUsecrea.cmake.in)
 
 # Invoke the macro
-CREA_ADVANCED_INSTALL_LIBRARY(${LIBRARY_NAME})
+CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME})
 #-----------------------------------------------------------------------------
index 5fba43d96f6c57de7e148067d790af509b9481b1..f4a0f5ea60b78068a0ccd923ce4d3a70c5da3464 100644 (file)
@@ -1 +1,34 @@
 PROJECT(PROJECT_NAME)
+
+SET(PROJECT_MAJOR_VERSION 1)
+SET(PROJECT_MINOR_VERSION 0)
+SET(PROJECT_BUILD_VERSION 0)
+
+SET(CREA_VERBOSE_CMAKE TRUE)
+
+FIND_PACKAGE(crea REQUIRED)
+IF (crea_FOUND)
+  INCLUDE(${crea_USE_FILE})
+ENDIF(crea_FOUND)
+
+CREA_PREVENT_IN_SOURCE_BUILD()
+
+SET(USE_GDCM OFF)
+SET(USE_GDCM_VTK OFF)
+SET(USE_WXWIDGETS OFF)
+SET(USE_VTK OFF)
+SET(USE_ITK OFF)
+SET(USE_BOOST OFF)
+
+CREA_FIND_AND_USE_LIBRARIES()
+
+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
+  )
+
+SUBDIRS(appli)
+SUBDIRS(lib)
diff --git a/appli/creaNewProject/NewProject/lib/CMakeLists.txt b/appli/creaNewProject/NewProject/lib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8fc9678
--- /dev/null
@@ -0,0 +1,2 @@
+# Add a SUBDIRS command for each of your libraries
+# SUBDIRS(template_lib)
diff --git a/appli/creaNewProject/NewProject/lib/template_lib/CMakeLists.txt b/appli/creaNewProject/NewProject/lib/template_lib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a41e67d
--- /dev/null
@@ -0,0 +1,59 @@
+#----------------------------------------------------------------------------
+# SET THE NAME OF YOUR LIBRARY
+SET ( LIBRARY_NAME   MyLib  )
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# CREATES A USER OPTION IN CMAKE
+OPTION ( BUILD_${LIBRARY_NAME}  "Build ${LIBRARY_NAME} library ?" ON))
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+IF ( BUILD_${LIBRARY_NAME} )
+#----------------------------------------------------------------------------
+
+  #----------------------------------------------------------------------------
+  # BUILD LIBRARY
+  #----------------------------------------------------------------------------
+
+  #----------------------------------------------------------------------------
+  # LIBRARY HEADERS (TO BE INSTALLED)
+  # EITHER LIST ALL .h IN CURRENT DIR USING NEXT LINE:
+  FILE(GLOB ${LIBRARY_NAME}_HEADERS "*.h")
+  # OR MANUALLY LIST YOUR HEADERS WITH NEXT COMMAND
+  #  SET ( ${LIBRARY_NAME}_HEADERS
+  #
+  #    )
+  #----------------------------------------------------------------------------
+
+  #----------------------------------------------------------------------------
+  # LIBRARY SOURCES (TO BE COMPILED)
+  # EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
+  FILE(GLOB ${LIBRARY_NAME}_SOURCES *.cxx *.cpp *.cc)
+  # OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
+  #  SET ( ${LIBRARY_NAME}_SOURCES 
+  #   
+  #    )
+  #----------------------------------------------------------------------------
+
+  #----------------------------------------------------------------------------
+  # LIBRARY DEPENDENCIES (LIBRARIES TO LINK WITH)
+  SET ( ${LIBRARY_NAME}_LINK_LIBRARIES
+    ${crea_LIBRARIES}
+    #    ${WXWIDGETS_LIBRARIES}
+    #    ${VTK_LIBRARIES}
+    #    ${ITK_LIBRARIES}
+    #    ${GDCM_LIBRARIES}
+    #    ${BOOST_LIBRARIES}
+    )
+  #----------------------------------------------------------------------------
+
+  
+  #----------------------------------------------------------------------------
+  # MACRO WHICH DOES ALL THE JOB : BUILD AND INSTALL
+  CREA_ADD_LIBRARY( ${LIBRARY_NAME} )
+  #----------------------------------------------------------------------------
+
+
+  #---------------------------------------------------------------------------
+ENDIF ( BUILD_${LIBRARY_NAME} )
diff --git a/cmake/CREAMacro_AddLibrary.cmake b/cmake/CREAMacro_AddLibrary.cmake
new file mode 100644 (file)
index 0000000..3597ad5
--- /dev/null
@@ -0,0 +1,41 @@
+# Creates and installs a library
+# Uses CREA_MANAGE_SHARED_LIBRARY and CREA_INSTALL_LIBRARY
+# hence the variables to be set for these are needed 
+# Additionnaly one needs to set :
+# ${LIBRARY_NAME}_HEADERS : the list of headers to install
+# ${LIBRARY_NAME}_SOURCES : the list of files to compile to build the lib
+# ${LIBRARY_NAME}_LINK_LIBRARIES : the list of libs to link with
+MACRO(CREA_ADD_LIBRARY LIBRARY_NAME)
+
+  IF(CREA_VERBOSE_CMAKE)
+    MESSAGE(STATUS "** Creating library ${LIBRARY_NAME}")
+    MESSAGE(STATUS "   Headers  : ${${LIBRARY_NAME}_HEADERS}")
+    MESSAGE(STATUS "   Sources  : ${${LIBRARY_NAME}_SOURCES}")
+    MESSAGE(STATUS "   Link libs: ${${LIBRARY_NAME}_LINK_LIBRARIES}")
+  ENDIF(CREA_VERBOSE_CMAKE)
+
+
+  # MANAGE SHARED LIB
+  CREA_MANAGE_SHARED_LIBRARY(${LIBRARY_NAME})
+
+  # CREATE THE TARGET
+  ADD_LIBRARY(${LIBRARY_NAME} ${${LIBRARY_NAME}_SHARED} ${${LIBRARY_NAME}_SOURCES})
+
+  # LINK
+  TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES})
+
+  # INSTALLS LIBRARY FOR CMAKE
+  CREA_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME})
+
+  # INSTALLS LIBRARY
+  INSTALL(
+    FILES ${${LIBRARY_NAME}_HEADERS}
+    DESTINATION ${${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_INCLUDE_PATHS}
+    )  
+  INSTALL(
+    TARGETS ${LIBRARY_NAME}
+    DESTINATION lib)
+
+
+ENDMACRO(CREA_ADD_LIBRARY)
+
similarity index 96%
rename from cmake/CREAMacro_InstallLibrary.cmake
rename to cmake/CREAMacro_InstallLibraryForCMake.cmake
index e49eb76929b5363b74dab1a34006b2e5a3232b8a..4e08f05b476d98e6aa2dd5e5b9af6ecf4217794b 100644 (file)
@@ -1,7 +1,7 @@
 #-----------------------------------------------------------------------------
-# Macro CREA_ADVANCED_INSTALL_LIBRARY
+# Macro CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE
 # Creates and install the cmake files which allow 
-# to find a library by the cmake command FIND_PACKAGE.
+# to find the library by the cmake command FIND_PACKAGE.
 #
 # Inputs :
 # --------
@@ -94,7 +94,7 @@
 #
 #-----------------------------------------------------------------------------
 
-MACRO(CREA_ADVANCED_INSTALL_LIBRARY LIBRARY_NAME)
+MACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME)
 
   #---------------------------------------------------------------------------
   # Sets the common values to build tree and install tree configs
@@ -156,8 +156,10 @@ MACRO(CREA_ADVANCED_INSTALL_LIBRARY LIBRARY_NAME)
 
   #---------------------------------------------------------------------------
   #-- INSTALL TREE configuration 
+
+
   SET(CILC_BUILD_TREE_CONFIGURATION FALSE)
-  # CREAte work directory to put the configured files because 
+  # 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)
@@ -178,6 +180,7 @@ MACRO(CREA_ADVANCED_INSTALL_LIBRARY LIBRARY_NAME)
   ENDIF(WIN32)
 
 
+
   # UseLIBRARY_NAME.cmake 
   CONFIGURE_FILE(
     ${CREA_CMAKE_DIR}/InstallLibraryForCMake_UseLibrary.cmake.in
@@ -250,14 +253,14 @@ MACRO(CREA_ADVANCED_INSTALL_LIBRARY LIBRARY_NAME)
 
 
 
-ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY)
+ENDMACRO(CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE)
 #-----------------------------------------------------------------------------
 
 
 
 
 #-----------------------------------------------------------------------------
-MACRO(CREA_INSTALL_LIBRARY LIBRARY_NAME)
+MACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE LIBRARY_NAME)
   
   # Sets the settings to default values
   SET(${LIBRARY_NAME}_INSTALL_FOLDER ${LIBRARY_NAME})
@@ -280,8 +283,8 @@ MACRO(CREA_INSTALL_LIBRARY LIBRARY_NAME)
   SET(${LIBRARY_NAME}_INSTALL_TREE_RELATIVE_LIBRARY_PATHS lib)
   
   # Invoke the advanced macro
-  CREA_ADVANCED_INSTALL_LIBRARY(${LIBRARY_NAME})
+  CREA_ADVANCED_INSTALL_LIBRARY_FOR_CMAKE(${LIBRARY_NAME})
 
 
-ENDMACRO(CREA_INSTALL_LIBRARY)
+ENDMACRO(CREA_INSTALL_LIBRARY_FOR_CMAKE)
 #-----------------------------------------------------------------------------
diff --git a/cmake/CREAMacro_ManageSharedLibrary.cmake b/cmake/CREAMacro_ManageSharedLibrary.cmake
new file mode 100644 (file)
index 0000000..bbfabd6
--- /dev/null
@@ -0,0 +1,35 @@
+# Manages the shared library creation/use 
+# * Creates an option ${LIBRARY_NAME}_BUILD_SHARED 
+# * Generates the file ${LIBRARY_NAME}DLLImportExport.h which 
+#   defines the symbols ${LIBRARY_NAME}_EXPORT and ${LIBRARY_NAME}_CDECL
+#   to be used in exported classes/functions declarations
+MACRO(CREA_MANAGE_SHARED_LIBRARY LIBRARY_NAME)
+
+  # STATIC OR DYNAMIC (SHARED) ? 
+  OPTION( ${LIBRARY_NAME}_BUILD_SHARED 
+    "Build ${LIBRARY_NAME} as a shared library (dynamic) ?" ON)
+  IF (${LIBRARY_NAME}_BUILD_SHARED)
+    SET(${LIBRARY_NAME}_SHARED SHARED)
+    CREA_DEFINE(${LIBRARY_NAME}_BUILD_SHARED)
+  ENDIF(${LIBRARY_NAME}_BUILD_SHARED)
+  
+  CREA_DEFINE(${LIBRARY_NAME}_EXPORT_SYMBOLS)
+
+  # ADDS CURRENT BINARY DIR TO INCLUDE DIRS
+  INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+
+  # CONFIGURES ${LIBRARY_NAME}DLLImportExport.h
+  CONFIGURE_FILE(
+    ${CREA_CMAKE_DIR}/LIBRARY_NAMEDLLImportExport.h.in
+    ${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_NAME}DLLImportExport.h
+    @ONLY IMMEDIATE
+    )
+  # ADDS IT TO THE LIST OF HEADERS
+  SET(${LIBRARY_NAME}_HEADERS
+    ${${LIBRARY_NAME}_HEADERS}
+    ${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_NAME}DLLImportExport.h
+    )
+  
+
+ENDMACRO(CREA_MANAGE_SHARED_LIBRARY LIBRARY_NAME)
+
index 1fe5b73cb12a6a6264acf3b63a4dc1157c965473..f0cc2e191e47fcb006432af75c09abf2f95220c2 100644 (file)
@@ -7,7 +7,15 @@ INCLUDE( ${CREA_CMAKE_DIR}/CREAMacro_FindAndUseLibraries.cmake)
 #========================================================================
 
 #========================================================================
-INCLUDE( ${CREA_CMAKE_DIR}/CREAMacro_InstallLibrary.cmake )
+INCLUDE( ${CREA_CMAKE_DIR}/CREAMacro_InstallLibraryForCMake.cmake )
+#========================================================================
+
+#========================================================================
+INCLUDE( ${CREA_CMAKE_DIR}/CREAMacro_ManageSharedLibrary.cmake )
+#========================================================================
+
+#========================================================================
+INCLUDE( ${CREA_CMAKE_DIR}/CREAMacro_AddLibrary.cmake )
 #========================================================================
 
 #========================================================================
diff --git a/cmake/LIBRARY_NAMEDLLImportExport.h.in b/cmake/LIBRARY_NAMEDLLImportExport.h.in
new file mode 100644 (file)
index 0000000..038f1ec
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __@LIBRARY_NAME@DLLImportExport_h_INCLUDED__
+#define __@LIBRARY_NAME@DLLImportExport_h_INCLUDED__
+
+// Automatically generated file which defines 
+// the symbols @LIBRARY_NAME@_EXPORT and @LIBRARY_NAME@_CDECL
+// to be used for the definition of classes or functions
+// which must be exported when the lib is built as a shared lib on Windows
+// and imported when the shared lib is used by another program
+
+#if defined(_WIN32) && defined (@LIBRARY_NAME@_BUILD_SHARED)
+  #ifdef @LIBRARY_NAME@_EXPORT_SYMBOLS
+    #define @LIBRARY_NAME@_EXPORT __declspec( dllexport )
+#else
+    #define @LIBRARY_NAME@_EXPORT __declspec( dllimport )
+  #endif
+  #define @LIBRARY_NAME@_CDECL __cdecl
+#else
+  #define @LIBRARY_NAME@_EXPORT
+  #define @LIBRARY_NAME@_CDECL
+#endif // defined(_WIN32)
+
+#endif
+
index 5a0c716c6b2e0e4cae6a8cd07ef64d6a3734d5c9..c6723c2b6efc06a836d5df501400f79c10c0ec74 100644 (file)
@@ -1,4 +1,6 @@
+#-----------------------------------------------------------------------------
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+#-----------------------------------------------------------------------------
 
 #-----------------------------------------------------------------------------
 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
@@ -52,7 +54,7 @@ TARGET_LINK_LIBRARIES(crea
 
 #----------------------------------------------------------------------------
 # INSTALLS LIBRARY
-FILE(GLOB HEADERS "*.h")
+FILE(GLOB crea_HEADERS "*.h")
 INSTALL(
   FILES ${HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/creaConfigure.h
   DESTINATION include/crea