You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1222 lines
45 KiB

2 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
18 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
  1. #
  2. # This program source code file is part of KICAD, a free EDA CAD application.
  3. #
  4. # Copyright (C) 2007-2021 Kicad Developers, see AUTHORS.txt for contributors.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, you may find one here:
  18. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. # or you may search the http://www.gnu.org website for the version 2 license,
  20. # or you may write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. #
  23. cmake_minimum_required( VERSION 3.22 FATAL_ERROR )
  24. # Generate DEPFILES without transforming relative paths
  25. cmake_policy( SET CMP0116 OLD )
  26. # Needed to allow the doxygen-python process that depends on swig generation running twice to occur
  27. # The current structure requires the add_custom_command to get called twice, the NEW behavior deduplicates it
  28. cmake_policy( SET CMP0113 OLD )
  29. # Enable CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to override the cmake pdb flags easily
  30. if (POLICY CMP0141)
  31. cmake_policy(SET CMP0141 NEW)
  32. endif (POLICY CMP0141)
  33. # Default to CMAKE_BUILD_TYPE = Release unless overridden on command line
  34. # http://www.cmake.org/pipermail/cmake/2008-September/023808.html
  35. if( DEFINED CMAKE_BUILD_TYPE )
  36. set( CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Set to either \"Release\" or \"Debug\"" )
  37. else()
  38. set( CMAKE_BUILD_TYPE Release CACHE STRING "Set to either \"Release\" or \"Debug\"" )
  39. endif()
  40. project( kicad )
  41. # Create a default build type for our QA that doesn't include `NDEBUG`
  42. set(CMAKE_CXX_FLAGS_QABUILD "-Os -g1 -ggdb1")
  43. include( GNUInstallDirs )
  44. include( CMakeDependentOption )
  45. include( CheckCXXCompilerFlag )
  46. # Output compile_commands.json for various LSP and other users
  47. set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
  48. # Path to KiCad's CMake modules.
  49. set( KICAD_CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" )
  50. set( CMAKE_MODULE_PATH "${KICAD_CMAKE_MODULE_PATH}" )
  51. include( ConfigurePlatform )
  52. # Create a flag to identify the non-Apple unix systems
  53. if( UNIX AND NOT APPLE )
  54. set( UNIX_NOT_APPLE ON )
  55. else()
  56. set( UNIX_NOT_APPLE OFF )
  57. endif()
  58. if( APPLE OR WIN32 )
  59. set( APPLE_OR_WIN32 ON )
  60. else()
  61. set( APPLE_OR_WIN32 OFF )
  62. endif()
  63. #
  64. # KiCad build options should be added below.
  65. #
  66. # If you add a new build option, please add its state to the
  67. # OnCopyVersionInfo() function in common/dialog_about/dialog_about.cpp
  68. # so that build option settings can be included in bug reports.
  69. #
  70. ####################################
  71. # Feature flags
  72. ####################################
  73. option( KICAD_SPICE_QA
  74. "Build software Quality assurance unit tests for spice (default ON)"
  75. ON )
  76. option( KICAD_USE_SENTRY
  77. "Build KiCad with support for sentry app metrics"
  78. OFF )
  79. option( KICAD_SIGNAL_INTEGRITY
  80. "Build tools for signal integrity analysis ( default ON )"
  81. ON )
  82. option( KICAD_BUILD_I18N
  83. "Build the translation libraries."
  84. OFF )
  85. option( KICAD_BUILD_QA_TESTS
  86. "Build software Quality assurance unit tests (default ON)"
  87. ON )
  88. option( KICAD_SCRIPTING_WXPYTHON
  89. "Build wxPython implementation for wx interface building in Python and py.shell (default ON)."
  90. ON )
  91. mark_as_advanced( KICAD_SCRIPTING_WXPYTHON )
  92. option( KICAD_UPDATE_CHECK
  93. "Build in update check"
  94. ON )
  95. # EGL is only needed on Linux with Wayland
  96. cmake_dependent_option( KICAD_USE_EGL
  97. "Build KiCad with EGL backend support for Wayland."
  98. OFF "UNIX_NOT_APPLE"
  99. OFF)
  100. cmake_dependent_option( KICAD_USE_BUNDLED_GLEW
  101. "Use the bundled version of GLEW - only available when KICAD_USE_EGL is set"
  102. ON "KICAD_USE_EGL"
  103. OFF )
  104. cmake_dependent_option( KICAD_WAYLAND
  105. "Support Wayland features"
  106. ON "KICAD_USE_EGL"
  107. OFF )
  108. # Options to build with flatpak platform defaults (only on Linux)
  109. cmake_dependent_option( KICAD_BUILD_FLATPAK
  110. "Build KiCad with metadata, launchers, icons, and MIME info following flatpak conventions"
  111. OFF "UNIX_NOT_APPLE"
  112. OFF )
  113. cmake_dependent_option( KICAD_BUILD_NIGHTLY_FLATPAK
  114. "Build a Nightly flatpak (requires KICAD_BUILD_FLATPAK=ON)"
  115. OFF "UNIX_NOT_APPLE"
  116. OFF )
  117. cmake_dependent_option( KICAD_WIN32_DPI_AWARE
  118. "Turn on DPI awareness for Windows builds only"
  119. OFF "WIN32"
  120. OFF )
  121. cmake_dependent_option( KICAD_WIN32_VERIFY_CODESIGN
  122. "When enabled, verifies the code signing signature of certain DLLs loaded during runtime."
  123. OFF "WIN32"
  124. OFF )
  125. # On Windows, binaries created by link option -g3 are very large (more than 1Gb for pcbnew,
  126. # and more than 3Gb for the full kicad suite)
  127. # This option create binaries using link option -g1 that create much smaller files, but
  128. # there are less info in debug (but the file names and line numbers are available)
  129. cmake_dependent_option( KICAD_BUILD_SMALL_DEBUG_FILES
  130. "Create smaller binaries in debug builds."
  131. OFF "NOT MSVC"
  132. OFF )
  133. cmake_dependent_option( KICAD_APPLE_MAKE_RELOCATEABLE_BUNDLE
  134. "On macOS, post-process the build to make it relocateable (default ON)"
  135. ON "APPLE" OFF )
  136. # Old versions of CMake and/or protobuf can require the FindProtobuf.cmake,
  137. # but modern platforms require this to be off
  138. option( KICAD_USE_CMAKE_FINDPROTOBUF "Use FindProtobuf provided by CMake" OFF )
  139. mark_as_advanced( KICAD_USE_CMAKE_FINDPROTOBUF )
  140. ####################################
  141. # Installation options
  142. ####################################
  143. option( KICAD_INSTALL_DEMOS
  144. "Install KiCad demos and examples (default ON)"
  145. ON )
  146. option( KICAD_I18N_UNIX_STRICT_PATH
  147. "Use standard Unix locale lookup path (default OFF)."
  148. OFF )
  149. cmake_dependent_option( KICAD_WIN32_INSTALL_PDBS
  150. "Installs debug pdb to the bin folder, DO NOT USE (NOR REQUIRED) FOR DEBUGGING THE SOURCE ON MSVC. This is purely for release building.
  151. MSVC can find the PDBs without this."
  152. OFF "WIN32"
  153. OFF )
  154. ####################################
  155. # Compiler options/tools
  156. ####################################
  157. # Not supported by all platforms (for instance mingw)
  158. option( KICAD_SANITIZE_ADDRESS
  159. "Build KiCad with address sanitizer options. WARNING: Not compatible with gold linker"
  160. OFF )
  161. # Not supported by all platforms (for instance mingw)
  162. option( KICAD_SANITIZE_THREADS
  163. "Build KiCad with thread sanitizer options. WARNING: Not compatible with gold linker"
  164. OFF )
  165. # Enable additional valgrind instrumentation for stack tracking in libcontext
  166. option( KICAD_USE_VALGRIND
  167. "Build KiCad with valgrind stack tracking enabled."
  168. OFF )
  169. option( KICAD_STDLIB_DEBUG
  170. "Build KiCad with libstdc++ debug flags enabled."
  171. OFF )
  172. option( KICAD_STDLIB_LIGHT_DEBUG
  173. "Build KiCad with libstdc++ with -Wp,-D_GLIBCXX_ASSERTIONS flag enabled. Not as intrusive as KICAD_STDLIB_DEBUG"
  174. OFF )
  175. cmake_dependent_option( KICAD_WIN32_BUILD_PARALLEL_CL_MP
  176. "Build in parallel using the /MP compiler option (default OFF for safety reasons)"
  177. OFF "WIN32"
  178. OFF )
  179. cmake_dependent_option( KICAD_WIN32_LTCG
  180. "Enable Whole Program Optimization"
  181. OFF "WIN32"
  182. OFF )
  183. # Advanced option to make link maps (only available on linux)
  184. cmake_dependent_option( KICAD_MAKE_LINK_MAPS
  185. "Create link maps for artifacts"
  186. OFF "UNIX_NOT_APPLE"
  187. OFF )
  188. mark_as_advanced( KICAD_MAKE_LINK_MAPS )
  189. set( KICAD_INIT_VARIABLES "Default" CACHE STRING "Specify how compiler should initialize variables" )
  190. set_property( CACHE KICAD_INIT_VARIABLES PROPERTY STRINGS
  191. "Default" # Equivalent to pattern in debug mode (but not when Valgrind is used), zero in release mode
  192. "Off" # Don't initialize anything
  193. "Zero" # Initialize trivial variables to 0
  194. "Pattern" ) # Initialize trivial variables to a non-zero pattern to flag them (usually 0xAA...)
  195. ####################################
  196. # Debugging/profiling
  197. ####################################
  198. option( KICAD_DRC_PROTO
  199. "Build the DRC prototype QA tool"
  200. OFF )
  201. option( KICAD_BUILD_PEGTL_DEBUG_TOOL
  202. "Build the PEGTL parser debugging/playground QA tool"
  203. OFF )
  204. option( KICAD_BUILD_PNS_DEBUG_TOOL
  205. "Build the P&S debugging/playground QA tool"
  206. OFF )
  207. option( KICAD_GAL_PROFILE
  208. "Enable profiling info for GAL"
  209. OFF )
  210. option( KICAD_IPC_API
  211. "Enable IPC API"
  212. ON )
  213. option( KICAD_IDF_TOOLS
  214. "Build additional idf tools"
  215. ON )
  216. # Global setting: exports are explicit
  217. set( CMAKE_CXX_VISIBILITY_PRESET "hidden" )
  218. set( CMAKE_VISIBILITY_INLINES_HIDDEN ON )
  219. # Global setting: build everything position independent
  220. set( CMAKE_POSITION_INDEPENDENT_CODE ON )
  221. # Global setting: Use C++20
  222. set(CMAKE_CXX_STANDARD 20)
  223. set(CMAKE_CXX_EXTENSIONS OFF)
  224. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  225. # Pass defines into KiCad code based on the build options set
  226. add_compile_definitions( $<$<BOOL:${KICAD_SCRIPTING_WXPYTHON}>:KICAD_SCRIPTING_WXPYTHON> )
  227. add_compile_definitions( $<$<BOOL:${KICAD_SIGNAL_INTEGRITY}>:KICAD_SIGNAL_INTEGRITY> )
  228. add_compile_definitions( $<$<BOOL:${KICAD_USE_VALGRIND}>:KICAD_USE_VALGRIND> )
  229. add_compile_definitions( $<$<BOOL:${KICAD_GAL_PROFILE}>:KICAD_GAL_PROFILE> )
  230. add_compile_definitions( $<$<BOOL:${KICAD_WIN32_VERIFY_CODESIGN}>:KICAD_WIN32_VERIFY_CODESIGN> )
  231. add_compile_definitions( $<$<BOOL:${KICAD_UPDATE_CHECK}>:KICAD_UPDATE_CHECK> )
  232. if( KICAD_USE_EGL )
  233. message( STATUS "Configuring KiCad for the wxGLCanvas EGL backend" )
  234. add_compile_definitions( KICAD_USE_EGL )
  235. endif()
  236. if( KICAD_WAYLAND )
  237. message( STATUS "Configuring KiCad to support Wayland features" )
  238. add_compile_definitions( KICAD_WAYLAND )
  239. endif()
  240. if( KICAD_IPC_API )
  241. add_definitions( -DKICAD_IPC_API )
  242. endif()
  243. # Ensure DEBUG is defined for all platforms in Debug builds
  244. add_compile_definitions( $<$<CONFIG:Debug>:DEBUG> )
  245. # Add option to add user directories for linker, if any
  246. link_directories( ${LINK_DIRECTORIES_PATH} )
  247. set( KICAD_CONFIG_DIR "kicad" CACHE STRING "Location of user specific KiCad config files" )
  248. mark_as_advanced( KICAD_CONFIG_DIR )
  249. add_compile_definitions( KICAD_CONFIG_DIR=${KICAD_CONFIG_DIR} )
  250. # Set default data file path to CMAKE_INSTALL_PREFIX if it wasn't specified during the
  251. # CMake configuration. The value of DEFAULT_INSTALL_PATH is expanded in config.h and
  252. # used in the source code to define the base path for kicad search paths and environment
  253. # variables.
  254. if( NOT DEFAULT_INSTALL_PATH )
  255. set( DEFAULT_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}"
  256. CACHE
  257. PATH
  258. "Location of KiCad data files." )
  259. endif()
  260. message( STATUS "KiCad install dir: <${DEFAULT_INSTALL_PATH}>" )
  261. # Generate build system specific header file.
  262. include( PerformFeatureChecks )
  263. perform_feature_checks()
  264. # Setup the compiler warnings
  265. include( ${KICAD_CMAKE_MODULE_PATH}/Warnings.cmake )
  266. if( WIN32 )
  267. # define UNICODE and_UNICODE definition on Windows. KiCad uses unicode.
  268. # Both definitions are required
  269. add_compile_definitions( UNICODE _UNICODE)
  270. # In fully standards-compliant mode, M_PI et al. are defined only if
  271. # _USE_MATH_DEFINES is set.
  272. add_compile_definitions( _USE_MATH_DEFINES )
  273. add_compile_definitions( $<$<BOOL:${KICAD_WIN32_DPI_AWARE}>:KICAD_WIN32_DPI_AWARE=1> )
  274. endif()
  275. add_compile_definitions( $<$<BOOL:${KICAD_BUILD_ARCH_X86}>:KICAD_BUILD_ARCH_X86> )
  276. add_compile_definitions( $<$<BOOL:${KICAD_BUILD_ARCH_X64}>:KICAD_BUILD_ARCH_X64> )
  277. add_compile_definitions( $<$<BOOL:${KICAD_BUILD_ARCH_ARM}>:KICAD_BUILD_ARCH_ARM> )
  278. add_compile_definitions( $<$<BOOL:${KICAD_BUILD_ARCH_ARM64}>:KICAD_BUILD_ARCH_ARM64> )
  279. #================================================
  280. # Provide access to CCACHE
  281. #================================================
  282. if (USE_CCACHE)
  283. find_program(CCACHE_FOUND ccache)
  284. if(CCACHE_FOUND)
  285. # Set ccache on the actual lang
  286. list(PREPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND})
  287. list(PREPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
  288. message(STATUS "Used ${CCACHE_FOUND} for compilation.")
  289. else(CCACHE_FOUND)
  290. message(STATUS "CCache was requested but not found.")
  291. endif(CCACHE_FOUND)
  292. endif(USE_CCACHE)
  293. #================================================
  294. # Provide access to DISTCC
  295. #================================================
  296. if (USE_DISTCC)
  297. find_program(DISTCC_FOUND distcc)
  298. if(DISTCC_FOUND)
  299. list(APPEND CMAKE_C_COMPILER_LAUNCHER ${DISTCC_FOUND})
  300. list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${DISTCC_FOUND})
  301. message(STATUS "Using ${DISTCC_FOUND} for distributed build.")
  302. else(DISTCC_FOUND)
  303. message(INFO "Distcc was requested but not found.")
  304. endif(DISTCC_FOUND)
  305. endif(USE_DISTCC)
  306. #================================================
  307. # Setup compiler-specific flags
  308. #================================================
  309. if( CMAKE_COMPILER_IS_GNUCXX )
  310. # Set 32-bit flag for GCC to prevent excess precision (not needed for Clang)
  311. if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
  312. set( CMAKE_CXX_FLAGS "-ffloat-store ${CMAKE_CXX_FLAGS}" )
  313. endif()
  314. endif( CMAKE_COMPILER_IS_GNUCXX )
  315. if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  316. # Clang needs this flag or wxStrings, etc. won't be viewable in the debugger
  317. set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstandalone-debug" )
  318. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstandalone-debug" )
  319. endif()
  320. if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  321. # Link flags in Debug: -g1 and -ggdb1 or -g1 and -ggdb3 can be used.
  322. # Level 1 produces minimal information, enough for making basic backtraces.
  323. # This includes descriptions of functions and external variables, and line number tables,
  324. # but no information about local variables.
  325. # Level 3 includes full information, but binaries are much larger.
  326. if( KICAD_BUILD_SMALL_DEBUG_FILES )
  327. set( CMAKE_C_FLAGS_DEBUG "-g1 -ggdb1" )
  328. set( CMAKE_CXX_FLAGS_DEBUG "-g1 -ggdb1" )
  329. else()
  330. set( CMAKE_C_FLAGS_DEBUG "-g3 -ggdb3" )
  331. set( CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3" )
  332. endif()
  333. check_cxx_compiler_flag( "-ftrivial-auto-var-init=pattern" COMPILER_SUPPORTS_TRIVIAL_PATTERN_INIT )
  334. if( COMPILER_SUPPORTS_TRIVIAL_PATTERN_INIT )
  335. set( VAR_PATTERN_INIT_FLAGS -ftrivial-auto-var-init=pattern )
  336. endif()
  337. check_cxx_compiler_flag( "-ftrivial-auto-var-init=zero" COMPILER_SUPPORTS_TRIVIAL_ZERO_INIT )
  338. if( COMPILER_SUPPORTS_TRIVIAL_ZERO_INIT )
  339. set( VAR_ZERO_INIT_FLAGS -ftrivial-auto-var-init=zero )
  340. else()
  341. # Clang 15 and below required a special flag to enable the zero-init flag, so try that
  342. check_cxx_compiler_flag( "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang"
  343. COMPILER_REQUIRES_ENABLE_TRIVIAL_ZERO_INIT )
  344. if( COMPILER_REQUIRES_ENABLE_TRIVIAL_ZERO_INIT )
  345. set( VAR_ZERO_INIT_FLAGS -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang )
  346. endif()
  347. endif()
  348. if( NOT KICAD_INIT_VARIABLES STREQUAL "Off" )
  349. if( KICAD_INIT_VARIABLES STREQUAL "Default" )
  350. # Disable when using valgrind to preserve reporting of uninitialized variables
  351. if( NOT KICAD_USE_VALGRIND )
  352. # Use pattern init in debug mode only, use zero init every other time
  353. if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
  354. set( VAR_INIT_FLAGS ${VAR_PATTERN_INIT_FLAGS} )
  355. else()
  356. set( VAR_INIT_FLAGS ${VAR_ZERO_INIT_FLAGS} )
  357. endif()
  358. endif()
  359. elseif( KICAD_INIT_VARIABLES STREQUAL "Zero" )
  360. set( VAR_INIT_FLAGS ${VAR_ZERO_INIT_FLAGS} )
  361. elseif( KICAD_INIT_VARIABLES STREQUAL "Pattern" )
  362. set( VAR_INIT_FLAGS ${VAR_PATTERN_INIT_FLAGS} )
  363. endif()
  364. if( VAR_INIT_FLAGS )
  365. add_compile_options( ${VAR_INIT_FLAGS} )
  366. message( STATUS "Initializing trivial variables (${VAR_INIT_FLAGS})" )
  367. endif()
  368. endif()
  369. if( KICAD_SANITIZE_ADDRESS )
  370. add_compile_definitions( KICAD_SANITIZE_ADDRESS )
  371. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_SANITIZE_VECTOR -fsanitize=address -fsanitize-recover=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" )
  372. # ASAN shouldn't be used with these options (https://github.com/google/sanitizers/wiki/AddressSanitizer#faq)
  373. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
  374. endif()
  375. if( KICAD_SANITIZE_THREADS )
  376. add_compile_definitions( KICAD_SANITIZE_THREADS )
  377. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_SANITIZE_VECTOR -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer" )
  378. # Based on this warning https://github.com/JuliaLang/julia/blob/29d5158d27ddc3983ae2e373c4cd05569b9ead6c/src/julia.h#L77
  379. if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11 )
  380. message( WARNING "Clang version 11 and below may leak memory when running the thread sanitizer.\n"
  381. "Be careful when using this compiler.")
  382. endif()
  383. # Just duplicate the same flags as ASAN here, because why not.
  384. set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
  385. endif()
  386. if( KICAD_STDLIB_DEBUG )
  387. add_compile_definitions( KICAD_STDLIB_DEBUG )
  388. set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG" )
  389. elseif( KICAD_STDLIB_LIGHT_DEBUG )
  390. # useless if KICAD_STDLIB_DEBUG is ON.
  391. # this option makes some controls to trap out of bound memory access.
  392. add_compile_definitions( KICAD_STDLIB_LIGHT_DEBUG )
  393. set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wp,-D_GLIBCXX_ASSERTIONS" )
  394. endif()
  395. if( MINGW )
  396. list(APPEND mingw_resource_compiler_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/resources/msw/ )
  397. # include dir to allow getting the version header
  398. list(APPEND mingw_resource_compiler_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ )
  399. list(APPEND mingw_resource_compiler_DEFINES KICAD_BUILD_ARCH=${KICAD_BUILD_ARCH} )
  400. if( KICAD_WIN32_DPI_AWARE )
  401. list(APPEND mingw_resource_compiler_DEFINES KICAD_WIN32_DPI_AWARE=1 )
  402. endif()
  403. set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" )
  404. # for some reasons, cmake does do use always a response file to send the list of objects
  405. # to the archiver, and because this list can be very long, and can create issue
  406. # when it is used in a command line, force use of a response file to store it
  407. set( CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1 )
  408. # The MinGW compiler can use the microsoft system snprintf as standard and it has a broken
  409. # API with respect to the C99 standard, so make sure we force it to use its own compliant
  410. # snprintf
  411. add_compile_definitions( __USE_MINGW_ANSI_STDIO=1 )
  412. # Allow linking for Boost for the UUID against bcrypt
  413. set( EXTRA_LIBS "bcrypt" )
  414. endif()
  415. if( APPLE )
  416. set( CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -headerpad_max_install_names") # needed by fixbundle
  417. endif()
  418. endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
  419. if( MSVC )
  420. include_directories( ${CMAKE_SOURCE_DIR}/resources/msw/ )
  421. # Disallow implicit linking for Boost
  422. add_compile_definitions( BOOST_ALL_NO_LIB )
  423. # But allow it for the UUID so that it will link against bcrypt
  424. add_compile_definitions( BOOST_UUID_FORCE_AUTO_LINK )
  425. # Disable MSVC's deprecation warnings
  426. add_compile_definitions( _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE _SCL_SECURE_NO_WARNINGS )
  427. # Hide Windows's min() and max() macros
  428. add_compile_definitions( NOMINMAX )
  429. # source and execution charset are UTF-8
  430. string( APPEND CMAKE_CXX_FLAGS " /utf-8" )
  431. # cmake 3.25 or higher requried for MSVC, should be fine
  432. if( USE_CCACHE AND CCACHE_FOUND )
  433. # Equivalent to /Z7, ensures cmake doesn't fight over the default
  434. # ccache may encounter external PDB file write errors due to paralleism
  435. # Using the embedded PDB mode is ok for development use of ccache
  436. set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "Embedded")
  437. else()
  438. # Equivalent to /Zi, ensures cmake doesn't fight over the default
  439. set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase")
  440. endif()
  441. # /Zc:__cplusplus: define this macro according to C++ standard version
  442. string( APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus" )
  443. # /Zc:inline: enforces C++11 requirement that inline functions must have a definition in the same unit
  444. string( APPEND CMAKE_CXX_FLAGS " /Zc:inline" )
  445. # /GF: enable string pooling
  446. string( APPEND CMAKE_CXX_FLAGS_RELEASE " /GF" )
  447. string( APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " /GF" )
  448. # /Gy: Enable Function-Level Linking
  449. string( APPEND CMAKE_CXX_FLAGS_RELEASE " /Gy" )
  450. string( APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " /Gy" )
  451. # Avoid fatal error because /GF + swig wrapper exceed standard obj file limits
  452. string( APPEND CMAKE_CXX_FLAGS " /bigobj" )
  453. # /permissive-: This puts MSVC into compliance mode, this flag is default on with C++20
  454. # but we want to turn it on to enable debug performance improvements available under C++17 in MSVC 17.5+
  455. string( APPEND CMAKE_CXX_FLAGS " /permissive-" )
  456. # Exception handling
  457. # Remove the potential default EHsc option cmake doesn't allow us to remove easily
  458. string( REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
  459. if( KICAD_WIN32_CONTEXT_WINFIBER )
  460. # /EHsc: ensure standard exception C++ unwinding is enabled, "extern C" can never throw exceptions
  461. string( APPEND CMAKE_CXX_FLAGS " /EHsc" )
  462. else()
  463. # the asm libcontext implementation a slight change of rules
  464. # /EHs: ensure standard exception C++ unwinding is enabled, "extern C" MAY throw exceptions
  465. string( APPEND CMAKE_CXX_FLAGS " /EHs" )
  466. endif()
  467. if( KICAD_SANITIZE_ADDRESS )
  468. add_definitions( -DKICAD_SANITIZE_ADDRESS )
  469. add_definitions( -D_DISABLE_VECTOR_ANNOTATION )
  470. string( APPEND CMAKE_CXX_FLAGS " /fsanitize=address" )
  471. endif()
  472. if( KICAD_WIN32_LTCG )
  473. # we are implementing this manually because CMake's LTCG option is incomplete
  474. # https://gitlab.kitware.com/cmake/cmake/-/issues/20484
  475. string( APPEND CMAKE_CXX_FLAGS_RELEASE " /GL" )
  476. endif()
  477. foreach( type EXE SHARED MODULE)
  478. # /DEBUG: create PDB
  479. string( APPEND CMAKE_${type}_LINKER_FLAGS " /DEBUG /MANIFEST:NO" )
  480. # /OPT:REF: omit unreferenced code
  481. string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:REF /MANIFEST:NO" )
  482. string( APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO " /OPT:REF /MANIFEST:NO" )
  483. # /OPT:ICF: fold common data
  484. string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /OPT:ICF /MANIFEST:NO" )
  485. string( APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO " /OPT:ICF /MANIFEST:NO" )
  486. if( KICAD_WIN32_LTCG )
  487. # we are implementing this manually because CMake's LTCG option is incomplete
  488. # https://gitlab.kitware.com/cmake/cmake/-/issues/20484
  489. string( APPEND CMAKE_${type}_LINKER_FLAGS_RELEASE " /LTCG" )
  490. endif()
  491. endforeach()
  492. # Let cl.exe parallelize builds
  493. if( KICAD_WIN32_BUILD_PARALLEL_CL_MP )
  494. string( APPEND CMAKE_CXX_FLAGS " /MP" )
  495. endif()
  496. set( CMAKE_INSTALL_UCRT_LIBRARIES TRUE )
  497. include( InstallRequiredSystemLibraries )
  498. endif()
  499. # KIFACE_SUFFIX is the file extension used for top level program modules which
  500. # implement the KIFACE interface. A valid suffix starts with a period '.'.
  501. if( WIN32 )
  502. # We use .kiface extension so we don't collide with python DSO. (Linux/mac issue?)
  503. # Windows works fine with the native dll extension
  504. # which also resolves metadata issues because windows wants to see the dll extension
  505. set( KIFACE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} )
  506. else()
  507. # Temporary situation until we can dovetail the python DSO into the kiface DSO.
  508. set( KIFACE_SUFFIX ".kiface" )
  509. endif()
  510. # KIFACE_PREFIX is a basename prefix used for top level program modules which
  511. # implement the KIFACE.
  512. set( KIFACE_PREFIX "_" )
  513. #message( STATUS "KIFACE_SUFFIX:${KIFACE_SUFFIX} KIFACE_PREFIX:${KIFACE_PREFIX}" )
  514. #================================================
  515. # Locations for install targets.
  516. #================================================
  517. if( NOT APPLE )
  518. # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
  519. if( WIN32 )
  520. set( KICAD_BIN bin
  521. CACHE PATH "Location of KiCad binaries." )
  522. else()
  523. set( KICAD_BIN ${CMAKE_INSTALL_BINDIR}
  524. CACHE PATH "Location of KiCad binaries." )
  525. endif()
  526. # For now, the kifaces are just in the normal bin folder
  527. set( KICAD_KIFACE ${KICAD_BIN}
  528. CACHE PATH "Location of KiCad kifaces." )
  529. # Do not make these variables "PATH" b/c cmake will truncate them and we need the full path
  530. if( NOT IS_ABSOLUTE ${CMAKE_INSTALL_DATADIR} )
  531. set( KICAD_DATA ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/kicad
  532. CACHE STRING "Location of KiCad data files." )
  533. set( KICAD_DOCS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/doc/kicad
  534. CACHE STRING "Location of KiCad documentation files." )
  535. else()
  536. set( KICAD_DATA ${CMAKE_INSTALL_DATADIR}/kicad
  537. CACHE STRING "Location of KiCad data files." )
  538. set( KICAD_DOCS ${CMAKE_INSTALL_DATADIR}/doc/kicad
  539. CACHE STRING "Location of KiCad documentation files." )
  540. endif()
  541. set( KICAD_LIBRARY_DATA ${KICAD_DATA}
  542. CACHE STRING "Location of KiCad stock EDA library data" )
  543. if( WIN32 )
  544. set( KICAD_PLUGINS ${KICAD_BIN}/scripting/plugins
  545. CACHE PATH "Location of KiCad plugins." )
  546. set( KICAD_LIB ${KICAD_BIN}
  547. CACHE PATH "Location of KiCad shared objects" )
  548. set( KICAD_USER_PLUGIN ${KICAD_BIN}/plugins
  549. CACHE PATH "Location of KiCad user-loaded plugins" )
  550. else()
  551. set( KICAD_PLUGINS ${KICAD_DATA}/plugins
  552. CACHE PATH "Location of KiCad plugins." )
  553. set( KICAD_LIB ${CMAKE_INSTALL_LIBDIR}
  554. CACHE PATH "Location of KiCad shared objects" )
  555. set( KICAD_USER_PLUGIN ${CMAKE_INSTALL_LIBDIR}/kicad/plugins
  556. CACHE PATH "Location of KiCad user-loaded plugins" )
  557. endif()
  558. set( KICAD_DEMOS ${KICAD_DATA}/demos
  559. CACHE PATH "Location of KiCad demo files." )
  560. set( KICAD_TEMPLATE ${KICAD_LIBRARY_DATA}/template
  561. CACHE PATH "Location of KiCad template files." )
  562. else()
  563. # everything without leading / is relative to CMAKE_INSTALL_PREFIX.
  564. # CMAKE_INSTALL_PREFIX is root of .dmg image
  565. set( KICAD_BIN ${CMAKE_INSTALL_PREFIX}
  566. CACHE PATH "Location of KiCad binaries." FORCE )
  567. # some paths to single app bundle
  568. set( OSX_BUNDLE_MAIN "KiCad.app" )
  569. set( OSX_BUNDLE_BIN_DIR "Contents/MacOS" )
  570. set( OSX_BUNDLE_LIB_DIR "Contents/Frameworks" )
  571. set( OSX_BUNDLE_KIFACE_DIR "Contents/PlugIns" )
  572. set( OSX_BUNDLE_SUP_DIR "Contents/SharedSupport" )
  573. set( OSX_BUNDLE_APP_DIR "Contents/Applications" )
  574. set( OSX_BUNDLE_BUILD_DIR "${CMAKE_BINARY_DIR}/kicad/${OSX_BUNDLE_MAIN}" )
  575. set( OSX_BUNDLE_BUILD_BIN_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_BIN_DIR}" )
  576. set( OSX_BUNDLE_BUILD_LIB_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_LIB_DIR}" )
  577. set( OSX_BUNDLE_BUILD_KIFACE_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )
  578. set( OSX_BUNDLE_BUILD_PLUGIN_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )
  579. set( OSX_BUNDLE_INSTALL_DIR "${KICAD_BIN}/${OSX_BUNDLE_MAIN}" )
  580. set( OSX_BUNDLE_INSTALL_BIN_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_BIN_DIR}" )
  581. set( OSX_BUNDLE_INSTALL_LIB_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_LIB_DIR}" )
  582. set( OSX_BUNDLE_INSTALL_KIFACE_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )
  583. set( OSX_BUNDLE_INSTALL_PLUGIN_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )
  584. # everything provided with the application bundle goes into
  585. # KiCad.app/Contents/SharedSupport => accessible via GetDataDir()
  586. # everything else to the .dmg image
  587. set( KICAD_DATA ${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_SUP_DIR}
  588. CACHE PATH "Location of KiCad data files." FORCE )
  589. set( KICAD_LIB ${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_LIB_DIR}
  590. CACHE PATH "Location of KiCad shared objects" FORCE )
  591. set( KICAD_USER_PLUGIN ${OSX_BUNDLE_INSTALL_PLUGIN_DIR}
  592. CACHE PATH "Location of KiCad user-loaded plugins" FORCE )
  593. set( KICAD_TEMPLATE ${KICAD_DATA}/template
  594. CACHE PATH "Location of KiCad template files." FORCE )
  595. set( KICAD_PLUGINS ${KICAD_DATA}/plugins
  596. CACHE PATH "Location of KiCad plugins." FORCE )
  597. set( KICAD_DOCS doc
  598. CACHE PATH "Location of KiCad documentation files." FORCE )
  599. set( KICAD_DEMOS demos
  600. CACHE PATH "Location of KiCad demo files." FORCE )
  601. # Required to run from build folder
  602. if( PYTHON_FRAMEWORK )
  603. list(APPEND CMAKE_BUILD_RPATH ${PYTHON_FRAMEWORK} )
  604. endif()
  605. # RPATH settings for building shared libraries
  606. set( CMAKE_MACOSX_RPATH FALSE )
  607. endif()
  608. mark_as_advanced( KICAD_BIN
  609. KICAD_KIFACE
  610. KICAD_PLUGINS
  611. KICAD_USER_PLUGIN
  612. KICAD_LIB
  613. KICAD_DATA
  614. KICAD_LIBRARY_DATA
  615. KICAD_DOCS
  616. KICAD_DEMOS
  617. KICAD_TEMPLATE )
  618. include( Functions )
  619. include( ExternalProject )
  620. #================================================
  621. # Find libraries that are needed to build KiCad.
  622. #================================================
  623. include( CheckFindPackageResult )
  624. if( KICAD_BUILD_I18N )
  625. find_package( Gettext REQUIRED )
  626. endif()
  627. #
  628. # Find OpenGL library, required
  629. #
  630. if( KICAD_USE_EGL )
  631. find_package( OpenGL REQUIRED COMPONENTS OpenGL EGL )
  632. else()
  633. set( OpenGL_GL_PREFERENCE "LEGACY" ) # CMake 3.11+ setting; see 'cmake --help-policy CMP0072'
  634. find_package( OpenGL REQUIRED )
  635. endif()
  636. #
  637. # Find GLEW library, required
  638. #
  639. # The EGL canvas on GTK requires the use of a GLEW version compiled with an EGL flag.
  640. # The one built in the thirdparty directory has the flag for EGL set, so we use it unless told
  641. # otherwise. Then we search for the system GLEW version and use that instead.
  642. #
  643. if( KICAD_USE_EGL AND KICAD_USE_BUNDLED_GLEW AND UNIX AND NOT APPLE )
  644. if( OpenGL_EGL_FOUND )
  645. message( STATUS "Found OpenGL EGL library: ${OPENGL_egl_LIBRARY}" )
  646. else()
  647. message( FATAL_ERROR "OpenGL EGL library not found" )
  648. endif()
  649. # Add the custom GLEW target
  650. add_subdirectory( thirdparty/glew )
  651. # Set the standard package variables to point to our custom target to mimic the system version.
  652. set( GLEW_LIBRARIES glew )
  653. set( GLEW_FOUND TRUE )
  654. include_directories( SYSTEM $<TARGET_PROPERTY:glew,INCLUDE_DIRECTORIES> )
  655. else()
  656. find_package( GLEW REQUIRED )
  657. check_find_package_result( GLEW_FOUND "GLEW" )
  658. include_directories( SYSTEM ${GLEW_INCLUDE_DIR} )
  659. endif()
  660. #
  661. # Find GLM library, required
  662. #
  663. find_package( GLM 0.9.8 REQUIRED )
  664. add_compile_definitions( GLM_FORCE_CTOR_INIT )
  665. include_directories( SYSTEM ${GLM_INCLUDE_DIR} )
  666. #
  667. # Find zlib library, required
  668. #
  669. find_package(ZLIB REQUIRED)
  670. #
  671. # Find Zstd library, required
  672. #
  673. find_package(ZSTD REQUIRED)
  674. #
  675. # Find libcurl, required
  676. #
  677. find_package( CURL REQUIRED )
  678. #
  679. # Find Cairo library, required
  680. #
  681. find_package( Cairo 1.12 REQUIRED )
  682. include_directories( SYSTEM ${CAIRO_INCLUDE_DIR} )
  683. find_package( Pixman 0.30 REQUIRED )
  684. include_directories( SYSTEM ${PIXMAN_INCLUDE_DIR} )
  685. # Find libgit2, required
  686. find_package( libgit2 1.5 REQUIRED )
  687. # Set include directories for libgit
  688. include_directories(${LIBGIT2_INCLUDE_DIRS})
  689. #
  690. # Find Boost headers and libraries, required.
  691. set( BOOST_REQUESTED_COMPONENTS locale ) # locale is required by nanoodbc/database libraries
  692. if( KICAD_BUILD_QA_TESTS )
  693. # required by the unit test framework
  694. list( APPEND BOOST_REQUESTED_COMPONENTS unit_test_framework )
  695. endif()
  696. find_package( Boost 1.71.0 REQUIRED COMPONENTS ${BOOST_REQUESTED_COMPONENTS} )
  697. #
  698. # Libraries required for outline font support.
  699. if( MSVC )
  700. # Earlier than 2.11.1 contain a crash bug specific to MSVC built freetype
  701. set( FREETYPE_MIN_VERSION 2.11.1 )
  702. endif()
  703. find_package( Freetype ${FREETYPE_MIN_VERSION} REQUIRED )
  704. include_directories( SYSTEM ${FREETYPE_INCLUDE_DIRS} )
  705. find_package( HarfBuzz REQUIRED )
  706. include_directories( SYSTEM ${HarfBuzz_INCLUDE_DIRS} )
  707. find_package( Fontconfig REQUIRED )
  708. # Include MinGW resource compiler.
  709. include( MinGWResourceCompiler )
  710. # Find ngspice library, required for integrated circuit simulator
  711. find_package( ngspice REQUIRED )
  712. # Find OpenCascade, required for STEP plugin and tools
  713. find_package(OCC)
  714. if( NOT OCC_FOUND )
  715. MESSAGE( FATAL_ERROR "================================================================\n"
  716. " OpenCASCADE was not found!\n"
  717. "================================================================\n")
  718. endif()
  719. if( OCC_VERSION_STRING VERSION_LESS 7.5.0 )
  720. MESSAGE( FATAL_ERROR "================================================================\n"
  721. "OpenCASCADE version ${OCC_VERSION_STRING} was found.\n"
  722. " KiCad requires a minimum version of 7.5.0\n"
  723. "================================================================\n")
  724. endif()
  725. include_directories( SYSTEM ${OCC_INCLUDE_DIR} )
  726. if( KICAD_USE_CMAKE_FINDPROTOBUF )
  727. include( FindProtobuf )
  728. find_package( Protobuf REQUIRED )
  729. else()
  730. find_package( Protobuf REQUIRED CONFIG )
  731. set( Protobuf_LIBRARY "protobuf::libprotobuf" )
  732. endif()
  733. if( NOT Protobuf_PROTOC_EXECUTABLE )
  734. if( NOT KICAD_USE_CMAKE_FINDPROTOBUF)
  735. set( Protobuf_PROTOC_EXECUTABLE "protobuf::protoc" )
  736. else()
  737. MESSAGE( FATAL_ERROR "Protobuf compiler not found. Please install protobuf-compiler." )
  738. endif()
  739. endif()
  740. if( NOT Protobuf_INCLUDE_DIR )
  741. get_target_property( Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES )
  742. endif()
  743. # Assist with header file searching optimization:
  744. # INC_BEFORE and INC_AFTER are two lists which go at the front and back of the
  745. # header file search lists, respectively.
  746. # INC_BEFORE is for use with "include_directories( BEFORE ...)", which _reverses_
  747. # the order during insertion. (So put first wanted last, which is
  748. # ${CMAKE_SOURCE_DIR/include.) Use '.' for current source dir since
  749. # we don't want expansion here and now, which would happen if using ${CMAKE_CURRENT_SOURCE_DIR}.
  750. # Instead we use '.' which is applicable to any source directory below here as a result of
  751. # this lack of expansion.
  752. set( INC_BEFORE
  753. .
  754. ${CMAKE_SOURCE_DIR}/include
  755. )
  756. set( INC_AFTER
  757. ${CMAKE_BINARY_DIR}
  758. )
  759. #
  760. # Find Python and other scripting resources
  761. #
  762. # SWIG 4.0 or later require for proper C++11 support.
  763. find_package( SWIG 4.0 REQUIRED )
  764. include( ${SWIG_USE_FILE} )
  765. set( PythonInterp_FIND_VERSION 3.6 )
  766. set( PythonLibs_FIND_VERSION 3.6 )
  767. find_package( PythonInterp ${PythonInterp_FIND_VERSION} )
  768. check_find_package_result( PYTHONINTERP_FOUND "Python Interpreter" )
  769. # Get the correct Python site package install path from the Python interpreter found by
  770. # FindPythonInterp unless the user specifically defined a custom path.
  771. if( NOT PYTHON_SITE_PACKAGE_PATH )
  772. execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import sys, sysconfig
  773. if 'deb_system' in sysconfig.get_scheme_names():
  774. scheme = 'deb_system'
  775. elif sys.version_info > (3, 10):
  776. scheme = sysconfig.get_default_scheme()
  777. else:
  778. scheme = sysconfig._get_default_scheme()
  779. print(\"%s\"%sysconfig.get_path('platlib', vars={'platbase': '.'}, scheme=scheme))"
  780. OUTPUT_VARIABLE PYTHON_SITE_PACKAGE_PATH
  781. OUTPUT_STRIP_TRAILING_WHITESPACE
  782. )
  783. if( NOT PYTHON_SITE_PACKAGE_PATH )
  784. message( FATAL_ERROR "Error occurred while attempting to find the Python site library path." )
  785. endif()
  786. endif()
  787. if( APPLE )
  788. set( OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR ${OSX_BUNDLE_LIB_DIR}/Python.framework/Versions/${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
  789. set( OSX_BUNDLE_INSTALL_PYTHON_SITE_PACKAGES_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}")
  790. set( PYTHON_DEST "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}"
  791. CACHE PATH "Python module install path."
  792. )
  793. add_compile_definitions( OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR="${OSX_BUNDLE_PYTHON_SITE_PACKAGES_DIR}" )
  794. elseif( VCPKG_TOOLCHAIN )
  795. set( PYTHON_DEST "${CMAKE_INSTALL_PREFIX}/bin/Lib/site-packages"
  796. CACHE PATH "Python module install path."
  797. )
  798. else()
  799. set( PYTHON_DEST "${PYTHON_SITE_PACKAGE_PATH}"
  800. CACHE PATH "Python module install path."
  801. )
  802. if( IS_ABSOLUTE ${PYTHON_SITE_PACKAGE_PATH} )
  803. set( PYTHON_FULL_DEST "${PYTHON_SITE_PACKAGE_PATH}"
  804. CACHE PATH "Python module full install path."
  805. )
  806. else()
  807. set( PYTHON_FULL_DEST "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGE_PATH}"
  808. CACHE PATH "Python module full install path."
  809. )
  810. endif()
  811. endif()
  812. message( STATUS "Python module install path: ${PYTHON_DEST}" )
  813. find_package( PythonLibs 3.6 REQUIRED )
  814. # pybind11 is header-only, so include the subdir
  815. add_subdirectory(thirdparty/pybind11)
  816. # Make sure that we get our pybind11 and not the system pybind11 (ours is patched to work with wx)
  817. include_directories( BEFORE SYSTEM ${PYBIND11_INCLUDE_DIR} )
  818. # Infrequently needed headers go at end of search paths, append to INC_AFTER which
  819. # although is used for all components, should be a harmless hit for something like eeschema
  820. # so long as unused search paths are at the end like this.
  821. set( INC_AFTER ${INC_AFTER} ${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/scripting )
  822. if( KICAD_SCRIPTING_WXPYTHON )
  823. # Find the wxPython installation
  824. if( NOT VCPKG_TOOLCHAIN AND NOT KICAD_BUILD_ARCH_ARM64 )
  825. find_package( wxPython REQUIRED )
  826. if( WXPYTHON_VERSION VERSION_LESS 4.0.0 )
  827. message( FATAL_ERROR "wxPython Phoenix is required" )
  828. endif()
  829. if( WXPYTHON_WXVERSION VERSION_LESS 3.2.0 )
  830. message( FATAL_ERROR "wxWidgets 3.2.0 or greater is required" )
  831. endif()
  832. endif()
  833. endif()
  834. # GTK3 is required on Linux
  835. if( UNIX AND NOT APPLE AND KICAD_SCRIPTING_WXPYTHON )
  836. if( NOT "${WXPYTHON_TOOLKIT}" STREQUAL "gtk3" )
  837. message( FATAL_ERROR "GTK3-based wxPython/Phoenix toolkit is required.")
  838. endif()
  839. endif()
  840. if( WXPYTHON_FLAVOR )
  841. message( STATUS "Found wxPython ${WXPYTHON_FLAVOR} "
  842. "${WXPYTHON_VERSION}/${WXPYTHON_TOOLKIT} "
  843. "(wxWidgets ${WXPYTHON_WXVERSION})" )
  844. endif()
  845. #
  846. # Find wxWidgets library, required
  847. #
  848. # Check if '--toolkit=xxx' option has been passed
  849. string( REGEX MATCH "--toolkit=([a-zA-Z0-9]+)"
  850. WXWIDGETS_REQUESTED_TOOLKIT "${wxWidgets_CONFIG_OPTIONS}" )
  851. if( WXWIDGETS_REQUESTED_TOOLKIT
  852. AND NOT WXWIDGETS_REQUESTED_TOOLKIT STREQUAL "--toolkit=${WXPYTHON_TOOLKIT}" )
  853. message( WARNING "wxWidgets and wxPython must be based on the same toolkit.\n"
  854. "It will be fixed automatically if you skip the '--toolkit=xxx' "
  855. "wxWidgets_CONFIG_OPTIONS parameter.")
  856. elseif( UNIX AND NOT APPLE )
  857. # Force the use of GTK3 on Linux
  858. set( wxWidgets_CONFIG_OPTIONS ${wxWidgets_CONFIG_OPTIONS} "--toolkit=gtk3" )
  859. else()
  860. # Use the same toolkit as wxPython otherwise there will be a symbol conflict
  861. set( wxWidgets_CONFIG_OPTIONS ${wxWidgets_CONFIG_OPTIONS} "--toolkit=${WXPYTHON_TOOLKIT}" )
  862. endif()
  863. # Require the same wxWidgets version as is used by wxPython
  864. if( KICAD_SCRIPTING_WXPYTHON )
  865. set( wxWidgets_REQ_VERSION ${WXPYTHON_WXVERSION} )
  866. else()
  867. set( wxWidgets_REQ_VERSION 3.2.0 )
  868. endif()
  869. # See line 49 of cmake/FindwxWidgets.cmake
  870. set( wxWidgets_CONFIG_OPTIONS ${wxWidgets_CONFIG_OPTIONS} --static=no )
  871. find_package( wxWidgets ${wxWidgets_REQ_VERSION} COMPONENTS gl aui adv html core net base propgrid xml stc richtext REQUIRED )
  872. # Include wxWidgets macros.
  873. include( ${wxWidgets_USE_FILE} )
  874. # Detect wxWidgets port being used
  875. if( wxWidgets_FIND_STYLE STREQUAL "win32" )
  876. string(REGEX MATCH "^[msw|qt|gtk]*" KICAD_WX_PORT "${WX_CONFIGURATION}")
  877. if( KICAD_WX_PORT STREQUAL "qt" )
  878. add_compile_definitions( __WXQT__ )
  879. elseif( KICAD_WX_PORT STREQUAL "gtk" )
  880. add_compile_definitions( __WXGTK__ )
  881. endif()
  882. elseif( _wx_selected_config )
  883. string(REGEX MATCH "^[msw|qt|gtk|osx]*" KICAD_WX_PORT "${_wx_selected_config}")
  884. endif()
  885. if( KICAD_WX_PORT )
  886. message( STATUS "Detected wxWidgets port: ${KICAD_WX_PORT}")
  887. else()
  888. message( FATAL_ERROR "Unable to detect wxWidgets port")
  889. endif()
  890. if( NOT MSVC )
  891. if( ${wxWidgets_VERSION_STRING} VERSION_LESS 3.2 )
  892. message( FATAL_ERROR "wxWidgets 3.2.0 or greater is required" )
  893. endif()
  894. endif()
  895. if( MINGW )
  896. # This needs to be on a separate line to protect against a broken FindWxWidgets.cmake in vcpkg
  897. if( ${wxWidgets_VERSION_STRING} VERSION_LESS 3.1 )
  898. # Work around a bug in wx < 3.1 -- when wx itself is compiled with
  899. # compiler extensions enabled, it assumes these are also available for
  900. # applications.
  901. add_definitions( -U__STRICT_ANSI__ )
  902. endif()
  903. endif()
  904. if( APPLE )
  905. # Remove app bundles in ${KICAD_BIN} before installing anything new.
  906. # Must be defined before all includes so that it is executed first.
  907. install( CODE "
  908. message( STATUS \"Removing existing application bundles...\" )
  909. # Remove links to standalone apps
  910. file( REMOVE \"${KICAD_BIN}/Bitmap2Component.app\" )
  911. file( REMOVE \"${KICAD_BIN}/Eeschema.app\" )
  912. file( REMOVE \"${KICAD_BIN}/GerbView.app\" )
  913. file( REMOVE \"${KICAD_BIN}/PCB Calculator.app\" )
  914. file( REMOVE \"${KICAD_BIN}/Pcbnew.app\" )
  915. file( REMOVE \"${KICAD_BIN}/Page Layout Editor.app\" )
  916. # Remove main bundle
  917. file( REMOVE_RECURSE ${KICAD_BIN}/${OSX_BUNDLE_MAIN} )
  918. " COMPONENT Runtime
  919. )
  920. endif()
  921. if( KICAD_USE_SENTRY )
  922. set( KICAD_SENTRY_DSN "" CACHE STRING "The sentry DSN used with sentry integration" )
  923. if ( KICAD_SENTRY_DSN STREQUAL "")
  924. message( FATAL_ERROR "Sentry DSN must be configured with KICAD_USE_SENTRY" )
  925. endif()
  926. if( WIN32 )
  927. set( CRASHPAD_WER_ENABLED ON )
  928. endif()
  929. add_subdirectory( thirdparty/sentry-native )
  930. add_compile_definitions( KICAD_USE_SENTRY )
  931. endif()
  932. if( KICAD_IPC_API )
  933. find_package( nng REQUIRED )
  934. endif()
  935. #================================================
  936. # Add the doxygen target
  937. #================================================
  938. find_package( Doxygen )
  939. add_subdirectory( doxygen )
  940. # Generate config.h.
  941. configure_file( ${PROJECT_SOURCE_DIR}/cmake/config.h.cmake
  942. ${CMAKE_BINARY_DIR}/config.h )
  943. #================================================
  944. # "make uninstall" rules
  945. #================================================
  946. configure_file(
  947. "${KICAD_CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in"
  948. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  949. IMMEDIATE @ONLY )
  950. add_custom_target( uninstall
  951. "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
  952. #================================================
  953. # Installation
  954. #================================================
  955. include( CTest )
  956. enable_testing()
  957. list( APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure" )
  958. #================================================
  959. # Let CMake look in these directories for nested
  960. # 'CMakeLists.txt' files to process
  961. #================================================
  962. # Binaries ( CMake targets )
  963. add_subdirectory( api )
  964. add_subdirectory( resources )
  965. add_subdirectory( thirdparty )
  966. add_subdirectory( libs )
  967. add_subdirectory( scripting )
  968. add_subdirectory( common )
  969. add_subdirectory( 3d-viewer )
  970. add_subdirectory( eeschema )
  971. add_subdirectory( gerbview )
  972. add_subdirectory( pcbnew )
  973. add_subdirectory( pagelayout_editor )
  974. add_subdirectory( bitmap2component )
  975. add_subdirectory( pcb_calculator )
  976. add_subdirectory( plugins ) # 3D plugins must be built before kicad
  977. add_subdirectory( cvpcb ) # must be after pcbnew
  978. add_subdirectory( kicad ) # should follow pcbnew, eeschema, api
  979. add_subdirectory( tools )
  980. add_subdirectory( utils )
  981. if( KICAD_BUILD_QA_TESTS )
  982. add_subdirectory( qa )
  983. endif()
  984. # Demos
  985. if( KICAD_INSTALL_DEMOS )
  986. add_subdirectory( demos )
  987. endif ( KICAD_INSTALL_DEMOS )
  988. # I18n Translations
  989. if( KICAD_BUILD_I18N )
  990. add_subdirectory( translation )
  991. endif()
  992. if( APPLE )
  993. set( KICAD_OSX_CODESIGN ON
  994. CACHE BOOL "Sign KiCad.app on macOS" FORCE )
  995. set( KICAD_OSX_SIGNING_ID "-"
  996. CACHE STRING "macOS Signing ID, defaults to ad-hoc" FORCE )
  997. set( KICAD_OSX_SIGNING_USE_SECURE_TIMESTAMP OFF
  998. CACHE BOOL "When signing on macOS, add a secure timestamp" FORCE )
  999. set( KICAD_OSX_SIGNING_USE_HARDENED_RUNTIME OFF
  1000. CACHE BOOL "When signing on macOS, use the Hardened Runtime" FORCE )
  1001. set( KICAD_OSX_SIGNING_ENTITLEMENTS_FILE ""
  1002. CACHE FILEPATH "Path to entitlements file for macOS signing" FORCE )
  1003. # We have to sign the app bundle after *all* the files are copied in the bundle
  1004. # otherwise the signature will be invalid.
  1005. # As of CMP0082 (CMake 3.14), the install rules are run in order, so we can just
  1006. # declare it last.
  1007. add_subdirectory( signing )
  1008. endif()