From ea4bec99d059071850715b39d837edc0541125ee Mon Sep 17 00:00:00 2001 From: Marco Serantoni Date: Mon, 30 Dec 2013 01:27:03 +0100 Subject: [PATCH] [MacOSX]/All purpose - Support for static linking --- CMakeLists.txt | 42 +++++++++++++++++++++++++++++-- CMakeModules/download_cairo.cmake | 7 +++++- cvpcb/CMakeLists.txt | 1 + pcbnew/CMakeLists.txt | 4 ++- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0473081e3..cb7fc24c38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,10 @@ option( KICAD_SCRIPTING_WXPYTHON "set this option ON to build wxpython implementation for wx interface building in python and py.shell" ) +option( KICAD_BUILD_STATIC + "Builds Kicad and all libraries static (except wx-widgets)" + ) + # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled: # PYTHON_EXECUTABLE can be defined when invoking cmake # ( use -DPYTHON_EXECUTABLE=/python.exe or python2 ) @@ -156,7 +160,12 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) if( GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs" ) endif() - + + if( APPLE ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__ASSERTMACROS__" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__ASSERTMACROS__" ) + endif() + endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") if( KICAD_KEEPCASE ) @@ -242,6 +251,19 @@ include( Functions ) include( ExternalProject ) +if ( APPLE ) + set( KICAD_BUILD_STATIC ON) + + if( NOT CMAKE_CXX_COMPILER ) + EXEC_PROGRAM( wx-config ARGS --cc OUTPUT_VARIABLE CMAKE_C_COMPILER ) + endif( NOT CMAKE_CXX_COMPILER ) + + if( NOT CMAKE_CXX_COMPILER ) + EXEC_PROGRAM( wx-config ARGS --cxx OUTPUT_VARIABLE CMAKE_CXX_COMPILER ) + endif( NOT CMAKE_CXX_COMPILER ) + +endif( APPLE ) + #================================================ # Find libraries that are needed to build KiCad. #================================================ @@ -256,6 +278,23 @@ add_definitions(-DWX_COMPATIBILITY) find_package( OpenGL QUIET ) check_find_package_result( OPENGL_FOUND "OpenGL" ) +if ( KICAD_BUILD_STATIC ) + + #set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib;.dll") + + include( download_pkgconfig ) + set( PKG_CONFIG_EXECUTABLE "${PKGCONFIG_ROOT}/bin/pkg-config") + include( download_glew ) + set( GLEW_GLEW_LIBRARY "${GLEW_ROOT}/lib/libGLEW.a") + set( GLEW_INCLUDE_DIR "${GLEW_ROOT}/include") + include( download_pixman ) + set( PIXMAN_LIBRARY "${PIXMAN_ROOT}/lib/libpixman-1.a") + include( download_libpng ) + include( download_cairo ) + set( CAIRO_INCLUDE_DIR "${CAIRO_ROOT}/include/cairo") + set( CAIRO_LIBRARY "${CAIRO_ROOT}/lib/libcairo.a") +endif( KICAD_BUILD_STATIC ) + ##################### # Find GLEW library # ##################### @@ -272,7 +311,6 @@ check_find_package_result(CAIRO_FOUND "Cairo") ################################################# include( download_boost ) - ########################## # Find wxWidgets library # ########################## diff --git a/CMakeModules/download_cairo.cmake b/CMakeModules/download_cairo.cmake index c8c6fa7db5..7720428d2d 100644 --- a/CMakeModules/download_cairo.cmake +++ b/CMakeModules/download_cairo.cmake @@ -39,10 +39,15 @@ set( PREFIX ${DOWNLOAD_DIR}/cairo ) if (APPLE) if( CMAKE_OSX_ARCHITECTURES ) - set( CAIRO_CFLAGS "CFLAGS=-arch ${CMAKE_OSX_ARCHITECTURES} -isysroot ${CMAKE_OSX_SYSROOT} -fno-lto" ) + set( CAIRO_CFLAGS "CFLAGS=-arch ${CMAKE_OSX_ARCHITECTURES} -fno-lto" ) set( CAIRO_LDFLAGS "LDFLAGS=-arch ${CMAKE_OSX_ARCHITECTURES} -framework CoreGraphics -framework CoreServices" ) set( CAIRO_OPTS "--enable-quartz-image" ) endif( CMAKE_OSX_ARCHITECTURES ) + + if( CMAKE_OSX_SYSROOT ) + set( CAIRO_CFLAGS "${CAIRO_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}") + endif( CMAKE_OSX_SYSROOT) + endif(APPLE) # = ${PREFIX}/src/glew diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 8498688eaf..53f39ada5e 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -107,6 +107,7 @@ target_link_libraries( cvpcb ${GDI_PLUS_LIBRARIES} ${GLEW_LIBRARIES} ${CAIRO_LIBRARIES} + ${PIXMAN_LIBRARY} ) # Only for win32 cross compilation using MXE diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 24c30ccea8..575cc744bf 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -367,7 +367,7 @@ if( KICAD_SCRIPTING_MODULES ) 3d-viewer pcbcommon pnsrouter - common + c${ommon pcad2kicadpcb lib_dxf ${GITHUB_PLUGIN_LIBRARIES} @@ -376,6 +376,7 @@ if( KICAD_SCRIPTING_MODULES ) gal ${GLEW_LIBRARIES} ${CAIRO_LIBRARIES} + ${PIXMAN_LIBRARY} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} ${GDI_PLUS_LIBRARIES} @@ -553,6 +554,7 @@ target_link_libraries( pcbnew ${PCBNEW_EXTRA_LIBS} ${GLEW_LIBRARIES} ${CAIRO_LIBRARIES} + ${PIXMAN_LIBRARY} ${Boost_LIBRARIES} # must follow GITHUB )