gitlab-ci: enable sanitizers for the meson builds
[mesa-waffle.git] / CMakeLists.txt
blob4456fcb1be5082b552d0a23fd2c4d59066a0021a
1 # SPDX-FileCopyrightText: Copyright 2012 Intel Corporation
2 # SPDX-License-Identifier: BSD-2-Clause
4 project(waffle1 C)
6 cmake_minimum_required(VERSION 2.8.12)
8 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
10 # Set the default location for all build artifacts to traditionally named
11 # top-level directories.  CMake's default location for build artifacts varies
12 # per artifact and is hard-to-guess.
13 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
14 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
15 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
17 include(WaffleDefineOS)
18 include(WaffleFindDependencies)
19 include(Options.cmake)
20 include(WaffleDefineInternalOptions)
21 include(WaffleValidateOptions)
22 include(WaffleDefineVersion)
23 include(WaffleDefineCompilerFlags)
24 include(GNUInstallDirs)
26 if(waffle_build_tests)
27     include(WaffleCMocka)
28 endif()
30 # Require MSVC 2013 U4
31 if (MSVC AND ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 18.00.31101.0)
32     message (FATAL_ERROR "Visual Studio 2013 Update 4 or later required")
33 endif ()
35 find_package(PkgConfig)
37 # ------------------------------------------------------------------------------
38 # Targets: check, check-func, valgrind-check, valgrind-check-func
39 # ------------------------------------------------------------------------------
42 # Target 'check' runs unit tests, but no functional tests.
44 add_custom_target(check)
47 # Target 'check-func' runs functional tests as well as unit tests.
49 # The unit tests are ran first (due to the depenency on 'check'). If any unit
50 # test fails, then no functional tests run.
52 add_custom_target(check-func
53     DEPENDS check
54     )
56 find_program(VALGRIND_EXECUTABLE valgrind)
57 if(VALGRIND_EXECUTABLE)
58     # Runs the 'check' target under valgrind.
59     add_custom_target(valgrind-check
60         DEPENDS check
61         )
63     # Runs the 'check-func' target under valgrind.
64     add_custom_target(valgrind-check-func
65         DEPENDS valgrind-check check-func
66         )
67 endif()
69 # ------------------------------------------------------------------------------
70 # Add subdirectories
71 # ------------------------------------------------------------------------------
73 if(waffle_on_mac)
74     link_libraries(
75         ${COCOA_FRAMEWORK}
76         ${CORE_FOUNDATION_FRAMEWORK}
77         )
78 endif()
80 include_directories(
81     include
82     include/waffle-1
83     src
84     )
86 add_subdirectory(third_party/threads)
87 include_directories(
88     third_party/threads
89     )
90 set(THREADS_LIBRARIES threads_bundled)
92 if(MSVC)
93     add_subdirectory(third_party/getopt)
94     include_directories(
95         third_party/getopt
96         )
97     set(GETOPT_LIBRARIES getopt_bundled)
98 endif()
100 add_subdirectory(doc)
101 add_subdirectory(src)
102 add_subdirectory(include)
103 add_subdirectory(man)
105 if(waffle_build_tests)
106     add_subdirectory(tests)
107 endif()
109 if(waffle_build_examples)
110     add_subdirectory(examples)
111 endif()
113 # ------------------------------------------------------------------------------
114 # Install packaging files: waffle.pc WaffleConfigVersion.cmake, and
115 # WaffleConfig.cmake
116 # ------------------------------------------------------------------------------
118 configure_file(waffle.pc.in ${waffle_libname}.pc @ONLY)
120 install(
121     FILES ${CMAKE_BINARY_DIR}/${waffle_libname}.pc
122     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
123     COMPONENT pkgconfig
124     )
126 set(ConfigPackageLocation "${CMAKE_INSTALL_LIBDIR}/cmake/Waffle")
127 include(CMakePackageConfigHelpers)
128 write_basic_package_version_file(
129     "${CMAKE_BINARY_DIR}/cmake/Modules/WaffleConfigVersion.cmake"
130     VERSION "${waffle_version}"
131     COMPATIBILITY SameMajorVersion
134 configure_package_config_file(
135     cmake/Modules/WaffleConfig.cmake.in
136     cmake/Modules/WaffleConfig.cmake
137     INSTALL_DESTINATION "${ConfigPackageLocation}"
138     PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR
139     NO_CHECK_REQUIRED_COMPONENTS_MACRO
142 install(
143     FILES
144         "${CMAKE_BINARY_DIR}/cmake/Modules/WaffleConfigVersion.cmake"
145         "${CMAKE_BINARY_DIR}/cmake/Modules/WaffleConfig.cmake"
146     DESTINATION "${ConfigPackageLocation}"
147     COMPONENT devel
150 # ------------------------------------------------------------------------------
151 # Install core documentation
152 # ------------------------------------------------------------------------------
154 install(
155     FILES
156         "README.md"
157         "LICENSE.txt"
158         "CONTRIBUTING.md"
159     DESTINATION "${CMAKE_INSTALL_DOCDIR}"
160     COMPONENT coredocs
161     )
163 # ------------------------------------------------------------------------------
164 # Install shell completion
165 # ------------------------------------------------------------------------------
167 find_package(bash-completion)
168 if (NOT BASH_COMPLETION_FOUND)
169     # Fallback default dir
170     set(BASH_COMPLETION_COMPLETIONSDIR
171         "${CMAKE_INSTALL_DATADIR}/bash-completion/completions/")
172 endif()
174 install(
175     FILES "shell-completion/bash/wflinfo"
176     DESTINATION "${CMAKE_INSTALL_PREFIX}/${BASH_COMPLETION_COMPLETIONSDIR}"
177     COMPONENT shell-completion
178     )
180 # ------------------------------------------------------------------------------
182 include(WafflePrintConfigurationSummary)
184 set (CPACK_SET_DESTDIR ON)
185 set (CPACK_PACKAGE_VERSION_MAJOR ${waffle_major_version})
186 set (CPACK_PACKAGE_VERSION_MINOR ${waffle_minor_version})
187 set (CPACK_PACKAGE_VERSION_PATCH ${waffle_patch_version})
189 # cpack detects win64 vs win32 only when msvc is available
190 # reported upstream, fix (likely post cmake 3.0) pending
191 if (MINGW)
192         if (CMAKE_SIZEOF_VOID_P EQUAL 8)
193                 set (CPACK_SYSTEM_NAME win64)
194         endif ()
195 endif ()
197 # See https://www.vtk.org/Wiki/CMake:CPackPackageGenerators
198 if (WIN32)
199         set (CPACK_GENERATOR "ZIP")
200 else ()
201         set (CPACK_GENERATOR "TBZ2")
202 endif ()
204 include(CPack)