ACGCommon.cmake 32.5 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5
if (EXISTS ${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.cmake)
  include (${CMAKE_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.cmake)
endif ()

# prevent build in source directory
6 7 8 9 10 11 12 13 14 15 16 17 18 19

# add option to disable plugin build
option (
  BLOCK_IN_SOURCE_BUILD
  "Disable building inside the source tree"
  ON
)

if ( BLOCK_IN_SOURCE_BUILD )
  if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
      message (SEND_ERROR "Building in the source directory is not supported.")
      message (FATAL_ERROR "Please remove the created \"CMakeCache.txt\" file, the \"CMakeFiles\" directory and create a build directory and call \"${CMAKE_COMMAND} <path to the sources>\".")
  endif ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
endif()
Jan Möbius's avatar
 
Jan Möbius committed
20 21

# allow only Debug and Release builds
Matthias Möller's avatar
Matthias Möller committed
22
set (CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "" FORCE)
Jan Möbius's avatar
 
Jan Möbius committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36
mark_as_advanced (CMAKE_CONFIGURATION_TYPES)

# set Debus as default build target
if (NOT CMAKE_BUILD_TYPE)
  set (CMAKE_BUILD_TYPE Debug CACHE STRING
      "Choose the type of build, options are: Debug, Release."
      FORCE)
endif ()

# create our output directroy
if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build)
  file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build)
endif ()

37
#generate the global doc target (but only once!)
Jan Möbius's avatar
Jan Möbius committed
38
if ( NOT TARGET doc )
39 40 41 42
  ADD_CUSTOM_TARGET( doc )
  SET_TARGET_PROPERTIES( doc PROPERTIES EchoString "Building Documentation"  )
endif()

Jan Möbius's avatar
 
Jan Möbius committed
43 44
# read version from file
macro (acg_get_version)
45 46 47
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/branding/VERSION")
      file (READ "${CMAKE_CURRENT_SOURCE_DIR}/branding/VERSION" _file)
    elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}/VERSION")
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
48 49 50 51 52 53 54 55 56 57
      file (READ "${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}/VERSION" _file)
    else ()
      file (READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" _file)
    endif ()

    string (
        REGEX REPLACE
        "^.*ID=([^\n]*).*$" "\\1"
        _id ${_file}
    )
Jan Möbius's avatar
 
Jan Möbius committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    string (
        REGEX REPLACE
        "^.*VERSION=([^\n]*).*$" "\\1"
        _version ${_file}
    )
    string (
        REGEX REPLACE
        "^.*MAJOR=([^\n]*).*$" "\\1"
        _major ${_file}
    )
    string (
        REGEX REPLACE
        "^.*MINOR=([^\n]*).*$" "\\1"
        _minor ${_file}
    )
    string (
        REGEX REPLACE
        "^.*PATCH=([^\n]*).*$" "\\1"
        _patch ${_file}
    )
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
78 79 80 81 82

    set (${_id}_VERSION ${_version})
    set (${_id}_VERSION_MAJOR ${_major})
    set (${_id}_VERSION_MINOR ${_minor})
    set (${_id}_VERSION_PATCH ${_patch})
Jan Möbius's avatar
 
Jan Möbius committed
83 84 85 86 87 88
endmacro ()


# set directory structures for the different platforms
if (WIN32)
  set (ACG_PROJECT_DATADIR ".")
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
89 90
  set (ACG_PROJECT_LIBDIR "lib")
  set (ACG_PROJECT_BINDIR ".")
Jan Möbius's avatar
 
Jan Möbius committed
91
  set (ACG_PROJECT_PLUGINDIR "Plugins")
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
92 93
  if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR})
    file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR})
Jan Möbius's avatar
 
Jan Möbius committed
94 95 96
  endif ()
else ()
  set (ACG_PROJECT_DATADIR "share/${CMAKE_PROJECT_NAME}")
Matthias Möller's avatar
Matthias Möller committed
97 98
  set (ACG_PROJECT_LIBDIR "lib${LIB_SUFFIX}")
  set (ACG_PROJECT_PLUGINDIR "lib${LIB_SUFFIX}/plugins")
Jan Möbius's avatar
 
Jan Möbius committed
99 100 101
  set (ACG_PROJECT_BINDIR "bin")
endif ()

Jan Möbius's avatar
Jan Möbius committed
102 103 104 105 106 107 108 109 110
if( NOT APPLE )
  # check 64 bit
  if( CMAKE_SIZEOF_VOID_P MATCHES 4 )
    set( HAVE_64_BIT 0 )
  else( CMAKE_SIZEOF_VOID_P MATCHES 4 )
    set( HAVE_64_BIT 1 )
  endif( CMAKE_SIZEOF_VOID_P MATCHES 4 )
endif (  NOT APPLE )

Jan Möbius's avatar
 
Jan Möbius committed
111 112 113 114 115
# allow a project to modify the directories
if (COMMAND acg_modify_project_dirs)
  acg_modify_project_dirs ()
endif ()

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
116 117 118 119 120
if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR})
 file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR})
endif ()


Jan Möbius's avatar
 
Jan Möbius committed
121 122
# sets default build properties
macro (acg_set_target_props target)
123 124 125 126 127

  if (NOT (CMAKE_MAJOR_VERSION  LESS 3))
    cmake_policy(SET CMP0042 NEW) #enables MACOSX_RPATH for all targets per default
  endif()

Jan Möbius's avatar
 
Jan Möbius committed
128 129 130 131 132 133 134
  if (WIN32)
    set_target_properties (
      ${target} PROPERTIES
      BUILD_WITH_INSTALL_RPATH 1
      SKIP_BUILD_RPATH 0
    )
  elseif (APPLE AND NOT ACG_PROJECT_MACOS_BUNDLE)
