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
base: master
from

Conversation

Projects
None yet
3 participants
@zhaihj
Contributor

zhaihj commented Oct 28, 2014

Add a simple cmake driver.
can be used by

rock --driver=cmake sourcefile.ooc

This works for rock's source.

zhaihj added some commits Oct 28, 2014

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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.

zhaihj added some commits Oct 28, 2014

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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.

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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.

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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.

@zhaihj zhaihj force-pushed the zhaihj:cmake_driver branch from dc9589c to 4e459ec Oct 29, 2014

@zhaihj

This comment has been minimized.

Contributor

zhaihj commented Oct 31, 2014

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

@fasterthanlime

This comment has been minimized.

style note: try to avoid braceless single-statement ifs on single lines.

Ie:

if (something) {
  somethingElse()
}

or

if (something) somethingElse()

But not:

if (something)
  somethingElse()

Mostly because it makes it easy to add more things in the if block.

This comment has been minimized.

Owner

zhaihj replied Nov 1, 2014

Thanks, I will fix it.

zhaihj added some commits Nov 1, 2014

@zhaihj

This comment has been minimized.

Contributor

zhaihj commented Nov 1, 2014

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

zhaihj added some commits Nov 1, 2014

@zhaihj

This comment has been minimized.

Owner

zhaihj commented on source/rock/frontend/drivers/CMakeDriver.ooc in 416c383 Nov 1, 2014

typo...

@zhaihj zhaihj force-pushed the zhaihj:cmake_driver branch from 7df964e to 416c383 Nov 1, 2014

@zhaihj

This comment has been minimized.

Owner

zhaihj commented on source/rock/frontend/drivers/CMakeDriver.ooc in 416c383 Nov 1, 2014

another typo

@zhaihj

This comment has been minimized.

Contributor

zhaihj commented Nov 1, 2014

Everything seems good.

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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)
@zhaihj

This comment has been minimized.

Contributor

zhaihj 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...

@zhaihj

This comment has been minimized.

Contributor

zhaihj 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

zhaihj added some commits Dec 12, 2014

@zhaihj

This comment has been minimized.

Owner

zhaihj commented on ff118b6 Dec 12, 2014

This does not really solve the problem.
According to this
http://public.kitware.com/Bug/bug_relationship_graph.php?bug_id=14736
"Automatically Select Architectures" seems a bug of cmake.

only use rdynamic for gcc
clang/tcc do not use this flag
@fasterthanlime

This comment has been minimized.

Collaborator

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