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.

1061 lines
38 KiB

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