Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
cmake: Add toolchain file for cross-compiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
thughes authored and ry committed Dec 23, 2010
1 parent e03fae1 commit ae8262a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Makefile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ BUILD?=build
VERBOSE?=0
PARALLEL_JOBS?=1
CMAKE?=cmake
TOOLCHAIN_FILE=#./cmake/codesourcery-arm-toolchain.cmake

all: doc package
all: package

$(BUILD)/Makefile:
mkdir $(BUILD) || exit 0
cd $(BUILD) && $(CMAKE) -DCMAKE_VERBOSE_MAKEFILE=$(VERBOSE) ..
cd $(BUILD) && $(CMAKE) -DCMAKE_VERBOSE_MAKEFILE=$(VERBOSE) -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) ..

build: $(BUILD)/Makefile
cd $(BUILD) && make -j $(PARALLEL_JOBS)
Expand Down
12 changes: 12 additions & 0 deletions README.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ To submit valgrind test results:

make -f Makefile.cmake cdash-mem

Cross-compiling:
An example toolchain file for the CodeSourcery ARM toolchain is included in
the cmake directory: codesourcery-arm-toolchain.cmake.

Install the CodeSourcery toolchain, set the path to the toolchain in
cmake/codesourcery-arm-toolchain.cmake, and uncomment the TOOLCHAIN_FILE
variable in Makefile.cmake to use it.

If you are using cmake directly, just add the flag
"-DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain-file" when
running cmake.

Using cmake directly:
cd ~/your-node-source-dir
mkdir name-of-build-dir (can be anything)
Expand Down
22 changes: 22 additions & 0 deletions cmake/codesourcery-arm-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(toolchain_dir #SET THIS TO YOUR TOOLCHAIN PATH)
set(toolchain_bin_dir ${toolchain_dir}/bin)
set(toolchain_libc_dir ${toolchain_dir}/arm-none-linux-gnueabi/libc)
set(toolchain_inc_dir ${toolchain_libc_dir}/include)
set(toolchain_lib_dir ${toolchain_libc_dir}/usr/lib)

set(CMAKE_SYSTEM_NAME Linux CACHE INTERNAL "system name")
set(CMAKE_SYSTEM_PROCESSOR arm CACHE INTERNAL "processor")
set(CMAKE_C_COMPILER ${toolchain_bin_dir}/arm-none-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${toolchain_bin_dir}/arm-none-linux-gnueabi-g++)
set(CMAKE_C_FLAGS "-isystem ${toolchain_inc_dir}" CACHE INTERNAL "c compiler flags")
set(CMAKE_CXX_FLAGS "-isystem ${toolchain_inc_dir}" CACHE INTERNAL "cxx compiler flags")

set(link_flags -L${toolchain_lib_dir})

set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared lnk flags")
set(CMAKE_FIND_ROOT_PATH ${toolchain_libc_dir} CACHE INTERNAL "cross root directory")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")
5 changes: 3 additions & 2 deletions cmake/v8_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if(NOT SHARED_V8)
set_property(TARGET v8
PROPERTY IMPORTED_LOCATION ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn})

set(compile_env_vars "CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} AR=${CMAKE_AR} RANLIB=${CMAKE_RANLIB} CFLAGS=\"${CMAKE_C_FLAGS}\" CXXFLAGS=\"${CMAKE_CXX_FLAGS}\" LDFLAGS=\"${CMAKE_EXE_LINKER_FLAGS}\"")

if(CMAKE_VERSION VERSION_GREATER 2.8 OR CMAKE_VERSION VERSION_EQUAL 2.8)
# use ExternalProject for CMake >2.8
Expand All @@ -47,7 +48,7 @@ if(NOT SHARED_V8)
URL ${PROJECT_SOURCE_DIR}/deps/v8

BUILD_IN_SOURCE True
BUILD_COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}
BUILD_COMMAND sh -c "${compile_env_vars} ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}"

SOURCE_DIR ${PROJECT_BINARY_DIR}/deps/v8
# ignore this stuff, it's not needed for building v8 but ExternalProject
Expand Down Expand Up @@ -78,7 +79,7 @@ if(NOT SHARED_V8)

add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/deps/v8/${v8_fn}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}
COMMAND sh -c "${compile_env_vars} ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/tools/scons/scons.py library=static visibility=default ${v8snapshot} mode=${v8mode} verbose=on arch=${v8arch} -j ${parallel_jobs}"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/deps/v8/
DEPENDS ${v8_sources_dest}
)
Expand Down

0 comments on commit ae8262a

Please sign in to comment.