Page 1 of 1

CMakes find_package() on OSX

Posted: Thu Apr 11, 2013 9:37 am
by Daniel Dekkers
Hi,

Does anyone have some positive experience with CMakes find_package() module on OSX?

On MSW, everything is fine. After building wxWidgets, I can specify the wxWidgets root directory in the CMake script:

Code: Select all

set(wxWidgets_ROOT_DIR "C:/cThrough/wxWidgets")
Followed by a call to find_package(), specifying the components I want:

Code: Select all

find_package(wxWidgets COMPONENTS core base gl adv html xml xrc aui REQUIRED)
If find_package() finds wxWidgets (which it does) then all inclusions seem to automagically be added via:

Code: Select all

include("${wxWidgets_USE_FILE}")
But on OSX, no such luck yet.

The problem is that this "wxWidgets_ROOT_DIR" variable doesn't seem to be used (I can fill in anything for it).
That would imply that i *HAVE* to "make install" wxWidgets (which I would like to avoid) because /usr/local/... is the only location find_package() knows where to look.

And even when I do perform a make install, only the libs seem to be copied, not the header files.
I can solve it by "manually" adding include paths of course, but that doesn't feel right:

Code: Select all

if(APPLE)
  include_directories("${wxWidgets_ROOT_DIR}/include") # header files
  include_directories("${wxWidgets_ROOT_DIR}/build/lib/wx/include/osx_cocoa-unicode-2.9") # for wx/setup.h, created during configuration.
endif()
I'm using the latest CMake (2.8.10.2) and the most recent wxWidgets svn revision (73807).

Thanks,
Daniel Dekkers

Re: CMakes find_package() on OSX

Posted: Thu Apr 11, 2013 2:08 pm
by eranif
Hi,

I use CMake to build codelite IDE on Linux / Mac.
To process is very simple:

In the CMakeLists.txt file I only use these lines:

Code: Select all

find_package(wxWidgets COMPONENTS ${WX_COMPONENTS} REQUIRED)
Where WX_COMPONENTS is an internal variable I use to specify which components to use

Followed by:

Code: Select all

# wxWidgets include (this will do all the magic to configure everything)
include( "${wxWidgets_USE_FILE}" )
And in the target:

Code: Select all

target_link_libraries(codelite ${wxWidgets_LIBRARIES} ... 
the environment variable wxWidgets_ROOT_DIR is not needed on Mac and Linux.
You should only make sure that your wx-config tool is in the system path.

For me, I build wxWidgets (without running 'make install') under:

Code: Select all

/Users/eran/devl/wx294/build-release/
Before running cmake, I simply type:

Code: Select all

export PATH=/Users/eran/devl/wx294/build-release/:$PATH
cmake 
make
The key thing: make sure that the correct wx-config tool is in the path
Eran

Re: CMakes find_package() on OSX

Posted: Fri Apr 12, 2013 11:43 am
by Daniel Dekkers
Hi Eran,

Thank you for your elaborate reply.

To avoid conflicts between a possibly existing installed wxWidgets (wx-config in /usr/local/...) and another one you've built in another location i'm still trying to specify the exact location of wx-config directly in the CMake script, instead of adding the location to the system path.

What I have now is this...

Code: Select all

# =======================
# === wxWidgets =========
# =======================

if(WIN32)
	# Tell find_package() where to look, via wxWidgets_ROOT_DIR…
	set(wxWidgets_ROOT_DIR "C:/cThrough/wxWidgets")
elseif(APPLE)
	set(wxWidgets_ROOT_DIR "/Users/danieldekkers/cThrough/wxWidgets")
	# Note, find_package() on OSX does not use wxWidgets_ROOT_DIR, use intermediate wx-config exe instead…
	set(wxWidgets_CONFIG_EXECUTABLE "${wxWidgets_ROOT_DIR}/build/wx-config")
endif()

find_package(wxWidgets COMPONENTS core base gl adv html xml xrc aui REQUIRED) # xrc needs adv

if(wxWidgets_FOUND)
	include("${wxWidgets_USE_FILE}")
else(wxWidgets_FOUND)
	message("wxWidgets not found!")
endif(wxWidgets_FOUND)
... which is a bit strange, because normally the wxWidgets_CONFIG_EXECUTABLE variable would be a result of find_package() and now it's an input.
But it seems to work, in the sense that the "automagicallyness" of include("${wxWidgets_USE_FILE}") works, the application compiles and links.

Thanks,
Daniel Dekkers