CMake sample project?

Hi,

I built LLVM on Windows XP through cmake and MinGW make. That was a breeze!
Now, I wanted to start a project.
It seems like I need Makefile.rules and Makefile.config to start a new project (from http://llvm.org/docs/Projects.html).

And llvm/projects/sample uses autoconf (or ./configure). Is there cmake based sample project available?
I could not find any from official release. Has any of you written sample project template that uses cmake?
I just wanted to move away from autotools.

Thanks.
Sam

sam lee <skynare@gmail.com> writes:

Hi,

I built LLVM on Windows XP through cmake and MinGW make. That was a breeze!
Now, I wanted to start a project.
It seems like I need Makefile.rules and Makefile.config to start a new
project (from http://llvm.org/docs/Projects.html).

Those files are unrelated to cmake.

And llvm/projects/sample uses autoconf (or ./configure). Is there cmake
based sample project available?
I could not find any from official release. Has any of you written sample
project template that uses cmake?

Just make a directory under LLVM_ROOT/projects and put your source
there, with a CMakeLists.txt file that contains the right directives
(you can use any of the llvm tools or libraries under LLVM_ROOT/tools or
LLVM_ROOT/lib as an example.) After creating those files, you must
re-invoke cmake for it taking notice of your new project.

Another approach is to build and install LLVM and write your project as
an standalone source tree outside LLVM's. Then link the LLVM libraries
into your executable.

[snip]

This isn’t meant to be a sample, but I can share with you the cmake files I use for my compiler. It builds in both windows user MSVC, and linux using G++, but should work with MinGW.

the structure is

src/
CMakeLists.txt # root make file
front/
CMakeLists.txt # library

middle/
CMakeLists.txt # library

back/
CMakeLists.txt # library

npp/
CMakeLists.txt # executable

src.zip (2.43 KB)

Ah, thank you so much.
How did you get the list of target_link_libraries() ?
Did you use llvm-config?
If you did not have access to llvm-config, how would you get list of libraries to link to?

Thanks.
Sam

I built the list by hand though trial and error. I’m not sure if and how llvm-config works with cmake. Its seems now that I got the right dependencies in the right order, there have been no ongoing maintenance issues.

I use llvm-config with cmake, for this I wrote a FindLLVM.cmake file [1], it
provides a FIND_LLVM_LIBS macro that calls llvm-config, example of use in [2].
Unfortunately it does not work with MSVC, so I had to hardcode the libraries
when building with MSVC.

The LLVM_NATIVE_OBJECTS part of FIND_LLVM_LIBS is probably not needed anymore,
since everything seems to be shipped as static library nowdays.

[1] http://bitbucket.org/opengtl/opengtl/src/tip/cmake/modules/FindLLVM.cmake
[2]
http://bitbucket.org/opengtl/opengtl/src/tip/OpenGTL/GTLCore/CMakeLists.txt

Ok, I created cmake sample project that can build fibonacci.cpp (from llvm/examples/Fibonacci/fibonacci.cpp).
I am linking to all libraries.
I’m on windows and I could not make llvm-config to work.

How does llvm-config work? I would like to port it to Python or Lua that works on every platform. I know it’s Perl, but somehow I could not get it to build on windows. I built it on MSYS. But, invoking it (llvm-config --libs) says: llvm-config: unknown component name: pic16codegen.
And, llvm-config --libs core only returns -lLLVMCore (it should return -lLLVMSystem and -lLLVMSupport).

And thank you for FindLLVM.cmake. When I have working llvm-config script, I’ll use it.

Thanks.
Sam

llvm-sample-project.7z (2.53 KB)

sam lee <skynare@gmail.com> writes:

Ok, I created cmake sample project that can build fibonacci.cpp (from
llvm/examples/Fibonacci/fibonacci.cpp).
I am linking to all libraries.
I'm on windows and I could not make llvm-config to work.

How does llvm-config work? I would like to port it to Python or Lua that
works on every platform.

It would be very hard to make llvm-config work for MSVC++. It should
work for mingw, though. I have no idea why it doesn't.

Anyways, instead of "fixing" llvm-config a better option is to use the
library dependency info contained on the LLVM cmake build (see
LLVM_ROOT/cmake/modules/LLVMLibDeps.cmake)

I plan to expand the cmake build for installing the required cmake files
along the rest of LLVM so the user can include them on his project's
build for obtaining library dependencies, etc. This is not hard to do,
but for the next month or two I'll be busy with other tasks.

I know it's Perl, but somehow I could not get it to
build on windows. I built it on MSYS. But, invoking it (llvm-config --libs)
says: llvm-config: unknown component name: pic16codegen.
And, llvm-config --libs core only returns -lLLVMCore (it should return
-lLLVMSystem and -lLLVMSupport).

[snip]