KiCad / KicadOSXBuilder

Kicad OSX Builder, which I plan to use as my boxed development environment on Mac OSX
87 stars 27 forks source link

Build failure using Boost #14

Closed mogenson closed 10 years ago

mogenson commented 10 years ago

Building KiCAD on 64bit OS X 10.9 fails when it reaches the Boost section of Step 5. I've installed cmake, glew, and swig using homebrew.

Generating headers containing GLSL source code
Performing build step for 'boost'
Headers are up-to-date
[  1%] Built target shader_headers
[ 33%] Built target bitmaps
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/build/property.jam:290: in validate1 from module property
error: Invalid property '<cflags>': No value specified for feature 'cflags'.
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/build/property.jam:299: in property.validate from module property
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/build/build-request.jam:216: in convert-command-line-element from module build-request
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/build/build-request.jam:154: in build-request.from-command-line from module build-request
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/build-system.jam:583: in load from module build-system
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/kernel/modules.jam:289: in import from module modules
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/tools/build/v2/kernel/bootstrap.jam:139: in boost-build from module
/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost/boost-build.jam:17: in module scope from module

make[2]: *** [/Users/mike/KicadOSXBuilder-master/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost-stamp/boost-build] Error 1
make[1]: *** [CMakeFiles/boost.dir/all] Error 2
make: *** [all] Error 2
build error on BUILD KICAD  STEP: 5

Do you also provide any pre-built binaries of KiCAD for Mac OS X?

JamesHagerman commented 10 years ago

I am also getting this error when I try to use this script to build KiCad...

Edit: I am running 10.8.5...

bstegmaier75 commented 10 years ago

This seems to be a problem arising with new cmake/XCode versions. There are also other reports that the Apple compiler is no longer reported as gcc by cmake and thus a couple of variables are no longer set as before (especially the PIC stuff which seems to break boost compilation due to an emtpy/wrong declared cflags option).

I made a small patch to the KiCad cmake files (also removing manual setting of toolchain - boost seems to be smart enough to guess who is building it):

=== modified file 'CMakeLists.txt'
--- old/CMakeLists.txt  2013-11-18 16:04:23 +0000
+++ new/CMakeLists.txt  2013-11-20 23:02:26 +0000
@@ -80,7 +80,7 @@
 # Set flags for GCC.
 #================================================