Matthias Möller's avatar
Matthias Möller committed
135
  if (NOT (CMAKE_MAJOR_VERSION  LESS 3) )
136 137 138 139 140 141 142 143 144 145 146 147 148 149
      set_target_properties (
        ${target} PROPERTIES
        INSTALL_RPATH "@executable_path/../${ACG_PROJECT_LIBDIR}"
        MACOSX_RPATH 1
        BUILD_WITH_INSTALL_RPATH 1
        SKIP_BUILD_RPATH 0
      )  
    else()
      set_target_properties (
        ${target} PROPERTIES
        INSTALL_NAME_DIR "@executable_path/../${ACG_PROJECT_LIBDIR}"
        BUILD_WITH_INSTALL_RPATH 1
        SKIP_BUILD_RPATH 0
      ) 
Matthias Möller's avatar
Matthias Möller committed
150
    endif(NOT (CMAKE_MAJOR_VERSION  LESS 3) )
Jan Möbius's avatar
 
Jan Möbius committed
151
  elseif (NOT APPLE)
Jan Möbius's avatar
Jan Möbius committed
152

Jan Möbius's avatar
 
Jan Möbius committed
153 154
    set_target_properties (
      ${target} PROPERTIES
Matthias Möller's avatar
Matthias Möller committed
155
      INSTALL_RPATH "$ORIGIN/../${ACG_PROJECT_LIBDIR}"
Jan Möbius's avatar
 
Jan Möbius committed
156 157 158 159 160
      BUILD_WITH_INSTALL_RPATH 1
      SKIP_BUILD_RPATH 0
      RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR}"
      LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR}"
    )
Jan Möbius's avatar
Jan Möbius committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

    # prepare for cross compiling
    if ( HAVE_64_BIT )
      if ( NOT CROSS_COMPILE_32)
        # Already in cache, be silent
        set( CROSS_COMPILE_32 false CACHE BOOL "Compile for 32-bit architecture")
      endif( NOT  CROSS_COMPILE_32 )

      if ( CROSS_COMPILE_32 )
        add_definitions( -m32 )
        set_target_properties( ${target} PROPERTIES LINK_FLAGS -m32  )
      endif ( CROSS_COMPILE_32 )

    else ( HAVE_64_BIT )

      if ( NOT CROSS_COMPILE_64)
        # Already in cache, be silent
        set( CROSS_COMPILE_64 false CACHE BOOL "Compile for 64-bit architecture")
      endif( NOT  CROSS_COMPILE_64 )

      if ( CROSS_COMPILE_64 )
        add_definitions( -m64 )
        set_target_properties( ${target} PROPERTIES LINK_FLAGS -m64  )
      endif ( CROSS_COMPILE_64 )

    endif( HAVE_64_BIT )

Jan Möbius's avatar
 
Jan Möbius committed
188 189 190 191 192 193 194 195 196
  endif ()
endmacro ()

include (AddFileDependencies)
include (ACGCompiler)

# define INCLUDE_TEMPLATES for everything we build
add_definitions (-DINCLUDE_TEMPLATES)

Matthias Möller's avatar
Matthias Möller committed
197 198 199 200 201 202 203 204 205 206 207 208
#unset cached qt variables which are set by all qt versions. version is the major number of the qt version (e.g. 4 or 5, not 4.8)
macro (acg_unset_qt_shared_variables version)
  if (ACG_INTERNAL_QT_LAST_VERSION)
    if (NOT ${ACG_INTERNAL_QT_LAST_VERSION} EQUAL ${version})
      unset(QT_BINARY_DIR)
      unset(QT_PLUGINS_DIR)
      unset(ACG_INTERNAL_QT_LAST_VERSION)
    endif()
  endif()
  set (ACG_INTERNAL_QT_LAST_VERSION "${version}" CACHE INTERNAL "Qt Version, which was used on the last time")
endmacro()

Jan Möbius's avatar
 
Jan Möbius committed
209 210 211
# look for selected qt dependencies
macro (acg_qt4)
  if (NOT QT4_FOUND)
Matthias Möller's avatar
Matthias Möller committed
212
    acg_unset_qt_shared_variables(4)
213
    set (QT_MIN_VERSION ${ARGN}) 
Jan Möbius's avatar
Jan Möbius committed
214

215 216 217 218 219
    if(POLICY CMP0020)
      # Automatically link Qt executables to qtmain target on Windows
      cmake_policy(SET CMP0020 NEW)
    endif(POLICY CMP0020)

Jan Möbius's avatar
Jan Möbius committed
220
    find_package (Qt4 COMPONENTS QtCore QtGui )
Jan Möbius's avatar
 
Jan Möbius committed
221 222 223 224 225

    set (QT_USE_QTOPENGL 1)
    set (QT_USE_QTNETWORK 1)
    set (QT_USE_QTSCRIPT 1)
    set (QT_USE_QTSQL 1)
Jan Möbius's avatar
Jan Möbius committed
226
    set (QT_USE_QTXML 1)
Jan Möbius's avatar
Jan Möbius committed
227
    set (QT_USE_QTXMLPATTERNS 1)
Jan Möbius's avatar
 
Jan Möbius committed
228 229 230 231
    set (QT_USE_QTHELP 1)
    set (QT_USE_QTWEBKIT 1)
    set (QT_USE_QTUITOOLS 1)

232 233 234 235
    if (QT_QTSCRIPTTOOLS_FOUND)
      set (QT_USE_QTSCRIPTTOOLS 1)
    endif()

