How to download a toolchain for cross compilation in cmake from separate file? -


i have project cmakelists.txt files in root , project compiles fine on linux , osx. want cross compile mips openwrt. automate as possible, use following code download toolchain , set compiler variables:

externalproject_add(ar71xx-toolchain     prefix "${project_binary_dir}/external/openwrt"     url "http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uclibc-0.9.33.2.tar.bz2"     update_command ""     patch_command ""     build_command ""     configure_command ""     install_command "" ) externalproject_get_property(ar71xx-toolchain source_dir) set(cmake_c_compiler ${source_dir}/toolchain-mips_34kc_gcc-4.8-linaro_uclibc-0.9.33.2/bin/mips-openwrt-linux-gcc) set(cmake_cxx_compiler ${source_dir}/toolchain-mips_34kc_gcc-4.8-linaro_uclibc-0.9.33.2/bin/mips-openwrt-linux-g++) set(cmake_strip ${source_dir}/toolchain-mips_34kc_gcc-4.8-linaro_uclibc-0.9.33.2/bin/mips-openwrt-linux-strip) 

i thought can put in separate toolchain file , pass -dcmake_toolchain_file, seems externalproject_add not executed inside toolchain file. avoid putting toolchain download step main cmakelists.txt since it's not essential project , require doing same each target platform... there way define optional steps current cross compile build , pass somehow command line parameter executed before main project build?

update: based on tsyvarev's answer works me in toolchain file:

set(cmake_system_name linux) set(toolchain_dir ${project_binary_dir}/external/openwrt/toolchain)  if(not exists ${toolchain_dir})     file(download http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uclibc-0.9.33.2.tar.bz2 ${toolchain_dir}/toolchain.tar.bz2 show_progress)     execute_process(command tar --strip-components=2 -xjf ${toolchain_dir}/toolchain.tar.bz2 working_directory ${toolchain_dir})     execute_process(command rm ${toolchain_dir}/toolchain.tar.bz2) endif()  set(cmake_c_compiler ${toolchain_dir}/bin/mips-openwrt-linux-gcc) set(cmake_cxx_compiler ${toolchain_dir}/bin/mips-openwrt-linux-g++) set(cmake_strip ${toolchain_dir}/bin/mips-openwrt-linux-strip) set(cmake_find_root_path  ${toolchain_dir}) set(cmake_find_root_path_mode_program never) set(cmake_find_root_path_mode_library only) set(cmake_find_root_path_mode_include only) 

there 1 issue when passing -dcmake_toolchain_file cmake parameter other projects added externalproject_add. because of it's own ${project_binary_dir} download toolchain again. problem...

externalproject_add executes steps @ build time, not @ configuration time.

for download file can use file(download ...) command. extract files arhive use execute_process appropriate command.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -