Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 111 lines (94 sloc) 4.232 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 "
84207b2 @jonforums Update in-source build error message
jonforums authored
40 "Makefiles distributed with mruby. Delete any created 'CMakeFiles' "
41 "subdirectory and 'CMakeCache.txt' file from the current directory, "
42 "change to the 'build' subdirectory, and re-run CMake from there.")
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
43 endif()
44
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
45 if(COMMAND cmake_policy)
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
46 cmake_policy(SET CMP0003 NEW) # don't split absolute link paths
47 cmake_policy(SET CMP0012 NEW) # recognize number & boolean literals
48 cmake_policy(SET CMP0015 NEW) # convert relative link paths to absolute
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
49 endif(COMMAND cmake_policy)
50
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
51 # Match original Makefile's default in-tree install.
52 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
53 set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH
54 "Install path prefix prepended to install directories."
55 FORCE
56 )
57 endif()
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
58
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
59 # TODO refactor to use an option when adding shared lib support
60 set(BUILD_SHARED_LIBS OFF)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
61
62 # Version of mruby, useful for versoning .so and .dll files.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
63 # TODO automate by parsing src/version.h -or- extract git info?
64 set(MRUBY_VERSION 1.0.0dev)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
65 string(REGEX MATCH "^[0-9]+[.][0-9]+" MRUBY_SOVERSION ${MRUBY_VERSION})
66 string(REPLACE "." "" MRUBY_DLL_SHORTVER ${MRUBY_SOVERSION})
67
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
68 # Search in the `cmake` directory for custom CMake helper modules.
69 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
70 include(IntrospectSystem)
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
71
72 # Search for C header files in these directories.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
73 include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/src")
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
74
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
75 # TODO re-enable (and implement) if needed
b5dcb71 First cmake build system. Works on Linux.
Beoran authored
76 # On some 64-bit platforms, libraries should be installed into `lib64'
77 # instead of `lib'. Set this to 64 to do that.
9f89da6 @jonforums Add native and cross compiling CMake build support
jonforums authored
78 #set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'")
79
80 # build the components
81 add_subdirectory(src)
82 add_subdirectory(mrblib)
83 add_subdirectory(tools)
84 add_subdirectory(test)
85
86 # install the header files
87 install(FILES include/mruby.h DESTINATION include)
88 install(FILES include/mrbconf.h DESTINATION include)
89 install(DIRECTORY include/mruby DESTINATION include FILES_MATCHING PATTERN "*.h")
90
91 # TODO refactor once proper versioning scheme implemented
92 # archive packaging
93 set(CPACK_GENERATOR "TGZ;ZIP")
94 string(TOLOWER ${CMAKE_SYSTEM_NAME} MRUBY_HOST)
95 if(CMAKE_C_COMPILER_VERSION)
96 string(REPLACE "." "" MRUBY_GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
97 endif()
98
99 # TODO add build info suffix for non-Windows builds?
100 if(MINGW)
101 set(MRUBY_BUILD "-mingw${MRUBY_GCC_VERSION}")
102 elseif(MSVC)
103 set(MRUBY_BUILD "-msvc${MSVC_VERSION}")
104 endif()
105 set(CPACK_PACKAGE_FILE_NAME
106 "${CMAKE_PROJECT_NAME}-${MRUBY_VERSION}-${MRUBY_HOST}${MRUBY_BUILD}"
107 )
108 include(CPack)
109
110 # vim: ts=2 sts=2 sw=2 et
Something went wrong with that request. Please try again.