Reputation: 123
I have read the answers in the questions:
But I still don't understand the proper solution for cmake. The answer in (2) works only with Ninja, not cmake. The answer in (1) concerns the basic concept without example. So for me, as a beginner in cmake, the solution using process_execute() is unclear in the terms of implementation.
Is it possible to create a top-level CMakeLists.txt with process_execute(), which can be used in the follow way:
cmake
command in shell.make
command after cmake
command for the project build.What is the simple scheme of a such solution in this case?
ADDITION
My project consists from libA and libB. The libA is а backend, which emits code. The libB is a runtime support library for emitted code. I want to build the whole project by a standard "single" build command (cmake && make && make install). Of course the cmake command inlcudes parameters.
The libA may emits code for some processors. The libA may works in a cross mode. The libB is used for linking with emitted code. That is why the libB as a runtime library must be compiled in native mode.
When the libA is building in cross mode the build process must uses a one compiler for the libA, and a second compiler for the libB. In my opinion the splitting of the build process into two separated commands ("cmake1 && make1" for libA and "cmake2 && make2" for libB) is a "logical" error.
Also it is useful if the single build command may builds a multiple number of version libB for different processors.
ADDITION2
possible solution: using add_subdirectory()
Upvotes: 0
Views: 761
Reputation: 123
The idea of a simplest solution for me via my current cmake user level. (Based on The canonical way ...)
libb.cmake:
set(CMAKE_C_COMPILER ${CC_ARCH})
add_library(libb_${X_ARCH} static ${libb_SOURCE})
targets/x86_64/CMakeLists.txt:
inlcude(../../libb.cmake)
targets/mips64el/CMakeLists.txt:
inlcude(../../libb.cmake)
CMakeLists.txt
...
foreach ( X_ARCH IN LISTS ARCHS_TO_BUILD)
set(CC_ARCH ...)
add_subdirectory(targets/${X_ARCH})
endforeach()
So a follow build command causes the using different compilers at a one build. (The specification of (cross-)compilers is taking out of context.) The using a multiple number of compilers becomes possible by add_subdirectory().
$ cmake -DARCHS_TO_BUILD="x86_64;mips64el" && make
File 'libb.cmake' works as the macro definition and files 'targets/*/CMakeLists.txt' work as the instance of definitions.
Upvotes: 0
Reputation: 11
since CMAKE_<LANG>_COMPILER is singleton variable for each lang, we can never assign different compilers to targets with same language in "One CMake Progress". Thus the cmake is nearly no more than a script launcher.
But there is a little things cmake can do. cmake is also a build-system based on dependencies. so you may achieve what you want by declare custom_target, see add_custom_target. which i thought is better than output-insensitive process_execute。
Upvotes: 1