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.

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