-if( CMAKE_COMPILER_IS_GNUCXX )
+if( CMAKE_COMPILER_IS_GNUCXX OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") )

     execute_process( COMMAND ${CMAKE_C_COMPILER} -dumpversion
         OUTPUT_VARIABLE GCC_VERSION

=== modified file 'CMakeModules/download_boost.cmake'
--- old/CMakeModules/download_boost.cmake   2013-11-14 22:51:11 +0000
+++ new/CMakeModules/download_boost.cmake   2013-11-20 23:03:46 +0000
@@ -139,10 +139,8 @@
     BUILD_COMMAND   ./b2
                     variant=release
                     threading=multi
-                    toolset=gcc
                     ${PIC_STUFF}
                     ${b2_libs}
-                    #link=static
                     --prefix=<INSTALL_DIR>
                     install

and added it to build.sh:

bstegmaier$ git diff
diff --git a/build.sh b/build.sh
index 2d6accc..c3f7b15 100755
--- a/build.sh
+++ b/build.sh
@@ -279,6 +279,7 @@ step2()
     cd $SOURCE_DIRECTORY/$KICAD_DIRECTORY
     echo "patching kicad sources ..."
     patch -p1 -N < $PATCH_DIRECTORY/kicad_misc.patch 
+    patch -p1 < $PATCH_DIRECTORY/cmake-osx.patch 

 }

That seems to do the trick for me (at least, on original kicad-testing branch, 10.8.3, XCode 4.6.1, and cmake 2.8.12).

EDIT: Sorry, compiler recognition was wrong in first version of this post. It should be OK now - even with different versions of cmake (both "Clang" and "AppleClang" identifiers should be recognized). This change has been tested with 10.9, Xcode 5.0.2, and cmake 2.8.12 from MacPorts.

NOTE 1: boost now compiles fine on 10.9/5.0.2, but now I am running into the same problem described here: https://github.com/mangelajo/KicadOSXBuilder/issues/12

NOTE 2: Patch of download_boost.cmake was made against kicad-testing branch (in the script KICAD_BRANCH="lp:kicad"). It probably will not apply as is against other branches.

mangelajo commented 10 years ago

bstegmaier75 thank you very much for the patch, I will get it fixed KiCad upstream as soon as possible (during weekend).

Greetings, Miguel Ángel.

JamesHagerman commented 10 years ago

That patch doesn't solve the issue completely.

The output cmake spits into ./build/kicad/CMakeFiles/boost.dir/build.make from the settings in download_boost.cmake end up like the following even AFTER I applied that patch:

cd /Users/jhagerman/dev/Circuits/KicadOSXBuilder/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost && ./b2 variant=release threading=multi cflags= --prefix=/Users/jhagerman/dev/Circuits/KicadOSXBuilder/src/kicad/boost_root install

The important part of that reads like this: ./b2 variant=release threading=multi cflags= --prefix=./path_to_boost_root install

So the "cflags=" part is still going to cause the boost build to fail. The empty cflags is coming from ${PIC_STUFF} being set to ${PIC_FLAG} on line 111 in download_boost.cmake.

I'm not sure where PIC_FLAG is supposed to be set but it's not getting set correctly... And as far as I can tell, that's the real cause of this output from the original issue ticket:

error: Invalid property '': No value specified for feature 'cflags'.

Where is PIC_FLAG supposed to be set and what is it supposed to be set to?

bstegmaier75 commented 10 years ago

Corrected my comment above, but didn't try on my 10.8 machine yet (already late here).

bstegmaier75 commented 10 years ago

Just to answer the question above... yes, boost fails because PIC_FLAG is empty.

As far as I can see PIC_FLAG is set in CMakeLists.txt to "-fPIC" here:

    else()
        # We build DLL/DSOs from static libraries, so create position independent code
        # for all cases, since we do not have DLL/DSO specific static libraries.
        # Subdirectories via add_subdirectores() reference this variable, and it is either set or empty,
        # empty for Windows.
        set( PIC_FLAG -fPIC )

But, you won't reach that piece of code because from whatever combinations of Xcode/cmake on the Apple compiler isn't reported as CMAKE_COMPILER_IS_GNUCXX anylonger...

JamesHagerman commented 10 years ago

@bstegmaier75 Thanks for the description and for the patches.

Although... I'm not sure where we are supposed to actually apply the patch. The build.sh file included in this GitHub project doesn't have a section for patching KiCad. This line (for example) doesn't exist:

echo "patching kicad sources ..."

So, where is this patch applied if we don't want to do it manually?

JamesHagerman commented 10 years ago

But, other then that, I was able to manually apply the patch to CMakeLists.txt and CMakeModules/download_boost.cmake and now it's gotten past Boost...

I'll post again to see if it builds completely or if it runs into the same version incompatibility issue as @bstegmaier75.

Edit: Well, the only issue I am having at this point is that /usr/local/lib/libGLEW.dylib is compiled for x86_64 by Homebrew... and this script expects all of the libraries to be Universal (i386 and x86_64). So I'm compiling with -a x86_64 now to see if that works

Edit: That'd didn't go well either. This file was i386 only: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks//QuickTime.framework/QuickTime

So, now I've gone out and compiled libGLEW for both architectures and am now trying the i386 version again...

bstegmaier75 commented 10 years ago

@JamesHagerman: Yes, you are right... I wasn't aware that different build.sh are existing... I took https://github.com/orsonmmz/KicadOSXBuilder.git as mentioned here http://www.ohwr.org/documents/293 as a basis. However, adding this patch like done in this version is the only "automatic" version I can imagine (and it's just a one-liner).

@mangelajo: I'm not sure if this patch should go to KiCad upstream as it is - even if it does it's job. It treats Gcc and (Apple)Clang compilers just the same (probably as it was before), but the split in cmake was done due to some reasons. For instance I read that versioning ist not equal between gcc/clang, so the parts in this if-block doing some magic -O1/-O2 workarounds depending on gcc version probably won't fit (but probably also didn't fit before). Maybe it would be a better idea to duplicate the most important (Apple only) things into it's own if/else section and maintain it there.

raider444 commented 10 years ago

I applied patch, and then I got another error:


In file included from /Users/raider/Downloads/KicadOSXBuilder/output/include/wx-2.9/wx/artprov.h:15:
In file included from /Users/raider/Downloads/KicadOSXBuilder/output/include/wx-2.9/wx/string.h:51:
/Users/raider/Downloads/KicadOSXBuilder/output/include/wx-2.9/wx/strvararg.h:31:18: fatal error:
      'tr1/type_traits' file not found
        #include 

cmake version 2.8.12 OS X 10.9 Xcode 5.0.2 (5A3005)

bstegmaier75 commented 10 years ago

Yes, see my previous posts.

