kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #05733
Re: [PATCH] expat dependency for cmake
On 10/15/2010 1:20 PM, Brian Sidebotham wrote:
> On 15 October 2010 16:32, Wayne Stambaugh <stambaughw@xxxxxxxxxxx> wrote:
>> On 10/15/2010 6:37 AM, Brian Sidebotham wrote:
>>>> I already had a suspicion my patch was not complete.
>>>> I was hoping to achieve that cmake does all the dependency checks and then decides if there is enough to build it or to ask for other dependencies, instead of finding out at linking-time.
>>>>
>>>>
>>>> Probably we need to do the wxWidgets check before the expat check, right?
>>>>
>>>> So the patch should to the following (?):
>>>> # only gl and mono can be detected
>>>> find_package(wxWidgets COMPONENTS mono gl REQUIRED)
>>
>> Why is the wxWidgets monolithic library being used? I can build separate
>> wxWidgets libraries on Windows using both dynamic link and static libraries on
>> both Mingw/MSYS and Visual Studio 2005 with no problems. I usually use static
>> because it make my life easier but I have successfully built Kicad both ways.
>> If you are going use the monolithic library, use a command line switch as shown
>> below.
>>
>> option(KICAD_USE_WX_MONO "Enable/disable building with wxWidgets monolithic
>> library (default OFF)")
>>
>> if(KICAD_USE_WX_MONO)
>> find_package( wxWidgets COMPONENTS mono gl REQUIRED )
>> else(KICAD_USE_WX_MONO)
>> find_package( wxWidgets COMPONENTS gl adv html core net base xml aui REQUIRED )
>> endif(KICAD_USE_WX_MONO)
>>
>> Use the -DKICAD_USE_WX_MONO=ON switch when running CMake.
>>
>>>> if(NOT WIN32)
>>>> find_package(wxWidgets COMPONENTS gl adv html core net base xml REQUIRED)
>>>> endif(NOT WIN32)
>>
>> There is no reason to use if(NOT WIN32) here. I know I've said this before and
>> I will say it again. Build tools should test for features not platforms.
>> Whenever you see WIN32, APPLE, POSIX, etc., try to replace it with a feature
>> test solution. See the "Recommendations for Writing Autoconf Macros" page of
>> http://www.lrde.epita.fr/~adl/dl/autotools.pdf for an excellent explanation of
>> why to test for features. Unfortunately the CMake folks accept and create
>> these kinds of tests.
>>
>> I know you thinking, how does that solve our expat library problem. There are
>> several ways to approach this problem but fortunately for us, the wxWidgets
>> folks have a clue and provided a wxUSE_EXPAT definition when wxWidgets is built
>> using its own internal version of expat. You should be able to use the CMake
>> CheckSymbolExists macro to check for wxUSE_EXPAT in the setup.h file for the
>> version of wxWidgets that was found. Now you know which expat library to link
>> against. Assuming that the linker paths are defined correctly, you can link to
>> the correct library. This is actually not the optimal way to do it. On
>> platforms that support wx-config, you should use it instead. So we end up with
>> something as following.
>>
>> find_program( wx-config, HAS_WX_CONFIG )
>>
>> if( NOT HAS_WX_CONFIG OR CROSS_COMPILING )
>> CheckSymbolExists( wxUSE_EXPAT path_to_correct_wx_version/setup.h
>> USE_WX_EXPAT )
>> if( USE_WX_EXPAT )
>> add_library( name_of_wx_widgets_expat_library )
>> else( USE_WX_EXPAT )
>> add_library( expat )
>> endif( USE_WX_EXPAT )
>> endif( NOT HAS_WX_CONFIG OR CROSS_COMPILING )
>
> That is a neat check for wx-config. There is already a windows port in
> existence, so no doubt one day it'll make it into the standard windows
> wxWidgets build. It's so much better than having to use a big list of
> libraries in the link command.
You have be careful using wx-config. It may not work when cross compiling
depending on the availability of a POSIX shell and the configuration of the
build environment. The other approach would be to create a small program like
the one below and compile it using the CMake CheckCSourceCompiles similar to
how autoconf would.
#include <wx/wx.h>
#if !defined( wxUSE_EXPAT )
#error "Build fails when you need to link against expat.
#endif
If the compile fails, add expat to the library list. Otherwise add the
wxWidgets expat library. This is actually the safest way. This will always
work but it introduces the overhead of compiling. This is why configure script
that autoconf generates takes so long.
Wayne
>
> Best Regards,
>
> Brian.
>
References