Skip to content

Fix dependencies using system-default compiler.#81

Open
nimble0 wants to merge 1 commit into
agruzdev:masterfrom
nimble0:fix/non-default-compiler
Open

Fix dependencies using system-default compiler.#81
nimble0 wants to merge 1 commit into
agruzdev:masterfrom
nimble0:fix/non-default-compiler

Conversation

@nimble0
Copy link
Copy Markdown
Contributor

@nimble0 nimble0 commented May 25, 2026

Compiler arguments need to be passed to ExternalProjects otherwise they use the system default compiler.

@nimble0
Copy link
Copy Markdown
Contributor Author

nimble0 commented May 25, 2026

Might be a good idea to extend this to pass compile options as well.

@agruzdev
Copy link
Copy Markdown
Owner

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}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it work on Windows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env comes from CoreUtils in GnuWin32 which is supplied with several common developer packages such as Git Bash.

@nimble0
Copy link
Copy Markdown
Contributor Author

nimble0 commented May 26, 2026

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.

@TheNicker
Copy link
Copy Markdown

TheNicker commented May 31, 2026

@agruzdev , Should dependencies added using add_subdirectory/ fetch_content so they'll be part of the build tree ?

@agruzdev
Copy link
Copy Markdown
Owner

@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.
ExternalProjects lets to build and install each dependency isolated. Much easier to debug and maintain,

@TheNicker
Copy link
Copy Markdown

TheNicker commented May 31, 2026

That approach is super hard to maintain

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}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants