summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
blob: 752222db051524ec1b3fe849a48a2a49e71af007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 
# Cmake build system for muby by [email protected], 2012.
# Released under the same license as mruby.
#
# NOTE: the original Makefile build system had a few hacks in them,
# whch I didn't duplicate. In stead the build logic is like this: 
# 1) First libritevm_object is built
# 2) From this libritevm_static.a is built.
# 2) Then mrbc is built and linked with libritevm_static.a .
# 4) Then libmrblib_object is builtfrom are built from the rb files in
#    the mrblib subdirectory
# 5) Then libmrblib_object &  libritevm_object are linked together into 
#    a single library libmrubylib_static.a 
# 6) Finally, mruby is built and linked with  libmrubylib_static.a
#
# As a result, applications that embed mruby will have to link against 
# libmrubylib_static.a only..
#
# TODO: make this work on windows too, support build options to generate 
# mrbconf.h, etc...
#

# Setup
# Need at least cmake version 2.8.8
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
    cmake_policy(SET CMP0015 NEW)
endif(COMMAND cmake_policy)

# Set the project name, we use only plain C.
project(MRUBY C)

# C compiler flags.
set(CMAKE_C_FLAGS "-Wall -g")
# should use  -O3 if it's a release build.bin/mrb 


# Version of mruby, useful for versoning .so and .dll files.
set(MRUBY_VERSION 1.0.0)
string(REGEX MATCH "^[0-9]+[.][0-9]+" MRUBY_SOVERSION ${MRUBY_VERSION})
string(REPLACE "." "" MRUBY_DLL_SHORTVER ${MRUBY_SOVERSION})

# Search in the `cmake' directory for additional CMake modules if needed.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

# Search for C header files in these directories.
include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

# Search for libaries too link tools with here: 
link_directories("lib")
link_directories("mrblib")

# put binaries that get built in bin
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
# Put libraries that get built into `lib'.
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

if(NOT IPHONE)
option(SHARED "Build shared libraries" on)
set(BUILD_SHARED_LIBS ${SHARED})    # actual CMake variable
endif(NOT IPHONE)

# On some 64-bit platforms, libraries should be installed into `lib64'
# instead of `lib'.  Set this to 64 to do that.
set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'")

set(FRAMEWORK_INSTALL_PREFIX "/Library/Frameworks" CACHE STRING
    "Directory in which to install Mac OS X frameworks")

# Options (none yet).

# Set up compilers.

include(CheckCSourceCompiles)

#   Begin tests

include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(FindPkgConfig)
include(TestBigEndian)


# lib Libraries that mruby uses itself (just libm)
set(MRUBY_LIBS m)

# Compile the sources to make libritevm
add_subdirectory("src")

# compile the compiler tool
add_subdirectory("tools/mrbc")

# compile libmrblib 
add_subdirectory("mrblib")

# generate final library 
add_library(mrubylib_static STATIC 
            $<TARGET_OBJECTS:ritevm_object> $<TARGET_OBJECTS:mrblib_object>)
add_library(mrubylib SHARED 
            $<TARGET_OBJECTS:ritevm_object> $<TARGET_OBJECTS:mrblib_object>)

install(TARGETS mrubylib mrubylib_static
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

# compile the interpreter tool
add_subdirectory("tools/mruby")

# for make install, install the header files
install(FILES include/mruby.h     DESTINATION include)
install(FILES include/mrbconf.h   DESTINATION include)
install(DIRECTORY include/mruby   DESTINATION include)
# For now, also install header files in src dir to ${PREFIX}include/mruby 
file(GLOB SRC_HEADERS src/*.h)
install (FILES ${SRC_HEADERS} DESTINATION include/mruby)