Imported Upstream version 1.9.8
[platform/upstream/doxygen.git] / CMakeLists.txt
1 # vim:ts=4:sw=4:expandtab:autoindent:
2 #
3 # Copyright (C) 1997-2015 by Dimitri van Heesch.
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation under the terms of the GNU General Public License is hereby
7 # granted. No representations are made about the suitability of this software
8 # for any purpose. It is provided "as is" without express or implied warranty.
9 # See the GNU General Public License for more details.
10 #
11 # Documents produced by Doxygen are derivative works derived from the
12 # input used in their production; they are not affected by this license.
13
14 cmake_minimum_required(VERSION 3.12)
15 project(doxygen)
16
17 option(build_wizard    "Build the GUI frontend for doxygen." OFF)
18 option(build_app       "Example showing how to embed doxygen in an application." OFF)
19 option(build_parse     "Parses source code and dumps the dependencies between the code elements." OFF)
20 option(build_xmlparser "Automatically update the XML parser modules when updating the schema files." OFF)
21 option(build_search    "Build external search tools (doxysearch and doxyindexer)" OFF)
22 option(build_doc       "Build user manual (HTML and PDF)" OFF)
23 option(build_doc_chm   "Build user manual (CHM)" OFF)
24 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
25     option(use_libc++  "Use libc++ as C++ standard library." ON)
26 endif()
27 option(use_libclang    "Add support for libclang parsing." OFF)
28 option(use_sys_spdlog  "Use system spdlog instead of bundled." OFF)
29 option(static_libclang "Link to a statically compiled version of LLVM/libclang." OFF)
30 option(win_static      "Link with /MT in stead of /MD on windows" OFF)
31 option(enable_console  "Enable that executables on Windows get the CONSOLE bit set for the doxywizard executable [development]"  OFF)
32 option(enable_coverage "Enable coverage reporting for gcc/clang [development]" OFF)
33 option(enable_tracing  "Enable tracing option in release builds [development]" OFF)
34 option(enable_lex_debug "Enable debugging info for lexical scanners in release builds [development]" OFF)
35
36 set(force_qt CACHE INTERNAL "Forces doxywizard to build using the specified major version, this can be Qt5 or Qt6")
37 set_property(CACHE force_qt PROPERTY STRINGS OFF Qt6 Qt5)
38
39 SET(enlarge_lex_buffers "262144" CACHE INTERNAL "Sets the lex input and read buffers to the specified size")
40
41 if(enable_coverage)
42   if ("${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
43     message(FATAL_ERROR "Doxygen cannot be generated in-place, the build directory (${PROJECT_BINARY_DIR}) has to differ from the doxygen main directory (${PROJECT_SOURCE_DIR})\nPlease don't forget to remove the already created file 'CMakeCache.txt' and the directory 'CMakeFiles'!")
44   endif()
45 endif()
46
47 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
48 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Sanitizers")
49 set(TOP "${PROJECT_SOURCE_DIR}")
50 include(version)
51
52 message(STATUS "Using Cmake version ${CMAKE_VERSION}")
53 if (${CMAKE_VERSION} VERSION_LESS "3.21.0")
54     set(depfile_supported  "0" CACHE INTERNAL "DEPFILE is not supported")
55 else()
56     set(depfile_supported  "1" CACHE INTERNAL "DEPFILE is supported")
57 endif()
58
59 set(clang    "0" CACHE INTERNAL "used in settings.h")
60
61 set(MACOS_VERSION_MIN 10.14)
62 if (use_libclang)
63         set(clang    "1" CACHE INTERNAL "used in settings.h")
64         find_package(LLVM CONFIG REQUIRED)
65         find_package(Clang CONFIG REQUIRED)
66 endif()
67 if (use_sys_spdlog)
68         find_package(spdlog CONFIG REQUIRED)
69 endif()
70 if (build_wizard)
71     if (force_qt STREQUAL "Qt6")
72         if (CMAKE_SYSTEM MATCHES "Darwin")
73             set(MACOS_VERSION_MIN 10.15)
74         endif()
75     endif()
76 endif()
77
78 # use C++17 standard for compiling
79 set(CMAKE_CXX_STANDARD 17)
80 set(CMAKE_CXX_STANDARD_REQUIRED ON)
81 set(CMAKE_CXX_EXTENSIONS ON)
82
83 if (CMAKE_SYSTEM MATCHES "Darwin")
84     set(CMAKE_OSX_DEPLOYMENT_TARGET "${MACOS_VERSION_MIN}" CACHE STRING "Minimum OS X deployment version" FORCE)
85     set(CMAKE_CXX_FLAGS "-Wno-deprecated-register -mmacosx-version-min=${MACOS_VERSION_MIN} ${CMAKE_CXX_FLAGS}")
86     set(CMAKE_C_FLAGS "-Wno-deprecated-register -mmacosx-version-min=${MACOS_VERSION_MIN} ${CMAKE_C_FLAGS}")
87     find_library(CORESERVICES_LIB CoreServices)
88     set(EXTRA_LIBS ${CORESERVICES_LIB})
89 endif()
90
91 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_OMIT_LOAD_EXTENSION=1")
92
93 if (WIN32)
94     if (MSVC)
95         if (NOT ICONV_DIR)
96           set(ICONV_DIR "${PROJECT_SOURCE_DIR}/winbuild")
97         endif()
98         set(CMAKE_REQUIRED_DEFINITIONS "-DLIBICONV_STATIC")
99         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") # needed for language.cpp on 64bit
100         add_definitions(-DLIBICONV_STATIC -D_CRT_SECURE_NO_WARNINGS)
101         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
102     endif()
103     if (CMAKE_GENERATOR MATCHES "NMake Makefiles")
104         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
105     endif()
106 endif()
107 if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
108    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
109
110    if (CMAKE_BUILD_TYPE STREQUAL  "")
111      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
112    endif()
113 endif()
114
115 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
116    if ((CMAKE_GENERATOR MATCHES "MinGW Makefiles") OR
117        (CMAKE_GENERATOR MATCHES "MSYS Makefiles") OR
118        (CMAKE_GENERATOR MATCHES "Unix Makefiles"))
119
120       set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
121
122       if (CMAKE_BUILD_TYPE STREQUAL  "")
123         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
124       endif()
125    endif()
126 endif()
127
128 # needed for JavaCC
129 set(JAVA_CC_EXTRA_FLAGS "-DJAVACC_CHAR_TYPE=\"unsigned char\"")
130 set(CMAKE_CXX_FLAGS       "${CMAKE_CXX_FLAGS}       ${JAVA_CC_EXTRA_FLAGS}")
131 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${JAVA_CC_EXTRA_FLAGS}")
132
133 if(POLICY CMP0063)
134   cmake_policy(SET CMP0063 NEW)
135 endif()
136 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
137 set(CMAKE_C_VISIBILITY_PRESET hidden)
138 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
139
140 if (CMAKE_GENERATOR MATCHES "Ninja")
141   set(LEX_FLAGS )
142   set(YACC_FLAGS )
143   set(JAVACC_FLAGS )
144 else ()
145   set(LEX_FLAGS $(LEX_FLAGS))
146   set(YACC_FLAGS $(YACC_FLAGS))
147   set(JAVACC_FLAGS $(JAVACC_FLAGS))
148 endif ()
149
150 find_program(DOT NAMES dot)
151 find_package(Python REQUIRED)
152 find_package(FLEX REQUIRED)
153 if (FLEX_VERSION VERSION_LESS 2.5.37)
154   message(SEND_ERROR "Doxygen requires at least flex version 2.5.37 (installed: ${FLEX_VERSION})")
155 endif()
156 find_package(BISON REQUIRED)
157 if (BISON_VERSION VERSION_LESS 2.7)
158   message(SEND_ERROR "Doxygen requires at least bison version 2.7 (installed: ${BISON_VERSION})")
159 endif()
160 find_package(Threads)
161 find_package(Sanitizers)
162
163 if ((CMAKE_BUILD_TYPE STREQUAL "Debug") OR enable_lex_debug)
164   set(LEX_FLAGS "${LEX_FLAGS} -d")
165 endif()
166
167 find_package(Iconv REQUIRED)
168 include_directories(${ICONV_INCLUDE_DIR})
169
170
171 #set(DOXYDOCS ${PROJECT_SOURCE_DIR}/doc CACHE INTERNAL "Path to doxygen docs")
172 set(DOXYDOCS ${PROJECT_BINARY_DIR}/doc)
173 set(ENV{DOXYGEN_DOCDIR} ${DOXYDOCS})
174 set(GENERATED_SRC "${PROJECT_BINARY_DIR}/generated_src" CACHE INTERNAL "Stores generated files")
175 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
176 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
177
178 # place binaries for all build types in the same directory, so we know where to find it
179 # when running tests or generating docs
180 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH})
181 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH})
182 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${EXECUTABLE_OUTPUT_PATH})
183 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${EXECUTABLE_OUTPUT_PATH})
184
185 if (win_static)
186     set(CompilerFlags
187         CMAKE_CXX_FLAGS
188         CMAKE_CXX_FLAGS_DEBUG
189         CMAKE_CXX_FLAGS_RELEASE
190         CMAKE_CXX_FLAGS_MINSIZEREL
191         CMAKE_CXX_FLAGS_RELWITHDEBINFO
192         CMAKE_C_FLAGS
193         CMAKE_C_FLAGS_DEBUG
194         CMAKE_C_FLAGS_RELEASE
195         CMAKE_C_FLAGS_MINSIZEREL
196         CMAKE_C_FLAGS_RELWITHDEBINFO)
197     foreach(CompilerFlag ${CompilerFlags})
198       string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
199     endforeach()
200 endif()
201
202 include(cmake/CompilerWarnings.cmake)
203 include(cmake/Coverage.cmake)
204 include(cmake/WindowsEncoding.cmake)
205
206 add_subdirectory(deps)
207 add_subdirectory(libversion)
208 add_subdirectory(libxml)
209 add_subdirectory(vhdlparser)
210 add_subdirectory(src)
211
212 if (build_doc_chm)
213     if (WIN32)
214           find_package(HTMLHelp REQUIRED)
215           set(build_doc ON)
216     else ()
217           message(WARNING "CHM documentation generation not supported for this platform, ignoring setting.")
218           set(build_doc_chm OFF)
219     endif ()
220 endif ()
221
222 if (build_doc)
223     add_subdirectory(examples)
224     add_subdirectory(doc)
225 endif ()
226
227 add_subdirectory(doc_internal)
228 add_subdirectory(addon)
229
230 enable_testing()
231 add_subdirectory(testing)
232
233 include(cmake/packaging.cmake) # set CPACK_xxxx properties
234 include(CPack)