Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / CMakeLists.txt
1 #=============================================================================
2 # CMake - Cross Platform Makefile Generator
3 # Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
4 #
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
7 #
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
13 set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
14 project(CMake)
15
16 if(CMAKE_BOOTSTRAP)
17   # Running from bootstrap script.  Set local variable and remove from cache.
18   set(CMAKE_BOOTSTRAP 1)
19   unset(CMAKE_BOOTSTRAP CACHE)
20 endif()
21
22 set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
23
24 if("${CMake_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
25   # Disallow architecture-specific try_run.  It may not run on the host.
26   macro(TRY_RUN)
27     if(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES)
28       message(FATAL_ERROR "TRY_RUN not allowed with CMAKE_TRY_COMPILE_OSX_ARCHITECTURES=[${CMAKE_TRY_COMPILE_OSX_ARCHITECTURES}]")
29     else()
30       _TRY_RUN(${ARGV})
31     endif()
32   endmacro()
33 endif()
34
35 #-----------------------------------------------------------------------
36 # a macro to deal with system libraries, implemented as a macro
37 # simply to improve readability of the main script
38 #-----------------------------------------------------------------------
39 macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
40   # Options have dependencies.
41   include(CMakeDependentOption)
42
43   # Optionally use system xmlrpc.  We no longer build or use it by default.
44   option(CTEST_USE_XMLRPC "Enable xmlrpc submission method in CTest." OFF)
45   mark_as_advanced(CTEST_USE_XMLRPC)
46
47   # Allow the user to enable/disable all system utility library options by
48   # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
49   set(UTILITIES BZIP2 CURL EXPAT LIBARCHIVE ZLIB)
50   foreach(util ${UTILITIES})
51     if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
52         AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
53       set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}")
54     endif()
55     if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util})
56       if(CMAKE_USE_SYSTEM_LIBRARY_${util})
57         set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON)
58       else()
59         set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
60       endif()
61       if(CMAKE_BOOTSTRAP)
62         unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE)
63       endif()
64       string(TOLOWER "${util}" lutil)
65       set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}"
66         CACHE BOOL "Use system-installed ${lutil}" FORCE)
67     else()
68       set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF)
69     endif()
70   endforeach()
71   if(CMAKE_BOOTSTRAP)
72     unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE)
73   endif()
74
75   # Optionally use system utility libraries.
76   option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}")
77   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_CURL "Use system-installed curl"
78     "${CMAKE_USE_SYSTEM_LIBRARY_CURL}" "NOT CTEST_USE_XMLRPC" ON)
79   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat"
80     "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}" "NOT CTEST_USE_XMLRPC" ON)
81   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib"
82     "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON)
83   CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2"
84     "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
85
86   # Mention to the user what system libraries are being used.
87   foreach(util ${UTILITIES})
88     if(CMAKE_USE_SYSTEM_${util})
89       message(STATUS "Using system-installed ${util}")
90     endif()
91   endforeach()
92
93   # Inform utility library header wrappers whether to use system versions.
94   configure_file(${CMake_SOURCE_DIR}/Utilities/cmThirdParty.h.in
95     ${CMake_BINARY_DIR}/Utilities/cmThirdParty.h
96     @ONLY)
97
98 endmacro()
99
100
101
102
103 set(CMAKE_BUILD_ON_VISUAL_STUDIO 0)
104 if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW )
105   set(CMAKE_BUILD_ON_VISUAL_STUDIO 1)
106 endif()
107
108
109 #-----------------------------------------------------------------------
110 # a macro to determine the generator and ctest executable to use
111 # for testing. Simply to improve readability of the main script.
112 #-----------------------------------------------------------------------
113 macro(CMAKE_SETUP_TESTING)
114   if (NOT DART_ROOT)
115     set(MAKEPROGRAM ${CMAKE_MAKE_PROGRAM})
116   endif ()
117
118   if(BUILD_TESTING)
119     set(CMAKE_TEST_GENERATOR "" CACHE STRING
120       "Generator used when running tests")
121     set(CMAKE_TEST_MAKEPROGRAM "" CACHE FILEPATH
122       "Generator used when running tests")
123     if(NOT CMAKE_TEST_GENERATOR)
124       set(CMAKE_TEST_GENERATOR "${CMAKE_GENERATOR}")
125       set(CMAKE_TEST_GENERATOR_TOOLSET "${CMAKE_GENERATOR_TOOLSET}")
126       set(CMAKE_TEST_MAKEPROGRAM "${MAKEPROGRAM}")
127     else()
128       set(CMAKE_TEST_DIFFERENT_GENERATOR TRUE)
129       set(CMAKE_TEST_GENERATOR_TOOLSET "")
130     endif()
131
132     # Are we testing with the MSVC compiler?
133     set(CMAKE_TEST_MSVC 0)
134     if(MSVC AND NOT CMAKE_TEST_DIFFERENT_GENERATOR)
135       set(CMAKE_TEST_MSVC 1)
136     else()
137       if("${CMAKE_TEST_GENERATOR}" MATCHES "NMake" OR
138           "${CMAKE_TEST_GENERATOR}" MATCHES "Visual Studio")
139         set(CMAKE_TEST_MSVC 1)
140       endif()
141     endif()
142
143     set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
144     foreach(util CURL EXPAT XMLRPC ZLIB)
145       if(CMAKE_USE_SYSTEM_${util})
146         set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
147       endif()
148     endforeach()
149
150     # This variable is set by cmake, however to
151     # test cmake we want to make sure that
152     # the ctest from this cmake is used for testing
153     # and not the ctest from the cmake building and testing
154     # cmake.
155     set(CMAKE_CTEST_COMMAND "${CMake_BIN_DIR}/ctest")
156     set(CMAKE_CMAKE_COMMAND "${CMake_BIN_DIR}/cmake")
157     set(CMAKE_CPACK_COMMAND "${CMake_BIN_DIR}/cpack")
158   endif()
159
160   # configure some files for testing
161   configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in"
162     "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake"
163     @ONLY)
164   configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
165     ${CMake_BINARY_DIR}/Tests/.NoDartCoverage)
166   configure_file(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage
167     ${CMake_BINARY_DIR}/Modules/.NoDartCoverage)
168   configure_file(${CMake_SOURCE_DIR}/CTestCustom.cmake.in
169     ${CMake_BINARY_DIR}/CTestCustom.cmake @ONLY)
170   configure_file(${CMake_SOURCE_DIR}/CTestCustom.ctest.in
171     ${CMake_BINARY_DIR}/CTestCustom.ctest @ONLY)
172   if(BUILD_TESTING AND DART_ROOT)
173     configure_file(${CMake_SOURCE_DIR}/CMakeLogo.gif
174       ${CMake_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif COPYONLY)
175   endif()
176   mark_as_advanced(DART_ROOT)
177   mark_as_advanced(CURL_TESTING)
178 endmacro()
179
180
181 # Provide a way for Visual Studio Express users to turn OFF the new FOLDER
182 # organization feature. Default to ON for non-Express users. Express users must
183 # explicitly turn off this option to build CMake in the Express IDE...
184 #
185 option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
186 mark_as_advanced(CMAKE_USE_FOLDERS)
187
188
189 #-----------------------------------------------------------------------
190 # a macro that only sets the FOLDER target property if it's
191 # "appropriate"
192 #-----------------------------------------------------------------------
193 macro(CMAKE_SET_TARGET_FOLDER tgt folder)
194   if(CMAKE_USE_FOLDERS)
195     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
196
197     # Really, I just want this to be an "if(TARGET ${tgt})" ...
198     # but I'm not sure that our min req'd., CMake 2.4.5 can handle
199     # that... so I'm just activating this for now, with a version
200     # compare, and only for MSVC builds.
201     if(MSVC)
202       if(NOT ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8)
203         set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
204       endif()
205     endif()
206   else()
207     set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
208   endif()
209 endmacro()
210
211
212 #-----------------------------------------------------------------------
213 # a macro to build the utilities used by CMake
214 # Simply to improve readability of the main script.
215 #-----------------------------------------------------------------------
216 macro (CMAKE_BUILD_UTILITIES)
217   #---------------------------------------------------------------------
218   # Create the KWIML library for CMake.
219   set(KWIML cmIML)
220   set(KWIML_HEADER_ROOT ${CMake_BINARY_DIR}/Utilities)
221   add_subdirectory(Utilities/KWIML)
222
223   #---------------------------------------------------------------------
224   # Create the kwsys library for CMake.
225   set(KWSYS_NAMESPACE cmsys)
226   set(KWSYS_USE_SystemTools 1)
227   set(KWSYS_USE_Directory 1)
228   set(KWSYS_USE_RegularExpression 1)
229   set(KWSYS_USE_Base64 1)
230   set(KWSYS_USE_MD5 1)
231   set(KWSYS_USE_Process 1)
232   set(KWSYS_USE_CommandLineArguments 1)
233   set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
234   set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
235   add_subdirectory(Source/kwsys)
236   set(kwsys_folder "Utilities/KWSys")
237   CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
238   CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}_c "${kwsys_folder}")
239   if(BUILD_TESTING)
240     CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestDynload "${kwsys_folder}")
241     CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestProcess "${kwsys_folder}")
242     CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsC "${kwsys_folder}")
243     CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestsCxx "${kwsys_folder}")
244     CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE}TestSharedForward "${kwsys_folder}")
245   endif()
246
247   #---------------------------------------------------------------------
248   # Setup third-party libraries.
249   # Everything in the tree should be able to include files from the
250   # Utilities directory.
251   include_directories(
252     ${CMake_BINARY_DIR}/Utilities
253     ${CMake_SOURCE_DIR}/Utilities
254     )
255
256   # check for the use of system libraries versus builtin ones
257   # (a macro defined in this file)
258   CMAKE_HANDLE_SYSTEM_LIBRARIES()
259
260   #---------------------------------------------------------------------
261   # Build zlib library for Curl, CMake, and CTest.
262   set(CMAKE_ZLIB_HEADER "cm_zlib.h")
263   if(CMAKE_USE_SYSTEM_ZLIB)
264     find_package(ZLIB)
265     if(NOT ZLIB_FOUND)
266       message(FATAL_ERROR
267         "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!")
268     endif()
269     set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR})
270     set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
271   else()
272     set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities)
273     set(CMAKE_ZLIB_LIBRARIES cmzlib)
274     add_subdirectory(Utilities/cmzlib)
275     CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty")
276   endif()
277
278   #---------------------------------------------------------------------
279   # Build Curl library for CTest.
280   if(CMAKE_USE_SYSTEM_CURL)
281     find_package(CURL)
282     if(NOT CURL_FOUND)
283       message(FATAL_ERROR
284         "CMAKE_USE_SYSTEM_CURL is ON but a curl is not found!")
285     endif()
286     set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS})
287     set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES})
288   else()
289     set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
290     set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
291     set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
292     option(CMAKE_BUILD_CURL_SHARED "Should curl be built shared" FALSE)
293     if(NOT CMAKE_BUILD_CURL_SHARED)
294       add_definitions(-DCURL_STATICLIB)
295     endif()
296     set(CMAKE_CURL_INCLUDES)
297     set(CMAKE_CURL_LIBRARIES cmcurl)
298     if(CMAKE_TESTS_CDASH_SERVER)
299       set(CMAKE_CURL_TEST_URL "${CMAKE_TESTS_CDASH_SERVER}/user.php")
300     endif()
301     add_subdirectory(Utilities/cmcurl)
302     CMAKE_SET_TARGET_FOLDER(cmcurl "Utilities/3rdParty")
303     CMAKE_SET_TARGET_FOLDER(LIBCURL "Utilities/3rdParty")
304   endif()
305
306   #---------------------------------------------------------------------
307   # Build Compress library for CTest.
308   set(CMAKE_COMPRESS_INCLUDES
309     "${CMAKE_CURRENT_BINARY_DIR}/Utilities/cmcompress")
310   set(CMAKE_COMPRESS_LIBRARIES "cmcompress")
311   add_subdirectory(Utilities/cmcompress)
312   CMAKE_SET_TARGET_FOLDER(cmcompress "Utilities/3rdParty")
313   if(CMAKE_USE_SYSTEM_BZIP2)
314     find_package(BZip2)
315   else()
316     set(BZIP2_INCLUDE_DIR
317       "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmbzip2")
318     set(BZIP2_LIBRARIES cmbzip2)
319     add_subdirectory(Utilities/cmbzip2)
320     CMAKE_SET_TARGET_FOLDER(cmbzip2 "Utilities/3rdParty")
321   endif()
322
323   #---------------------------------------------------------------------
324   # Build or use system libarchive for CMake and CTest.
325   if(CMAKE_USE_SYSTEM_LIBARCHIVE)
326     if(EXISTS ${CMAKE_ROOT}/Modules/FindLibArchive.cmake) # added in 2.8.3
327       find_package(LibArchive)
328     else()
329       include(${CMake_SOURCE_DIR}/Modules/FindLibArchive.cmake)
330     endif()
331     if(NOT LibArchive_FOUND)
332       message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
333     endif()
334     set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS})
335     set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES})
336   else()
337     set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES})
338     set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES})
339     add_definitions(-DLIBARCHIVE_STATIC)
340     set(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle")
341     set(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL")
342     set(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support")
343     set(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support")
344     set(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support")
345     add_subdirectory(Utilities/cmlibarchive)
346     CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty")
347     set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES})
348   endif()
349
350   #---------------------------------------------------------------------
351   # Build expat library for CMake and CTest.
352   if(CMAKE_USE_SYSTEM_EXPAT)
353     find_package(EXPAT)
354     if(NOT EXPAT_FOUND)
355       message(FATAL_ERROR
356         "CMAKE_USE_SYSTEM_EXPAT is ON but a expat is not found!")
357     endif()
358     set(CMAKE_EXPAT_INCLUDES ${EXPAT_INCLUDE_DIRS})
359     set(CMAKE_EXPAT_LIBRARIES ${EXPAT_LIBRARIES})
360   else()
361     set(CMAKE_EXPAT_INCLUDES)
362     set(CMAKE_EXPAT_LIBRARIES cmexpat)
363     add_subdirectory(Utilities/cmexpat)
364     CMAKE_SET_TARGET_FOLDER(cmexpat "Utilities/3rdParty")
365   endif()
366
367   #---------------------------------------------------------------------
368   # Build XMLRPC library for CMake and CTest.
369   if(CTEST_USE_XMLRPC)
370     find_package(XMLRPC QUIET REQUIRED libwww-client)
371     if(NOT XMLRPC_FOUND)
372       message(FATAL_ERROR
373         "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
374     endif()
375     set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
376     set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
377   endif()
378
379   #---------------------------------------------------------------------
380   # Use curses?
381   if (UNIX)
382     # there is a bug in the Syllable libraries which makes linking ccmake fail, Alex
383     if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES syllable)
384       set(CURSES_NEED_NCURSES TRUE)
385       find_package(Curses QUIET)
386       if (CURSES_LIBRARY)
387         option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" ON)
388       else ()
389         message("Curses libraries were not found. Curses GUI for CMake will not be built.")
390         set(BUILD_CursesDialog 0)
391       endif ()
392     else()
393       set(BUILD_CursesDialog 0)
394     endif()
395   else ()
396     set(BUILD_CursesDialog 0)
397   endif ()
398   if(BUILD_CursesDialog)
399     add_subdirectory(Source/CursesDialog/form)
400   endif()
401 endmacro ()
402
403 #-----------------------------------------------------------------------
404 if(CMAKE_CXX_PLATFORM_ID MATCHES "OpenBSD")
405   execute_process(COMMAND ${CMAKE_CXX_COMPILER}
406     ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
407     OUTPUT_VARIABLE _GXX_VERSION
408   )
409   string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
410     _GXX_VERSION_SHORT ${_GXX_VERSION})
411   if(_GXX_VERSION_SHORT EQUAL 33)
412     message(FATAL_ERROR
413       "GXX 3.3 on OpenBSD is known to cause CPack to Crash.\n"
414       "Please use GXX 4.2 or greater to build CMake on OpenBSD\n"
415       "${CMAKE_CXX_COMPILER} version is: ${_GXX_VERSION}")
416   endif()
417 endif()
418
419 #-----------------------------------------------------------------------
420 # The main section of the CMakeLists file
421 #
422 #-----------------------------------------------------------------------
423 include(Source/CMakeVersion.cmake)
424 # Releases define a small tweak level.
425 if("${CMake_VERSION_TWEAK}" VERSION_LESS 20000000)
426   set(CMake_VERSION_IS_RELEASE 1)
427   set(CMake_VERSION_SOURCE "")
428 else()
429   set(CMake_VERSION_IS_RELEASE 0)
430   include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake)
431 endif()
432
433 # Compute the full version string.
434 set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH})
435 if(${CMake_VERSION_TWEAK} GREATER 0)
436   set(CMake_VERSION ${CMake_VERSION}.${CMake_VERSION_TWEAK})
437 endif()
438 if(CMake_VERSION_RC)
439   set(CMake_VERSION ${CMake_VERSION}-rc${CMake_VERSION_RC})
440 endif()
441 if(CMake_VERSION_SOURCE)
442   set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SOURCE})
443 endif()
444
445 # Include the standard Dart testing module
446 enable_testing()
447 include (${CMAKE_ROOT}/Modules/Dart.cmake)
448
449 # Set up test-time configuration.
450 set_directory_properties(PROPERTIES
451   TEST_INCLUDE_FILE "${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake")
452
453 # where to write the resulting executables and libraries
454 set(BUILD_SHARED_LIBS OFF)
455 set(EXECUTABLE_OUTPUT_PATH "" CACHE INTERNAL "No configurable exe dir.")
456 set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
457   "Where to put the libraries for CMake")
458
459 # The CMake executables usually do not need any rpath to run in the build or
460 # install tree.
461 set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.")
462
463 set(CMAKE_DATA_DIR "share/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}" CACHE STRING
464   "Install location for data (relative to prefix).")
465 set(CMAKE_DOC_DIR "doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}" CACHE STRING
466   "Install location for documentation (relative to prefix).")
467 set(CMAKE_MAN_DIR "man" CACHE STRING
468   "Install location for man pages (relative to prefix).")
469 mark_as_advanced(CMAKE_DATA_DIR CMAKE_DOC_DIR CMAKE_MAN_DIR)
470 if(CYGWIN AND EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
471   # Force doc, data and man dirs to conform to cygwin layout.
472   set(CMAKE_DOC_DIR  "share/doc/cmake-${CMake_VERSION}")
473   set(CMAKE_DATA_DIR "share/cmake-${CMake_VERSION}")
474   set(CMAKE_MAN_DIR  "share/man")
475   # let the user know we just forced these values
476   message(STATUS "Setup for Cygwin packaging")
477   message(STATUS "Override cache CMAKE_DOC_DIR = ${CMAKE_DOC_DIR}")
478   message(STATUS "Override cache CMAKE_DATA_DIR = ${CMAKE_DATA_DIR}")
479   message(STATUS "Override cache CMAKE_MAN_DIR = ${CMAKE_MAN_DIR}")
480 endif()
481 string(REGEX REPLACE "^/" "" CMAKE_DATA_DIR "${CMAKE_DATA_DIR}")
482 string(REGEX REPLACE "^/" "" CMAKE_DOC_DIR "${CMAKE_DOC_DIR}")
483 string(REGEX REPLACE "^/" "" CMAKE_MAN_DIR "${CMAKE_MAN_DIR}")
484
485 if(BUILD_TESTING)
486   include(${CMake_SOURCE_DIR}/Tests/CMakeInstall.cmake)
487 endif()
488
489 # include special compile flags for some compilers
490 include(CompileFlags.cmake)
491
492 # no clue why we are testing for this here
493 include(CheckSymbolExists)
494 CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
495 CHECK_SYMBOL_EXISTS(environ "stdlib.h" HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
496
497 # CMAKE_TESTS_CDASH_SERVER: CDash server used by CMake/Tests.
498 #
499 # If not defined or "", this variable defaults to the server at
500 # http://www.cdash.org/CDash.
501 #
502 # If set explicitly to "NOTFOUND", curl tests and ctest tests that use
503 # the network are skipped.
504 #
505 # If set to something starting with "http://localhost/", the CDash is
506 # expected to be an instance of CDash used for CDash testing, pointing
507 # to a cdash4simpletest database. In these cases, the CDash dashboards
508 # should be run first.
509 #
510 if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x")
511   set(CMAKE_TESTS_CDASH_SERVER "http://www.cdash.org/CDash")
512 endif()
513
514 # build the utilities (a macro defined in this file)
515 CMAKE_BUILD_UTILITIES()
516
517 # On NetBSD ncurses is required, since curses doesn't have the wsyncup()
518 # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib,
519 # which isn't in the default linker search path. So without RPATH ccmake
520 # doesn't run and the build doesn't succeed since ccmake is executed for
521 # generating the documentation.
522 if(BUILD_CursesDialog)
523   get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH)
524   set(CURSES_NEED_RPATH FALSE)
525   if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64")
526     set(CURSES_NEED_RPATH TRUE)
527   endif()
528 endif()
529
530 if(BUILD_QtDialog)
531   if(APPLE)
532     set(CMAKE_BUNDLE_NAME
533       "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}-${CMake_VERSION_PATCH}")
534     set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
535     # make sure CMAKE_INSTALL_PREFIX ends in /
536     string(LENGTH "${CMAKE_INSTALL_PREFIX}" LEN)
537     math(EXPR LEN "${LEN} -1" )
538     string(SUBSTRING "${CMAKE_INSTALL_PREFIX}" ${LEN} 1 ENDCH)
539     if(NOT "${ENDCH}" STREQUAL "/")
540       set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
541     endif()
542     set(CMAKE_INSTALL_PREFIX
543       "${CMAKE_INSTALL_PREFIX}${CMAKE_BUNDLE_NAME}.app/Contents")
544   endif()
545
546   set(QT_NEED_RPATH FALSE)
547   if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64")
548     set(QT_NEED_RPATH TRUE)
549   endif()
550 endif()
551
552
553 # The same might be true on other systems for other libraries.
554 # Then only enable RPATH if we have are building at least with cmake 2.4,
555 # since this one has much better RPATH features than cmake 2.2.
556 # The executables are then built with the RPATH for the libraries outside
557 # the build tree, which is both the build and the install RPATH.
558 if (UNIX)
559   if(   CMAKE_USE_SYSTEM_CURL   OR  CMAKE_USE_SYSTEM_ZLIB
560         OR  CMAKE_USE_SYSTEM_EXPAT  OR  CTEST_USE_XMLRPC  OR  CURSES_NEED_RPATH  OR  QT_NEED_RPATH)
561     set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.")
562     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
563     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
564   endif()
565 endif ()
566
567
568 # add the uninstall support
569 configure_file(
570   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
571   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
572   @ONLY)
573 add_custom_target(uninstall
574   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
575
576 include (CMakeCPack.cmake)
577
578 # setup some Testing support (a macro defined in this file)
579 CMAKE_SETUP_TESTING()
580 configure_file(
581   "${CMAKE_CURRENT_SOURCE_DIR}/DartLocal.conf.in"
582   "${CMAKE_CURRENT_BINARY_DIR}/DartLocal.conf"
583   COPYONLY)
584
585 option(CMAKE_STRICT
586   "Perform strict testing to record property and variable access. Can be used to report any undefined properties or variables" OFF)
587 mark_as_advanced(CMAKE_STRICT)
588
589 if(NOT CMake_VERSION_IS_RELEASE)
590   if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND
591       NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS 4.2)
592     set(C_FLAGS_LIST -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts
593                      -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security
594                      -Wmissing-format-attribute -fno-common -Wundef
595     )
596     set(CXX_FLAGS_LIST -Wnon-virtual-dtor -Wcast-align -Wchar-subscripts -Wall -W
597                        -Wshadow -Wpointer-arith -Wformat-security -Wundef
598     )
599
600     foreach(FLAG_LANG  C CXX)
601       foreach(FLAG ${${FLAG_LANG}_FLAGS_LIST})
602         if(NOT " ${CMAKE_${FLAG_LANG}_FLAGS} " MATCHES " ${FLAG} ")
603           set(CMAKE_${FLAG_LANG}_FLAGS "${CMAKE_${FLAG_LANG}_FLAGS} ${FLAG}")
604         endif()
605       endforeach()
606     endforeach()
607
608     unset(C_FLAGS_LIST)
609     unset(CXX_FLAGS_LIST)
610   endif()
611 endif()
612
613 # build the remaining subdirectories
614 add_subdirectory(Source)
615 add_subdirectory(Utilities)
616 add_subdirectory(Tests)
617
618 if(BUILD_TESTING)
619   CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
620 endif()
621 CMAKE_SET_TARGET_FOLDER(cmw9xcom "Utilities/Win9xCompat")
622 CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
623
624 # add a test
625 add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
626   --system-information  -G "${CMAKE_TEST_GENERATOR}" )
627
628 # Install license file as it requires.
629 install(FILES Copyright.txt DESTINATION ${CMAKE_DOC_DIR})
630
631 # Install script directories.
632 install(
633   DIRECTORY Modules Templates
634   DESTINATION ${CMAKE_DATA_DIR}
635   FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
636   DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
637                         GROUP_READ GROUP_EXECUTE
638                         WORLD_READ WORLD_EXECUTE
639   PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
640                               GROUP_READ GROUP_EXECUTE
641                               WORLD_READ WORLD_EXECUTE
642   )
643
644 # process docs related install
645 add_subdirectory(Docs)
646
647 #-----------------------------------------------------------------------
648 # End of the main section of the CMakeLists file
649 #-----------------------------------------------------------------------
650
651 # As a special case when building CMake itself, CMake 2.8.0 and below
652 # look up EXECUTABLE_OUTPUT_PATH in the top-level CMakeLists.txt file
653 # to compute the location of the "cmake" executable.  We set it here
654 # so that those CMake versions can find it.  We wait until after all
655 # the add_subdirectory() calls to avoid affecting the subdirectories.
656 set(EXECUTABLE_OUTPUT_PATH ${CMake_BIN_DIR})