]> Creatis software - FrontAlgorithms.git/blobdiff - CMakeLists.txt
...
[FrontAlgorithms.git] / CMakeLists.txt
index 5182771b76c9d578a8a444d86ae29c953e1c6e3f..3e9783b4945d0d66b65d5cc1db9657158424e1fa 100644 (file)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-# for CMake 2.6 corrected behaviour (see "cmake --help-policy CMP0003")
-IF(
-    COMMAND cmake_policy AND
-    ${CMAKE_MAJOR_VERSION} EQUAL 2 AND
-    ${CMAKE_MINOR_VERSION} GREATER 4
-    )
-  CMAKE_POLICY(SET CMP0003 NEW)
-  CMAKE_POLICY(SET CMP0005 NEW)
-  CMAKE_POLICY(SET CMP0011 NEW)
-  CMAKE_POLICY(SET CMP0012 NEW)
-ENDIF(
-  COMMAND cmake_policy AND
-  ${CMAKE_MAJOR_VERSION} EQUAL 2 AND
-  ${CMAKE_MINOR_VERSION} GREATER 4
-  )
-
-## ================
-## = Project name =
-## ================
-
-PROJECT(FrontAlgorithms)
-SET(FrontAlgorithms_MAJOR_VERSION   "0")
-SET(FrontAlgorithms_MINOR_VERSION   "0")
-SET(FrontAlgorithms_RELEASE_VERSION "1")
-SET(FrontAlgorithms_VERSION "${FrontAlgorithms_MAJOR_VERSION}.${FrontAlgorithms_MINOR_VERSION}.${FrontAlgorithms_RELEASE_VERSION}")
-
-## ===========
-## = Options =
-## ===========
-
-OPTION(BUILD_EXAMPLES "Build examples" OFF)
-OPTION(BUILD_SHARED_LIBS "Build shared libs" OFF)
-
-IF(BUILD_SHARED_LIBS)
-  SET(LIB_TYPE SHARED)
-ELSE(BUILD_SHARED_LIBS)
-  SET(LIB_TYPE STATIC)
-ENDIF(BUILD_SHARED_LIBS)
-
-## ============
-## = Packages =
-## ============
-
-INCLUDE(GenerateExportHeader)
-
-## -------------------------------------------------------------------------
-## If compiling on UNIX-like OS, an error could arise when using ITKVtkGlue:
-##
-##   <command-line>:0:0: warning: "vtkRenderingCore_AUTOINIT" redefined
-##   <command-line>:0:0: note: this is the location of the previous definition
-##
-## This is avoided by not including the VTK_USE_FILE. Nevertheless, this fails
-## on MS-Win OS.
-##
-## This is due to object factories. To avoid this, and let the project be
-## usable on UNIX-like and MS-Win, the way to find ITK and VTK differs
-## -------------------------------------------------------------------------
-
-IF(UNIX)
-  FIND_PACKAGE(ITK REQUIRED)
-  FIND_PACKAGE(VTK REQUIRED)
-  INCLUDE(${ITK_USE_FILE})
-  IF(NOT ITKVtkGlue_LOADED)
-    MESSAGE(FATAL_ERROR "ITKVtkGlue module is required but not available.")
-  ENDIF(NOT ITKVtkGlue_LOADED)
-ELSE(UNIX)
-  FIND_PACKAGE(ITK REQUIRED)
-  INCLUDE(${ITK_USE_FILE})
-  IF(ITKVtkGlue_LOADED)
-    FIND_PACKAGE(VTK REQUIRED)
-    INCLUDE(${VTK_USE_FILE})
-  ELSE(ITKVtkGlue_LOADED)
-    FIND_PACKAGE(ItkVtkGlue REQUIRED)
-    INCLUDE(${ItkVtkGlue_USE_FILE})
-    SET(Glue ItkVtkGlue)
-  ENDIF(ITKVtkGlue_LOADED)
-ENDIF(UNIX)
-
-OPTION(USE_cpPlugins "Build cpPlugins based stuff" OFF)
-IF(USE_cpPlugins)
-  FIND_PACKAGE(cpPlugins REQUIRED)
-ENDIF(USE_cpPlugins)
-
-## ================================================
-## = Do not allow to build inside the source tree =
-## ================================================
-
-IF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
-  MESSAGE(FATAL_ERROR "Building in the source tree is not allowed")
-ENDIF(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
-
-## =====================================
-## = Where to put executables and libs =
-## =====================================
-
-SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
-SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
-MARK_AS_ADVANCED(
+## =========================================================================
+## @author Leonardo Florez Valencia
+## @email florez-l@javeriana.edu.co
+## =========================================================================
+
+cmake_minimum_required(VERSION 3.0)
+
+## ========================
+## == Project definition ==
+## ========================
+
+set(prj_MAJ_VER 0)
+set(prj_MIN_VER 1)
+set(prj_REL_VER 0)
+set(prj_VER "${prj_MAJ_VER}.${prj_MIN_VER}.${prj_REL_VER}")
+set(prj_SHORT_VER "${prj_MAJ_VER}")
+project(fpa VERSION ${prj_VER})
+
+## ==========================
+## == Some useful policies ==
+## ==========================
+
+set(_policies CMP0015 CMP0020 CMP0042 CMP0053)
+foreach(_p ${_policies})
+  if(POLICY ${_p})
+    cmake_policy(SET ${_p} NEW)
+  endif(POLICY ${_p})
+endforeach(_p)
+
+## =========================================================
+## == If working on a MacOSX, activate the use of RPATH's ==
+## ==   Furthermore: prepare the type of executables      ==
+## =========================================================
+
+set(EXECUTABLE_TYPE "" CACHE STRING "Executable linking." FORCE)
+if(APPLE)
+  set(EXECUTABLE_TYPE "MACOSX_BUNDLE" CACHE STRING "Executable linking." FORCE)
+  set(CMAKE_MACOSX_RPATH true CACHE BOOL "Use RPATH's on MacOSX." FORCE)
+  mark_as_advanced(CMAKE_MACOSX_RPATH)
+elseif(WIN32)
+  set(EXECUTABLE_TYPE "WIN32" CACHE STRING "Executable linking." FORCE)
+endif(APPLE)
+mark_as_advanced(EXECUTABLE_TYPE)
+
+## =======================================================================
+## == Force c++11 language version                                      ==
+## == NOTE: It seems that by default on Visual Studio Compiler supports ==
+## ==       c++11, so it only need to be tested on other OS.            ==
+## =======================================================================
+
+if(NOT MSVC)
+  include(CheckCXXCompilerFlag)
+  check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
+  if(COMPILER_SUPPORTS_CXX11)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+  else(COMPILER_SUPPORTS_CXX11)
+    check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+    if(COMPILER_SUPPORTS_CXX0X)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+    else(COMPILER_SUPPORTS_CXX0X)
+      message(
+        FATAL_ERROR
+        "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support."
+        )
+    endif(COMPILER_SUPPORTS_CXX0X)
+  endif(COMPILER_SUPPORTS_CXX11)
+endif(NOT MSVC)
+
+## ===================================================
+## == Prepare header generator to build shared libs ==
+## ===================================================
+
+include(GenerateExportHeader)
+
+## ==================================================
+## == Do not allow to build inside the source tree ==
+## ==================================================
+
+if(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
+  message(FATAL_ERROR "Building in the source tree is not allowed.")
+endif(PROJECT_BINARY_DIR STREQUAL ${PROJECT_SOURCE_DIR})
+
+## =================================================
+## == Where to put targets (executables and libs) ==
+## =================================================
+
+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 containing headers =
-## ==============================
-
-INCLUDE_DIRECTORIES(
-  ${PROJECT_SOURCE_DIR}/lib
-  ${PROJECT_BINARY_DIR}/lib
-  )
+## ===========================================
+## == Find needed packages and dependencies ==
+## ===========================================
+
+find_package(ITK CONFIG REQUIRED)
+include(${ITK_USE_FILE})
+if(ITKVtkGlue_LOADED)
+  find_package(VTK CONFIG REQUIRED)
+  include(${VTK_USE_FILE})
+endif(ITKVtkGlue_LOADED)
+
+## =========================
+## == Installation values ==
+## =========================
+
+set(config_install_dir "lib/cmake/${PROJECT_NAME}")
+set(include_install_dir "include")
+set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
+set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
+set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
+set(targets_export_name "${PROJECT_NAME}Targets")
+set(namespace "${PROJECT_NAME}::")
 
 ## ===========================
-## = Subdirs containing code =
+## == Build different parts ==
 ## ===========================
 
-SUBDIRS(
-  cmake
-  lib
-  appli
+subdirs(appli lib tests)
+
+## ===============================
+## == Global installation rules ==
+## ===============================
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+  "${version_config}" COMPATIBILITY SameMajorVersion
+  )
+configure_package_config_file(
+  "cmake/${PROJECT_NAME}Config.cmake.in"
+  "${project_config}"
+  INSTALL_DESTINATION "${config_install_dir}"
+  )
+install(
+  EXPORT "${targets_export_name}"
+  NAMESPACE "${namespace}"
+  DESTINATION "${config_install_dir}"
+  )
+install(
+  FILES "${project_config}"
+  DESTINATION "${config_install_dir}"
   )
 
 ## eof - $RCSfile$
+