diff --git a/Makefile.cmake b/Makefile.cmake index aaa3f6f258..0281b413e7 100644 --- a/Makefile.cmake +++ b/Makefile.cmake @@ -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) diff --git a/README.cmake b/README.cmake index 88cd99c869..925249c8ae 100644 --- a/README.cmake +++ b/README.cmake @@ -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) diff --git a/cmake/codesourcery-arm-toolchain.cmake b/cmake/codesourcery-arm-toolchain.cmake new file mode 100644 index 0000000000..c45bce5067 --- /dev/null +++ b/cmake/codesourcery-arm-toolchain.cmake @@ -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 "") diff --git a/cmake/v8_build.cmake b/cmake/v8_build.cmake index ea27e5fd08..b35caef2e6 100644 --- a/cmake/v8_build.cmake +++ b/cmake/v8_build.cmake @@ -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 @@ -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 @@ -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} )