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.

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