I am also running into this problem with my patch on 10.9 (but others with <10.9 obviously not), but I am quite sure that this is a different issue (already reported as #12). Maybe also related to probably wrong build settings due to the compiler not being recognized as gcc as before or just a general change in compiler behaviour. There are various similar reports with missing tr1 stuff when compiling other applications with MacPorts/Homebrew on 10.9. I will try some of the proposed solutions I found this evening.

bstegmaier75 commented 10 years ago

Good news... fix for #12 seems to be quite straightforward, see that issue for some explanations. The linker on 10.9 didn't like the --no-undefined flag defined for GCC, so I did split the configuration into a separate block for Clang compilers (just copy/paste... could be done more elegant probably with a common section for both compilers) and also added the fix for #12. With that, I don't have problems compiling on 10.9, Xcode 5.0.2, cmake 2.8.12, dependencies installed using MacPorts, and building only for x86_64.

build.sh has to be modified as shown above, the new cmake-osx.patch is as follows:

bstegmaier$ cat patches/cmake-osx.patch 
=== modified file 'CMakeLists.txt'
--- old/CMakeLists.txt  2013-11-18 16:04:23 +0000
+++ new/CMakeLists.txt  2013-11-21 20:01:31 +0000
@@ -159,7 +159,35 @@
         set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs" )
     endif()

-endif( CMAKE_COMPILER_IS_GNUCXX )
+elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang" )
+
+    # Establish -Wall early, so specialized relaxations of this may come
+    # subsequently on the command line, such as in pcbnew/github/CMakeLists.txt
+    set( CMAKE_C_FLAGS   "-Wall ${CMAKE_C_FLAGS}" )
+    set( CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}" )
+
+   set( CMAKE_C_FLAGS_RELEASE   "-O2" )
+    set( CMAKE_CXX_FLAGS_RELEASE "-O2" )
+
+    set( CMAKE_C_FLAGS_DEBUG   "-g3 -ggdb3 -DDEBUG" )
+    set( CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3 -DDEBUG" )
+
+    set( CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG" )
+    set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG" )
+
+    # We build DLL/DSOs from static libraries, so create position independent code
+    # for all cases, since we do not have DLL/DSO specific static libraries.
+    # Subdirectories via add_subdirectores() reference this variable, and it is either set or empty,
+    # empty for Windows.
+    set( PIC_FLAG -fPIC )
+
+    set( CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} ${PIC_FLAG}" )
+    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PIC_FLAG}" )
+    
+    # enforce libstdc++ on 10.9
+    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++" )    
+
+endif()

 if( KICAD_KEEPCASE )
     add_definitions( -DKICAD_KEEPCASE )

=== modified file 'CMakeModules/download_boost.cmake'
--- old/CMakeModules/download_boost.cmake   2013-11-14 22:51:11 +0000
+++ new/CMakeModules/download_boost.cmake   2013-11-21 20:01:31 +0000
@@ -139,10 +139,8 @@
     BUILD_COMMAND   ./b2
                     variant=release
                     threading=multi
-                    toolset=gcc
                     ${PIC_STUFF}
                     ${b2_libs}
-                    #link=static
                     --prefix=<INSTALL_DIR>
                     install
JamesHagerman commented 10 years ago

Sweet! That solved part of my issue too! Thank you so much!

Although, I still had to compile as i386 because of a QT library being non-universal... But I'll try again and see if this patch fixed that too (somehow).

Edit: This fix worked!! Sweet! Now I've got a working Universal binary of KiCad!

I'm going to try and get the binary host on the KiCad site so we don't have to always compile it ourselves...

raider444 commented 10 years ago

Now I have error:


...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc/release/link-static/threading-multi/pthread/once.o...
gcc.compile.c++ bin.v2/libs/thread/build/gcc/release/link-static/threading-multi/future.o
/bin/sh: line 1: -ftemplate-depth-128: command not found
      -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic -Wextra -Wno-long-long -Wno-variadic-macros -Wunused-function -pedantic -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_THREAD_POSIX -DNDEBUG  -I"." -c -o "bin.v2/libs/thread/build/gcc/release/link-static/threading-multi/future.o" "libs/thread/src/future.cpp"
...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc/release/link-static/threading-multi/future.o...
...skipped libboost_thread.a(clean) for lack of pthread/thread.o...
...skipped libboost_thread.a for lack of pthread/thread.o...
...skipped 

libboost_thread.a for lack of libboost_thread.a... ...failed updating 92 targets... ...skipped 35 targets... make[2]: *** [/Users/raider/Downloads/KicadOSXBuilder/src/kicad/.downloads-by-cmake/boost_1_54_0/src/boost-stamp/boost-build] Error 1 make[1]: *** [CMakeFiles/boost.dir/all] Error 2 make: *** [all] Error 2 build error on BUILD KICAD STEP: 5

UPD Sorry it was my mistake. I applied new patch above previous patch. Now solved. Thanks!

bstegmaier75 commented 10 years ago

I have seen this problem also once patching around various things. It seems as if the compile-command is executed without a correct compiler command at the beginning and the first parameter is treated as compiler command (which can't be found).

Please check in this state if the cmake-osx.patch applied cleanly (no .rej files somewhere in the src/kicad folder). I can't remember exactly but I think this problem happened to me when this patch didn't apply (because I tried to apply it to a different KiCad branch).

Probably first try starting from a clean state (delete all src, build, etc. folders) and make sure that in the build.sh really the original kicad-testing branch is used (the script I started from used a fork of the CERN guys as default). If you want to use another branch you might have to redo this patch (I didn't investigate further but in my case it seems as if the patch didn't apply because of different time-stamps (?) although the content around the patched lines is the same and patch normally should be smart enough to get this sorted out on its own).

raider444 commented 10 years ago

Thanks, I've already solved my problem. I've applied new patch above previous patch.

exitrip commented 10 years ago

Thanks! Patch works for me on OSX10.8.5, macports, newest xcode, x86_64, and lp:~cern-kicad/kicad/ratsnest

mangelajo commented 10 years ago

Good work! :+1