Jan Möbius's avatar
 
Jan Möbius committed
236 237 238 239
    include (${QT_USE_FILE})
  endif ()
endmacro ()

Matthias Möller's avatar
Matthias Möller committed
240
macro (acg_qt5)
241 242 243 244 245

   if(POLICY CMP0020)
     # Automatically link Qt executables to qtmain target on Windows
     cmake_policy(SET CMP0020 NEW)
   endif(POLICY CMP0020)
Matthias Möller's avatar
Matthias Möller committed
246 247 248 249
  #if (NOT QT5_FOUND)

    #set (QT_MIN_VERSION ${ARGN})

Matthias Möller's avatar
Matthias Möller committed
250 251 252 253 254 255 256 257
  #try to find qt5 automatically
  #for custom installation of qt5, dont use any of these variables
  set (QT5_INSTALL_PATH "" CACHE PATH "Path to Qt5 directory which contains lib and include folder")
  if (EXISTS "${QT5_INSTALL_PATH}")
    set (CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${QT5_INSTALL_PATH}")
    set (QT5_INSTALL_PATH_EXISTS TRUE)
  endif()
  
258
  
Jan Möbius's avatar
Jan Möbius committed
259
    
Matthias Möller's avatar
Matthias Möller committed
260
    find_package (Qt5Core QUIET)
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
     
    #find WINDOWS_SDK to avoid qt error. This must be done BEFORE Qt5Widgets is searched
    if (Qt5Core_FOUND AND WIN32)    
      string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${Qt5Core_VERSION_STRING}")
      string(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${Qt5Core_VERSION_STRING}")
      string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${Qt5Core_VERSION_STRING}")
    
      if ( (QT_VERSION_MAJOR EQUAL 5) AND (QT_VERSION_MINOR LESS 3 OR ( QT_VERSION_MINOR EQUAL 3 AND QT_VERSION_PATCH EQUAL 0 )) ) # for all Qt version > 5.0.0 and < 5.3.1
        #glu32.lib is needed by qt5 opengl version. it cannot find it by itself so we help qt
        #this block has to be executed, before Qt5Gui is searched, otherwise we will end up with the (not so useful) QT5 error message 
        set(WINDOWS_SDK_LIBS "COULD_NOT_FOUND" CACHE PATH "Path to the latest windows sdk libs which includes glu32.lib. Used by Qt5.")
        if (EXISTS "${WINDOWS_SDK_LIBS}\\glu32.lib")
          set (CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${WINDOWS_SDK_LIBS}")
        elseif(QT5_INSTALL_PATH_EXISTS) #trying to install qt5. notify about missing sdk before the qt message comes
          message(FATAL_ERROR "Could not find glu32.lib. This is necessary for QT5 OpenGL version for windows, spleace specify glu32.lib in WINDOWS_SDK_LIB or install Qt version >= 5.3.1")
        endif()
      endif()    
    endif(Qt5Core_FOUND AND WIN32)
    
Matthias Möller's avatar
Matthias Möller committed
280
    find_package (Qt5Declarative QUIET)
281
    find_package (Qt5Widgets QUIET)    
Matthias Möller's avatar
Matthias Möller committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295
    find_package (Qt5Gui QUIET)
    find_package (Qt5OpenGL QUIET)
    find_package (Qt5Network QUIET)
    find_package (Qt5Script QUIET)
    find_package (Qt5ScriptTools QUIET)
    find_package (Qt5Sql QUIET)
    find_package (Qt5Xml QUIET)
    find_package (Qt5XmlPatterns QUIET)
    find_package (Qt5Help QUIET)
    find_package (Qt5WebKit QUIET)
    find_package (Qt5UiTools QUIET)
    find_package (Qt5Concurrent QUIET)
    find_package (Qt5PrintSupport QUIET)
    find_package (Qt5Svg QUIET)
Jan Möbius's avatar
Jan Möbius committed
296 297
    
    if (NOT WIN32 AND NOT APPLE)
Matthias Möller's avatar
Matthias Möller committed
298
    	find_package (Qt5X11Extras QUIET)
Jan Möbius's avatar
Jan Möbius committed
299 300 301
    endif ()
    

Matthias Möller's avatar
Matthias Möller committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
    if (Qt5Core_FOUND AND Qt5Declarative_FOUND AND Qt5Widgets_FOUND
      AND Qt5Gui_FOUND AND Qt5OpenGL_FOUND AND Qt5Network_FOUND
      AND Qt5Script_FOUND AND Qt5ScriptTools_FOUND AND Qt5Sql_FOUND
      AND Qt5Xml_FOUND AND Qt5XmlPatterns_FOUND AND Qt5Help_FOUND
      AND Qt5WebKit_FOUND AND Qt5UiTools_FOUND AND Qt5Concurrent_FOUND
      AND Qt5PrintSupport_FOUND)
      set (QT5_FOUND TRUE)
    endif()
    
    if (QT5_FOUND)   
      acg_unset_qt_shared_variables(5)
    
      #set plugin dir
      list(GET Qt5Gui_PLUGINS 0 _plugin)
      if (_plugin)
        get_target_property(_plugin_full ${_plugin} LOCATION)
        get_filename_component(_plugin_dir ${_plugin_full} PATH)
      set (QT_PLUGINS_DIR "${_plugin_dir}/../" CACHE PATH "Path to the qt plugin directory")
      elseif(QT5_INSTALL_PATH_EXISTS)
        set (QT_PLUGINS_DIR "${QT5_INSTALL_PATH}/plugins/" CACHE PATH "Path to the qt plugin directory")
      elseif()
        set (QT_PLUGINS_DIR "QT_PLUGIN_DIR_NOT_FOUND" CACHE PATH "Path to the qt plugin directory")
      endif(_plugin)
      
      #set binary dir for fixupbundle
      if(QT5_INSTALL_PATH_EXISTS)
        set(_QT_BINARY_DIR "${QT5_INSTALL_PATH}/bin")
      else()
        get_target_property(_QT_BINARY_DIR ${Qt5Widgets_UIC_EXECUTABLE} LOCATION)
        get_filename_component(_QT_BINARY_DIR ${_QT_BINARY_DIR} PATH)
      endif(QT5_INSTALL_PATH_EXISTS)
      
      set (QT_BINARY_DIR "${_QT_BINARY_DIR}" CACHE PATH "Qt5 binary Directory")
      mark_as_advanced(QT_BINARY_DIR)
      
      set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  
Matthias Möller's avatar
Matthias Möller committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
      include_directories(${Qt5Core_INCLUDE_DIRS})
      include_directories(${Qt5Declarative_INCLUDE_DIRS})
      include_directories(${Qt5Widgets_INCLUDE_DIRS})
      include_directories(${Qt5Gui_INCLUDE_DIRS})
      include_directories(${Qt5OpenGL_INCLUDE_DIRS})
      include_directories(${Qt5Network_INCLUDE_DIRS})
      include_directories(${Qt5Script_INCLUDE_DIRS})
      include_directories(${Qt5ScriptTools_INCLUDE_DIRS})
      include_directories(${Qt5Sql_INCLUDE_DIRS})
      include_directories(${Qt5Xml_INCLUDE_DIRS})
      include_directories(${Qt5XmlPatterns_INCLUDE_DIRS})
      include_directories(${Qt5Help_INCLUDE_DIRS})
      include_directories(${Qt5WebKit_INCLUDE_DIRS})
      include_directories(${Qt5UiTools_INCLUDE_DIRS})
      include_directories(${Qt5Concurrent_INCLUDE_DIRS})
      include_directories(${Qt5PrintSupport_INCLUDE_DIRS})
      add_definitions(${Qt5Core_DEFINITIONS})
      add_definitions(${Qt5Widgets_DEFINITIONS})
      add_definitions(${Qt5Gui_DEFINITIONS})
      add_definitions(${Qt5OpenGL_DEFINITIONS})
      add_definitions(${Qt5Network_DEFINITIONS})
      add_definitions(${Qt5Script_DEFINITIONS})
      add_definitions(${Qt5ScriptTools_DEFINITIONS})
      add_definitions(${Qt5Sql_DEFINITIONS})
      add_definitions(${Qt5Xml_DEFINITIONS})
      add_definitions(${Qt5XmlPatterns_DEFINITIONS})
      add_definitions(${Qt5Help_DEFINITIONS})
      add_definitions(${Qt5WebKit_DEFINITIONS})
      add_definitions(${Qt5UiTools_DEFINITIONS})
      add_definitions(${Qt5Concurrent_DEFINITIONS})
      add_definitions(${Qt5PrintSupport_DEFINITIONS})
370
      
371 372 373 374 375
      if (Qt5X11Extras_FOUND)
	      include_directories(${Qt5X11Extras_INCLUDE_DIRS})
	      add_definitions(${Qt5X11Extras_DEFINITIONS})
      endif ()
      
376 377 378
      if ( NOT MSVC )
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
      endif()
Jan Möbius's avatar
Jan Möbius committed
379

Matthias Möller's avatar
Matthias Möller committed
380
      set (QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Declarative_LIBRARIES} ${Qt5Widgets_LIBRARIES}
Matthias Möller's avatar
Matthias Möller committed
381 382 383
        ${Qt5Gui_LIBRARIES} ${Qt5OpenGL_LIBRARIES} ${Qt5Network_LIBRARIES}
        ${Qt5Script_LIBRARIES} ${Qt5ScriptTools_LIBRARIES} ${Qt5Sql_LIBRARIES}
        ${Qt5Xml_LIBRARIES} ${Qt5XmlPatterns_LIBRARIES} ${Qt5Help_LIBRARIES}
Matthias Möller's avatar
Matthias Möller committed
384 385
        ${Qt5WebKit_LIBRARIES} ${Qt5UiTools_LIBRARIES} ${Qt5Concurrent_LIBARIES} 
        ${Qt5PrintSupport_LIBRARIES})
386 387 388 389
        
      if (Qt5X11Extras_FOUND)
	      list (APPEND QT_LIBRARIES ${Qt5X11Extras_LIBRARIES})
	  endif ()
Matthias Möller's avatar
Matthias Möller committed
390
       
391 392 393
      if (MSVC)
        set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5Core_QTMAIN_LIBRARIES})
      endif()
