Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmake driver #847

Closed
wants to merge 28 commits into from
Closed

Add cmake driver #847

wants to merge 28 commits into from

Conversation

horasal
Copy link
Contributor

@horasal horasal commented Oct 28, 2014

Add a simple cmake driver.
can be used by

rock --driver=cmake sourcefile.ooc

This works for rock's source.

@horasal
Copy link
Contributor Author

@horasal horasal commented Oct 28, 2014

I found that sometimes Driver won't copy some c source files.
Both make and cmake drivers fail because of this but direct compilation works.

For example:

Name: foo
Description: fooooo
SourcePath: source
Requires: sdl2, stb-image, stb-vorbis

and source file:

use foo
// then do something with stb image/vorbis

compiling this with rock -vv will show that:

CMake driver
Copying /home/housezet/complier/official/rock/sdk/lang/Array.h to build/rock_tmp/ooc/sdk/Array.h
Copying /home/housezet/.ooc_libs/ooc-stb-image/source/stb/stb_image.h to build/rock_tmp/ooc/stb-image/stb_image.h
Copying /home/housezet/.ooc_libs/ooc-stb-image/source/stb/stb_image.c to build/rock_tmp/stb-image/source/stb/stb_image.c
Writing to build/CMakeLists.txt

It shows that the c sources of stb-vorbis is not copied.

CMake Error at CMakeLists.txt:76 (add_executable):
  Cannot find source file:

    rock_tmp/stb-vorbis/source/stb/stb_vorbis.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

Make driver also fails on this.

@horasal
Copy link
Contributor Author

@horasal horasal commented Oct 28, 2014

Some changes to front/CommandLine

CMake needs a project name but current dummy module does not have a name (it is set to "" explicitly)
The last commit make it comes with name same as use-file.
Now cmake driver can compile use file to library.

@horasal
Copy link
Contributor Author

@horasal horasal commented Oct 29, 2014

Fix the problem that rock does not copy c sources in uses' requirement

When we directly compile *.use file(which usually means compile to library), requirement is not properly added to dummy module. This commit fixes it.

@horasal
Copy link
Contributor Author

@horasal horasal commented Oct 29, 2014

I found that MakeDriver do not have the ability of compiling to library. When we compiling a use file without main, it still tries to generate executable. And also there's no option for generate static/shared library. ( May be I missed something? )
The following patch make driver add extensions for library, use gcc -shared or ar to generate library when module is dummy.

@horasal
Copy link
Contributor Author

@horasal horasal commented Oct 31, 2014

Commit horasal@ff24719 does not really work...
I'm considering revert it

@horasal
Copy link
Contributor Author

@horasal horasal commented Nov 1, 2014

Revert horasal@ff24719 and fix the problem.
It seems the reason is that related libraries in UseDef requirements are not collected.

@horasal
Copy link
Contributor Author

@horasal horasal commented Nov 1, 2014

Everything seems good.

@horasal
Copy link
Contributor Author

@horasal horasal commented Nov 1, 2014

CMakeDriver updated

Sometimes some flags may not work.
Such as the "-m32" flag on compitur without gcc-multilib
We should check if they are usable before adding them to C_FLAGS
Current this check is only performed on embedded flags, for extern flag, I think it is user or pkg-config's work.

This may be related to: #758

For example, now make file will check -m flag:

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    SET(CMAKE_DET_ARCH_FLAG "-m64")
else()
    SET(CMAKE_DET_ARCH_FLAG "-m32")
endif()
IF(NOT "${CMAKE_DET_ARCH_FLAG}" MATCHES "-m64")
    message(WARNING "You have arch ${CMAKE_DET_ARCH_FLAG} but -m64 is used.")
ENDIF(NOT "${CMAKE_DET_ARCH_FLAG}" MATCHES "-m64")
check_c_compiler_flag(-m64 FLAG_m64)
if(FLAG_m64)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
endif(FLAG_m64)

@horasal
Copy link
Contributor Author

@horasal horasal commented Nov 11, 2014

Flag check is fragile. When using -m32 on x86-64 machines, cmake fails to check all flags after -m32.

And also, I'm trying building rock with tcc, but it always fails without any error message...

@horasal
Copy link
Contributor Author

@horasal horasal commented Dec 12, 2014

Todo:
MSVC does not work ( because it does not even support search path like /usr/local/include
libGC can not be detected with cmake-gui for windows (works under mingw/msys though)
Arch check is fragile
Remove arch flag for xcode
-pg flag should also be used for link

clang/tcc do not use this flag
@fasterthanlime
Copy link
Collaborator

@fasterthanlime fasterthanlime commented Jul 9, 2015

@zhaihj I merged your work so far. Seems to work to build rock indeed! Haven't tried other, more convoluted projects.

The reason I was prudent approaching a CMake driver is that I didn't want it to be "dumb" — ie. directly copying include paths & lib paths to the CMakeLists.txt would've been bad. I see you're using FindPkgConfig, which takes care of that, so, good!

I'm sure we'll run into other problems in the future, but for now I think this version is a good start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants