Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 110 lines (93 sloc) 4.123 kb
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
1 # CMake build system for mruby
2 # License: released under the same license as mruby
3 # Author: jonforums@gmail.com
4 # Author: beoran@gmail.com
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
5 #
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
6 # Usage example:
7 # 1. Ensure CMake, Bison, and a build toolchain are on `PATH`
8 # 2. Change to a build directory outside source tree, eg - `build` subdir
9 # 3. Create build Makefiles or project files.
10 # `cmake ..` (UNIX-like system)
11 # `cmake -G "MSYS Makefiles" ..`
12 # `cmake -G "Visual Studio 10" ..`
13 # `cmake -G "NMake Makefiles" ..`
14 # ** to cross-compile: add -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/file
15 # ** to set install dir: add -DCMAKE_INSTALL_PREFIX=/path/to/installdir
16 # 4a. Build: `make` (to make noisy, add `VERBOSE=1`)
17 # 4b. Build and test: `make all test`
18 # 4c. Build, test, and install: `make all test install`
19 # 4d. Build, test, and package: `make all test package`
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
20
21 cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
22
23 # Default build mode is Release With Debug Info unless specified
24 if(NOT CMAKE_BUILD_TYPE)
25 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
26 "Choose build type: empty Debug Release RelWithDebInfo MinSizeRel"
27 FORCE)
28 message(STATUS "Build type not set, defaulting to 'RelWithDebInfo'")
29 endif()
30
31 project(mruby C)
32
33 # TODO stop polluting source tree with CMakeFiles/ and CMakeCache.txt
34 # on build location check failure
35 # Make sure we are not trying to generate in in-tree build unless building
a334cdc @jonforums Update CMake to enable normal Xcode workflows
jonforums authored
36 # with an MSVC or Xcode IDE where it's OK.
37 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT (MSVC_IDE OR XCODE))
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
38 message(FATAL_ERROR
39 "\nIn-source builds are not allowed as CMake would overwrite the "
40 "Makefiles distributed with mruby. Please change to the 'build' "
41 "subdirectory and run CMake from there.")
42 endif()
43
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
44 if(COMMAND cmake_policy)
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
45 cmake_policy(SET CMP0003 NEW) # don't split absolute link paths
46 cmake_policy(SET CMP0012 NEW) # recognize number & boolean literals
47 cmake_policy(SET CMP0015 NEW) # convert relative link paths to absolute
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
48 endif(COMMAND cmake_policy)
49
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
50 # Match original Makefile's default in-tree install.
51 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
52 set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH
53 "Install path prefix prepended to install directories."
54 FORCE
55 )
56 endif()
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
57
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
58 # TODO refactor to use an option when adding shared lib support
59 set(BUILD_SHARED_LIBS OFF)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
60
61 # Version of mruby, useful for versoning .so and .dll files.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
62 # TODO automate by parsing src/version.h -or- extract git info?
63 set(MRUBY_VERSION 1.0.0dev)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
64 string(REGEX MATCH "^[0-9]+[.][0-9]+" MRUBY_SOVERSION ${MRUBY_VERSION})
65 string(REPLACE "." "" MRUBY_DLL_SHORTVER ${MRUBY_SOVERSION})
66
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
67 # Search in the `cmake` directory for custom CMake helper modules.
68 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
69 include(IntrospectSystem)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
70
71 # Search for C header files in these directories.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
72 include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/src")
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
73
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
74 # TODO re-enable (and implement) if needed
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
75 # On some 64-bit platforms, libraries should be installed into `lib64'
76 # instead of `lib'. Set this to 64 to do that.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
77 #set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'")
78
79 # build the components
80 add_subdirectory(src)
81 add_subdirectory(mrblib)
82 add_subdirectory(tools)
83 add_subdirectory(test)
84
85 # install the header files
86 install(FILES include/mruby.h DESTINATION include)
87 install(FILES include/mrbconf.h DESTINATION include)
88 install(DIRECTORY include/mruby DESTINATION include FILES_MATCHING PATTERN "*.h")
89
90 # TODO refactor once proper versioning scheme implemented
91 # archive packaging
92 set(CPACK_GENERATOR "TGZ;ZIP")
93 string(TOLOWER ${CMAKE_SYSTEM_NAME} MRUBY_HOST)
94 if(CMAKE_C_COMPILER_VERSION)
95 string(REPLACE "." "" MRUBY_GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
96 endif()
97
98 # TODO add build info suffix for non-Windows builds?
99 if(MINGW)
100 set(MRUBY_BUILD "-mingw${MRUBY_GCC_VERSION}")
101 elseif(MSVC)
102 set(MRUBY_BUILD "-msvc${MSVC_VERSION}")
103 endif()
104 set(CPACK_PACKAGE_FILE_NAME
105 "${CMAKE_PROJECT_NAME}-${MRUBY_VERSION}-${MRUBY_HOST}${MRUBY_BUILD}"
106 )
107 include(CPack)
108
109 # vim: ts=2 sts=2 sw=2 et
Something went wrong with that request. Please try again.