Jan Möbius's avatar
Jan Möbius committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

	  #add_definitions(-DQT_NO_OPENGL)

	  #adding QT_NO_DEBUG to all release modes. 
	  #  Note: for multi generators like msvc you cannot set this definition depending of
	  #  the current build type, because it may change in the future inside the ide and not via cmake
	  if (MSVC_IDE)
	    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
	    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
		
		set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
	    set(CMAKE_CXX_FLAGS_MINSITEREL "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
		
		set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
	    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} /DQT_NO_DEBUG")
	  else(MSVC_IDE)
	    if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
	      add_definitions(-DQT_NO_DEBUG)
	    endif()
      endif(MSVC_IDE)

    endif ()
Matthias Möller's avatar
Matthias Möller committed
416 417
endmacro ()

Jan Möbius's avatar
 
Jan Möbius committed
418 419 420 421 422 423 424 425 426 427 428 429 430
# unsets the given variable
macro (acg_unset var)
    set (${var} "" CACHE INTERNAL "")
endmacro ()

# sets the given variable
macro (acg_set var value)
    set (${var} ${value} CACHE INTERNAL "")
endmacro ()

# test for OpenMP
macro (acg_openmp)
  if (NOT OPENMP_NOTFOUND)
431 432
    # Set off OpenMP on Darwin architectures
    # since it causes crashes sometimes
433
#    if(NOT APPLE)    
434 435 436 437 438
        find_package(OpenMP)
      if (OPENMP_FOUND)
        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
        set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
        add_definitions(-DUSE_OPENMP)
David Bommes's avatar
David Bommes committed
439 440 441
#      else ()
#        set (OPENMP_NOTFOUND 1)
#      endif ()
442
    endif()
Jan Möbius's avatar
 
Jan Möbius committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
  endif ()
endmacro ()

# test for FTGL
macro (acg_ftgl)
  find_package (Freetype)

  if (FREETYPE_FOUND)
    find_package (FTGL)

    if (FTGL_FOUND)
      add_definitions (-DUSE_FTGL)
      include_directories (${FTGL_INCLUDE_DIR} ${FREETYPE_INCLUDE_DIR_freetype2})
      set (FTGL_LIBS ${FREETYPE_LIBRARIES} ${FTGL_LIBRARIES})
    endif ()
  endif ()
endmacro ()

# append all files with extension "ext" in the "dirs" directories to "ret"
462
# excludes all files starting with a '.' (dot)
Jan Möbius's avatar
 
Jan Möbius committed
463 464 465
macro (acg_append_files ret ext)
  foreach (_dir ${ARGN})
    file (GLOB _files "${_dir}/${ext}")
466 467 468
    foreach (_file ${_files})
      get_filename_component (_filename ${_file} NAME)
      if (_filename MATCHES "^[.]")
Jan Möbius's avatar
Jan Möbius committed
469
	list (REMOVE_ITEM _files ${_file})
470 471
      endif ()
    endforeach ()
Jan Möbius's avatar
 
Jan Möbius committed
472 473 474 475 476
    list (APPEND ${ret} ${_files})
  endforeach ()
endmacro ()

# append all files with extension "ext" in the "dirs" directories and its subdirectories to "ret"
477
# excludes all files starting with a '.' (dot)
Jan Möbius's avatar
 
Jan Möbius committed
478 479
macro (acg_append_files_recursive ret ext)
  foreach (_dir ${ARGN})
480
    file (GLOB_RECURSE _files "${_dir}/${ext}")
481 482 483
    foreach (_file ${_files})
      get_filename_component (_filename ${_file} NAME)
      if (_filename MATCHES "^[.]")
Jan Möbius's avatar
Jan Möbius committed
484
	list (REMOVE_ITEM _files ${_file})
485 486
      endif ()
    endforeach ()
Jan Möbius's avatar
 
Jan Möbius committed
487 488 489 490
    list (APPEND ${ret} ${_files})
  endforeach ()
endmacro ()

491

Jan Möbius's avatar
 
Jan Möbius committed
492 493 494 495 496 497 498 499 500 501 502 503
# drop all "*T.cc" files from list
macro (acg_drop_templates list)
  foreach (_file ${${list}})
    if (_file MATCHES "T.cc$")
      list (REMOVE_ITEM ${list} ${_file})
    endif ()
  endforeach ()
endmacro ()

# generate moc targets for sources in list
macro (acg_qt4_automoc moc_SRCS)
  qt4_get_moc_flags (_moc_INCS)
504 505
  
  list(REMOVE_DUPLICATES _moc_INCS)
Jan Möbius's avatar
 
