Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate compiler flags on first CMake invocation #323

Closed
kkaefer opened this issue Mar 13, 2017 · 5 comments
Closed

Duplicate compiler flags on first CMake invocation #323

kkaefer opened this issue Mar 13, 2017 · 5 comments
Assignees
Labels
Milestone

Comments

@kkaefer
Copy link

kkaefer commented Mar 13, 2017

I'm using NDK r14, but have observed this behavior in earlier NDKs as well: When generating the build directory with CMake, the first invocation adds the Android-specific compiler flags twice. E.g. when compiling for armeabiv7-a, I'm seeing two sets of these flags:

-g
-DANDROID
-ffunction-sections
-funwind-tables
-fstack-protector-strong
-no-canonical-prefixes
-march=armv7-a
-mfloat-abi=softfp
-mfpu=vfpv3-d16
-fno-integrated-as
-mthumb
-Wa,--noexecstack
-Wformat
-Werror=format-security
-std=c++11
-frtti
-fexceptions

While this doesn't make the build fail, a subsequent rerun of CMake (e.g. triggered by a changed CMakeLists.txt file) will rebuild the ninja file to only include one set of these flags. This will in turn trigger a full recompile of all sources, since the compile flags changed. On larger project, this is undesirable since it takes a long time.

The error happens because CMake invokes the toolchain file twice during the first build, but only once during subsequent build system rebuilds.

This can be solved by adding an include guard at the top of the toolchain file:

if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
	return()
endif(ANDROID_NDK_TOOLCHAIN_INCLUDED)
set(ANDROID_NDK_TOOLCHAIN_INCLUDED true)
@DanAlbert
Copy link
Member

Given how temperamental cmake toolchain files seem to be, I'm going to get this into r15 beta 1 to try to flush out any issues early.

@DanAlbert DanAlbert self-assigned this Mar 13, 2017
@hrydgard
Copy link

Possibly related: When a build fails with an error in Android Studio the first time after having changed CMakeLists or its parameters, it immediately starts another gradle sync and wipes out the build log from the Gradle Console window, which is pretty annoying.

@DanAlbert
Copy link
Member

Does that happen even with the snippet to fix this is added? If so it's probably something we should raise with the Studio team.

@hrydgard
Copy link

Actually, still happens with the snipped fix added, so it's an unrelated issue.

Repro:

  1. Cause a compiler error, for example insert #error hello anywhere in your C++ code
  2. build (click the hammer button). wait for it to error.
  3. Change your CMakelists.txt (say, add message("hello")
  4. build again

After step 4, gradle will immediately wipe the build log when the build error happens and start a sync, as I mentioned above, requiring another click on the build button to see the error text.

Guess I should go file that over at https://code.google.com/p/android/issues/entry?template=Tools%20bug%20report ?

@DanAlbert
Copy link
Member

@hrydgard: Yeah, they should be able to help you.

https://android-review.googlesource.com/c/353248/ to fix spurious rebuilds in r15 beta 1. Thanks for the fix, @kkaefer!

miodragdinic pushed a commit to MIPS/ndk that referenced this issue Apr 17, 2018
CMake invokes the toolchain file twice during the first build, but
only once during subsequent rebuilds. This was causing the various
flags to be added twice on the first build, and on a rebuild ninja
would see only one set of the flags and rebuild the world.

Test: ./validate.py
Bug: android/ndk#323
Change-Id: I18ceb3b785ec7aea442b2cc226b5f515282c7097
arcady-lunarg pushed a commit to KhronosGroup/glslang that referenced this issue Jul 18, 2023
Currently with the build instructions provided in README.md
the build will fail.

In the r25 NDK the CMake toolchain defaults to the legacy path,
due to a bug in the current implementation.

android/ndk#323
silverclaw pushed a commit to silverclaw/glslang that referenced this issue Aug 18, 2023
Currently with the build instructions provided in README.md
the build will fail.

In the r25 NDK the CMake toolchain defaults to the legacy path,
due to a bug in the current implementation.

android/ndk#323
kd-11 pushed a commit to kd-11/glslang that referenced this issue Dec 11, 2023
Currently with the build instructions provided in README.md
the build will fail.

In the r25 NDK the CMake toolchain defaults to the legacy path,
due to a bug in the current implementation.

android/ndk#323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants