Fix dependencies using system-default compiler.#81
Conversation
|
Might be a good idea to extend this to pass compile options as well. |
|
Hello! My initial idea was that CMAKE_TOOLCHAIN_FILE can be used to setup a custom compiler. Is it not convenient? As for only CC/CXX args, isn't it easier to set them just as environment variables before running CMake? |
| UPDATE_COMMAND "" | ||
| PATCH_COMMAND "" | ||
| CONFIGURE_COMMAND ${MESON_EXECUTABLE} setup --backend ${MESON_BACKEND} --buildtype ${MESON_BUILD_TYPE} | ||
| CONFIGURE_COMMAND env CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ${MESON_EXECUTABLE} setup --backend ${MESON_BACKEND} --buildtype ${MESON_BUILD_TYPE} |
There was a problem hiding this comment.
Env comes from CoreUtils in GnuWin32 which is supplied with several common developer packages such as Git Bash.
|
I find it slightly easier, it's how cmake-gui changes compiler and it remembers the setting across runs (unlike environment variables). But the other issue with it, is that it's a foot-gun as it is. |
|
@agruzdev , Should dependencies added using add_subdirectory/ fetch_content so they'll be part of the build tree ? |
This was my initial version. That approach is super hard to maintain. Each add_subdirectory populates own variables, they might collide between dependencies. So CMake cache very quickly becomes a huge mess. |
Fair. In that case I like the idea, consider propagating additional variables (just an example) include(ExternalProject)
set(_ep_cmake_args
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
"-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
)
if(CMAKE_BUILD_TYPE)
list(APPEND _ep_cmake_args
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
)
endif()
if(CMAKE_TOOLCHAIN_FILE)
list(APPEND _ep_cmake_args
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}"
)
endif()
if(CMAKE_MT)
list(APPEND _ep_cmake_args
"-DCMAKE_MT:FILEPATH=${CMAKE_MT}"
)
endif()
if(CMAKE_RC_COMPILER)
list(APPEND _ep_cmake_args
"-DCMAKE_RC_COMPILER:FILEPATH=${CMAKE_RC_COMPILER}"
)
endif()
ExternalProject_Add(my_external
SOURCE_DIR "${some_source_dir}"
BINARY_DIR "${CMAKE_BINARY_DIR}/_deps/my_external-build"
CMAKE_ARGS ${_ep_cmake_args}
) |
Compiler arguments need to be passed to ExternalProjects otherwise they use the system default compiler.