Jan Möbius committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)
     # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
     # here. this is required to make bouic work correctly:
     # we need to add generated .cpp files to the sources (to compile them),
     # but we cannot let automoc handle them, as the .cpp files don't exist yet when
     # cmake is run for the very first time on them -> however the .cpp files might
     # exist at a later run. at that time we need to skip them, so that we don't add two
     # different rules for the same moc file
     get_source_file_property (_skip ${_abs_FILE} SKIP_AUTOMOC)

     if ( NOT _skip AND EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        string (REGEX MATCHALL "Q_OBJECT" _match "${_contents}")
        if (_match)
            get_filename_component (_basename ${_current_FILE} NAME_WE)
            set (_header ${_abs_FILE})
            set (_moc    ${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp)

            add_custom_command (OUTPUT ${_moc}
                COMMAND ${QT_MOC_EXECUTABLE}
                ARGS ${_moc_INCS} ${_header} -o ${_moc}
                DEPENDS ${_header}
            )

            add_file_dependencies (${_abs_FILE} ${_moc})
            set (${moc_SRCS} ${${moc_SRCS}} ${_moc})
540
            
Matthias Möller's avatar
Matthias Möller committed
541 542 543 544 545 546 547 548
        endif ()
     endif ()
  endforeach ()
endmacro ()

# generate moc targets for sources in list
macro (acg_qt5_automoc moc_SRCS)
  qt5_get_moc_flags (_moc_INCS)
549 550
  
  list(REMOVE_DUPLICATES _moc_INCS)
Matthias Möller's avatar
Matthias Möller committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)
     # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
     # here. this is required to make bouic work correctly:
     # we need to add generated .cpp files to the sources (to compile them),
     # but we cannot let automoc handle them, as the .cpp files don't exist yet when
     # cmake is run for the very first time on them -> however the .cpp files might
     # exist at a later run. at that time we need to skip them, so that we don't add two
     # different rules for the same moc file
     get_source_file_property (_skip ${_abs_FILE} SKIP_AUTOMOC)

     if ( NOT _skip AND EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        string (REGEX MATCHALL "Q_OBJECT" _match "${_contents}")
        if (_match)
            get_filename_component (_basename ${_current_FILE} NAME_WE)
            set (_header ${_abs_FILE})
            set (_moc    ${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp)

Jan Möbius's avatar
Jan Möbius committed
577 578 579 580 581
            add_custom_command (OUTPUT ${_moc}
                COMMAND ${QT_MOC_EXECUTABLE}
                ARGS ${_moc_INCS} ${_header} -o ${_moc}
                DEPENDS ${_header}
            )
Matthias Möller's avatar
Matthias Möller committed
582 583 584 585

            add_file_dependencies (${_abs_FILE} ${_moc})
            set (${moc_SRCS} ${${moc_SRCS}} ${_moc})

Jan Möbius's avatar
 
Jan Möbius committed
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        endif ()
     endif ()
  endforeach ()
endmacro ()

# generate uic targets for sources in list
macro (acg_qt4_autouic uic_SRCS)

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)

     if ( EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        get_filename_component (_basename ${_current_FILE} NAME_WE)
        string (REGEX REPLACE "Ui$" "" _cbasename ${_basename})
        set (_outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.hh)
        set (_header ${_basename}.hh)
        set (_source ${_abs_PATH}/${_cbasename}.cc)
610
        
Jan Möbius's avatar
 
Jan Möbius committed
611 612 613
        add_custom_command (OUTPUT ${_outfile}
            COMMAND ${QT_UIC_EXECUTABLE}
            ARGS -o ${_outfile} ${_abs_FILE}
Matthias Möller's avatar
Matthias Möller committed
614
            MAIN_DEPENDENCY ${_abs_FILE} VERBATIM)
Jan Möbius's avatar
 
Jan Möbius committed
615 616 617

        add_file_dependencies (${_source} ${_outfile})
        set (${uic_SRCS} ${${uic_SRCS}} ${_outfile})
618
            
Jan Möbius's avatar
 
Jan Möbius committed
619 620 621 622
     endif ()
  endforeach ()
endmacro ()

Matthias Möller's avatar
Matthias Möller committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
# generate uic targets for sources in list
macro (acg_qt5_autouic uic_SRCS)

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)

     if ( EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        get_filename_component (_basename ${_current_FILE} NAME_WE)
        string (REGEX REPLACE "Ui$" "" _cbasename ${_basename})
        set (_outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.hh)
        set (_header ${_basename}.hh)
        set (_source ${_abs_PATH}/${_cbasename}.cc)

        add_custom_command (OUTPUT ${_outfile}
            COMMAND ${Qt5Widgets_UIC_EXECUTABLE}
            ARGS -o ${_outfile} ${_abs_FILE}
Matthias Möller's avatar
Matthias Möller committed
646
            MAIN_DEPENDENCY ${_abs_FILE} VERBATIM)
Matthias Möller's avatar
Matthias Möller committed
647 648 649 650 651 652 653

        add_file_dependencies (${_source} ${_outfile})
        set (${uic_SRCS} ${${uic_SRCS}} ${_outfile})

     endif ()
  endforeach ()
endmacro ()
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670

# generate qrc targets for sources in list
macro (acg_qt4_autoqrc qrc_SRCS)

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)

     if ( EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        get_filename_component (_basename ${_current_FILE} NAME_WE)
        set (_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${_basename}.cpp)
671
        
Matthias Möller's avatar
Matthias Möller committed
672 673 674
        add_custom_command (OUTPUT ${_outfile}
            COMMAND ${QT_RCC_EXECUTABLE}
            ARGS -o ${_outfile}  ${_abs_FILE}
675
            DEPENDS ${_abs_FILE}) 
Matthias Möller's avatar
Matthias Möller committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

        add_file_dependencies (${_source} ${_outfile})
        set (${qrc_SRCS} ${${qrc_SRCS}} ${_outfile})

     endif ()
  endforeach ()
endmacro ()

# generate qrc targets for sources in list
macro (acg_qt5_autoqrc qrc_SRCS)

  set (_matching_FILES )
  foreach (_current_FILE ${ARGN})

     get_filename_component (_abs_FILE ${_current_FILE} ABSOLUTE)

     if ( EXISTS ${_abs_FILE} )

        file (READ ${_abs_FILE} _contents)

        get_filename_component (_abs_PATH ${_abs_FILE} PATH)

        get_filename_component (_basename ${_current_FILE} NAME_WE)
        set (_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${_basename}.cpp)

701
        qt5_add_resources( ${_outfile}  ${_abs_FILE}  )
702 703 704 705 706 707 708 709

        add_file_dependencies (${_source} ${_outfile})
        set (${qrc_SRCS} ${${qrc_SRCS}} ${_outfile})

     endif ()
  endforeach ()
endmacro ()

Jan Möbius's avatar
 
Jan Möbius committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
# get all files in directory, but ignore svn
macro (acg_get_files_in_dir ret dir)
  file (GLOB_RECURSE __files RELATIVE "${dir}" "${dir}/*")
  foreach (_file ${__files})
    if (NOT _file MATCHES ".*svn.*")
      list (APPEND ${ret} "${_file}")
    endif ()
  endforeach ()
endmacro ()

# copy the whole directory without svn files
function (acg_copy_after_build target src dst)
  acg_unset (_files)
  acg_get_files_in_dir (_files ${src})
  foreach (_file ${_files})
725 726
    add_custom_command(TARGET ${target} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_if_different "${src}/${_file}" "${dst}/${_file}"
Jan Möbius's avatar
 
Jan Möbius committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
    )
  endforeach ()
endfunction ()

# install the whole directory without svn files
function (acg_install_dir src dst)
  acg_unset (_files)
  acg_get_files_in_dir (_files ${src})
  foreach (_file ${_files})
    get_filename_component (_file_PATH ${_file} PATH)
    install(FILES "${src}/${_file}"
      DESTINATION "${dst}/${_file_PATH}"
    )
  endforeach ()
endfunction ()

# extended version of add_executable that also copies output to out Build directory
function (acg_add_executable _target)
  add_executable (${_target} ${ARGN})

  # set common target properties defined in common.cmake
  acg_set_target_props (${_target})

750
  if (WIN32 OR (APPLE AND NOT ACG_PROJECT_MACOS_BUNDLE))
Jan Möbius's avatar
 
Jan Möbius committed
751 752 753
    add_custom_command (TARGET ${_target} POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E
                        copy_if_different
754 755 756 757
                          $<TARGET_FILE:${_target}>
                          ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR}/$<TARGET_FILE_NAME:${_target}>)
  endif (WIN32 OR (APPLE AND NOT ACG_PROJECT_MACOS_BUNDLE))
  
758
  if (NOT ACG_PROJECT_MACOS_BUNDLE OR NOT APPLE)
Jan Möbius's avatar
 
Jan Möbius committed
759 760 761 762 763
    install (TARGETS ${_target} DESTINATION ${ACG_PROJECT_BINDIR})
  endif ()
endfunction ()

# extended version of add_library that also copies output to out Build directory
764 765 766 767 768 769 770 771
function (acg_add_library _target _libtype)

  if (${_libtype} STREQUAL SHAREDANDSTATIC)
    set (_type SHARED)
    if (NOT WIN32)
      set (_and_static 1)
    else ()
      set (_and_static 0)
772
    endif ()    
773 774 775 776 777
  else ()
    set (_type ${_libtype})
    set (_and_static 0)
  endif ()

778 779
  add_library (${_target} ${_type} ${ARGN} )

Jan Möbius's avatar
 
Jan Möbius committed
780 781 782
  # set common target properties defined in common.cmake
  acg_set_target_props (${_target})

783 784 785 786 787
  if (_and_static)
    add_library (${_target}Static STATIC ${ARGN})

    # set common target properties defined in common.cmake
    acg_set_target_props (${_target}Static)
788 789

    set_target_properties(${_target}Static PROPERTIES OUTPUT_NAME ${_target})
790
    
791
    if (NOT APPLE)
792
      set_target_properties (${_target}Static PROPERTIES 
793 794
                             LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
                            )
795 796 797
    endif ()
  endif ()

798
  if (WIN32 OR (APPLE AND NOT ACG_PROJECT_MACOS_BUNDLE))
Jan Möbius's avatar
 
Jan Möbius committed
799 800 801 802
    if (${_type} STREQUAL SHARED)
      add_custom_command (TARGET ${_target} POST_BUILD
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
803 804 805
                            $<TARGET_FILE:${_target}>
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR}/$<TARGET_FILE_NAME:${_target}>)
    add_custom_command (TARGET ${_target} POST_BUILD
Jan Möbius's avatar
 
Jan Möbius committed
806 807
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
808 809
                            $<TARGET_LINKER_FILE:${_target}>
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR}/$<TARGET_LINKER_FILE_NAME:${_target}>)
Jan Möbius's avatar
 
Jan Möbius committed
810 811 812 813
    elseif (${_type} STREQUAL MODULE)
      if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR})
        file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR})
      endif ()
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
814
      add_custom_command (TARGET ${_target} POST_BUILD
Jan Möbius's avatar
 
Jan Möbius committed
815 816
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
817 818
                            $<TARGET_FILE:${_target}>
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_PLUGINDIR}/$<TARGET_FILE_NAME:${_target}>)
819
    elseif (${_type} STREQUAL STATIC)
820
    add_custom_command (TARGET ${_target} POST_BUILD
821 822
                          COMMAND ${CMAKE_COMMAND} -E
                          copy_if_different
823 824 825 826 827 828 829 830
                            $<TARGET_FILE:${_target}>
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_LIBDIR}/$<TARGET_FILE_NAME:${_target}>)
  endif()
  
   
  # make an extra copy for windows into the binary directory
    if (${_type} STREQUAL SHARED AND WIN32)
      add_custom_command (TARGET ${_target} POST_BUILD
831
                          COMMAND ${CMAKE_COMMAND} -E
832 833 834 835 836 837 838 839 840 841 842 843
                          copy_if_different 
                            $<TARGET_FILE:${_target}>
                            ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR}/$<TARGET_FILE_NAME:${_target}>)
  endif () 
    
  endif(WIN32 OR (APPLE AND NOT ACG_PROJECT_MACOS_BUNDLE))
  
  if (_and_static)
    add_custom_command (TARGET ${_target}Static POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E
                        copy_if_different
                          $<TARGET_FILE:${_target}Static>
844
                          ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR}/$<TARGET_FILE_NAME:${_target}Static>)
845

Jan Möbius's avatar
 
Jan Möbius committed
846
  endif ()
847
 
848 849

  # Block installation of libraries by setting ACG_NO_LIBRARY_INSTALL
850
  if ( NOT ACG_NO_LIBRARY_INSTALL ) 
851 852 853 854 855 856 857
    if (NOT ACG_PROJECT_MACOS_BUNDLE OR NOT APPLE)
      if (${_type} STREQUAL SHARED OR ${_type} STREQUAL STATIC )
        install (TARGETS ${_target}
                 RUNTIME DESTINATION ${ACG_PROJECT_BINDIR}
                 LIBRARY DESTINATION ${ACG_PROJECT_LIBDIR}
                 ARCHIVE DESTINATION ${ACG_PROJECT_LIBDIR})
        if (_and_static)
858 859
          install (TARGETS ${_target}Static
                   DESTINATION ${ACG_PROJECT_LIBDIR})
860 861 862
        endif ()
      elseif (${_type} STREQUAL MODULE)
        install (TARGETS ${_target} DESTINATION ${ACG_PROJECT_PLUGINDIR})
863
      endif ()
Jan Möbius's avatar
 
Jan Möbius committed
864
    endif ()
865
  endif()
Jan Möbius's avatar
Jan Möbius committed
866

Jan Möbius's avatar
 
Jan Möbius committed
867
endfunction ()
Jan Möbius's avatar
Jan Möbius committed
868 869 870 871 872 873 874 875 876 877 878 879 880

#generates qt translations
function (acg_add_translations _target _languages _sources)

  string (TOUPPER ${_target} _TARGET)
  # generate/use translation files
  # run with UPDATE_TRANSLATIONS set to on to build qm files
  option (UPDATE_TRANSLATIONS_${_TARGET} "Update source translation *.ts files (WARNING: make clean will delete the source .ts files! Danger!)")

  set (_new_ts_files)
  set (_ts_files)

  foreach (lang ${_languages})
Jan Möbius's avatar
Jan Möbius committed
881 882
    if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/translations/${_target}_${lang}.ts" OR UPDATE_TRANSLATIONS_${_TARGET})
      list (APPEND _new_ts_files "translations/${_target}_${lang}.ts")
Jan Möbius's avatar
Jan Möbius committed
883
    else ()
Jan Möbius's avatar
Jan Möbius committed
884
      list (APPEND _ts_files "translations/${_target}_${lang}.ts")
Jan Möbius's avatar
Jan Möbius committed
885 886 887
    endif ()
  endforeach ()

Jan Möbius's avatar
Jan Möbius committed
888

Jan Möbius's avatar
Jan Möbius committed
889
  set (_qm_files)
Jan Möbius's avatar
Jan Möbius committed
890
  if ( _new_ts_files )
Matthias Möller's avatar
Matthias Möller committed
891 892 893
    if (QT5_FOUND)
      #qt5_create_translation(_qm_files ${_sources} ${_new_ts_files})
    elseif (QT4_FOUND)
894 895
    qt4_create_translation(_qm_files ${_sources} ${_new_ts_files})
  endif ()
Jan Möbius's avatar
Jan Möbius committed
896 897
  endif ()

Jan Möbius's avatar
Jan Möbius committed
898
  if ( _ts_files )
Matthias Möller's avatar
Matthias Möller committed
899 900 901
    if (QT5_FOUND)
      #qt5_add_translation(_qm_files2 ${_ts_files})
    elseif (QT4_FOUND)
902
    qt4_add_translation(_qm_files2 ${_ts_files})
Matthias Möller's avatar
Matthias Möller committed
903
    endif()
Jan Möbius's avatar
Jan Möbius committed
904 905 906 907 908 909 910 911 912 913 914 915 916 917
    list (APPEND _qm_files ${_qm_files2})
  endif ()

  # create a target for the translation files ( and object files )
  # Use this target, to update only the translations
  add_custom_target (translations_target_${_target} DEPENDS ${_qm_files})

  # Build translations with the application
  add_dependencies(${_target} translations_target_${_target} )

  if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/Translations)
    file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/Translations )
  endif ()

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
918 919 920 921 922 923 924 925
  foreach (_qm ${_qm_files})
    get_filename_component (_qm_name "${_qm}" NAME)
    add_custom_command (TARGET translations_target_${_target} POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E
                        copy_if_different
                          ${_qm}
                          ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/Translations/${_qm_name})
  endforeach ()
Jan Möbius's avatar
Jan Möbius committed
926 927

  if (NOT ACG_PROJECT_MACOS_BUNDLE OR NOT APPLE)
928
    install (FILES ${_qm_files} DESTINATION "${ACG_PROJECT_DATADIR}/Translations")
Jan Möbius's avatar
Jan Möbius committed
929 930
  endif ()
endfunction ()
931 932 933 934 935 936 937

# Function that writes all generated qch files into one Help.qhcp project file
function (generate_qhp_file files_loc plugin_name)

    set(qhp_file "${files_loc}/${plugin_name}.qhp")
    # Read in template file
    file(STRINGS "${CMAKE_SOURCE_DIR}/OpenFlipper/Documentation/QtHelpResources/QtHelpProject.qhp" qhp_template)
938
    
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
    # Initialize new project file
    file(WRITE ${qhp_file} "")
    foreach (_line ${qhp_template})
        string(STRIP ${_line} stripped)
        if("${stripped}" STREQUAL "files")
            acg_get_files_in_dir (_files ${files_loc})
            foreach (_file ${_files})
                string(REGEX MATCH ".+[.]+((html)|(htm)|(xml))$" fileresult ${_file})
                string(LENGTH "${fileresult}" len)
                if(${len} GREATER 0)
                    file(APPEND ${qhp_file} "<file>${_file}</file>\n")
                endif()
            endforeach()
        else()
            string(REGEX REPLACE "plugin" ${plugin} newline ${_line})
            file(APPEND ${qhp_file} "${newline}\n")
        endif()
    endforeach()
endfunction()