title: CMake and make consecutive runs with different flags yields same output
body: <p>Consider the following simplified case:</p>
  <pre class="lang-sh prettyprint-override"><code>cmake ... -DMY_MACRO_USED_IN_CXX_CODE=1
  make my_target
  echo $(md5 my_target)
  cmake ... -DMY_MACRO_USED_IN_CXX_CODE=2
  make my_target
  echo $(md5 my_target)
  </code></pre>
  <p>I use the macro to selectively use code snippets in my c++ project.
  During multiple runs of this shell script, sometimes the md5 of <code>my_target</code> doesn't change! This happens even if I insert <code>sleep 1s</code> after each call to <code>cmake</code>. I wonder what is happening here? How do I prevent this? Other than sleep for some randomly long periods?</p>
  <p>minimal example:</p>
  <pre class="lang-sh prettyprint-override"><code># files
  main.cc
  test.sh
  CMakeLists.txt
  </code></pre>
  <pre><code># CMakeLists.txt
  cmake_minimum_required(VERSION 3.9.0)
  project(minimal-cmake-flags)
  if (NOT DEFINED MY_MACRO OR &quot;${MY_MACRO}&quot; STREQUAL &quot;&quot;)
    set(MY_MACRO 2000)
  endif()
  add_executable(main main.cc)
  target_compile_definitions(main PUBLIC
    MY_MACRO=${MY_MACRO})
  </code></pre>
  <pre class="lang-sh prettyprint-override"><code>#! /bin/bash
  function f() {
    cmake . -DMY_MACRO=$1 &amp;&gt; /dev/null
    make main &amp;&gt; /dev/null
    echo $(md5 main)
    ./main
    rm main
  }
  for i in $(seq 1 10); do
    f $i
  done
  </code></pre>
  <pre class="lang-cc prettyprint-override"><code>// main.cc
  #include &lt;iostream&gt;
  using namespace std;
  #ifndef MY_MACRO
  #define MY_MACRO (1)
  #endif
  int main() {
    cout &lt;&lt; MY_MACRO &lt;&lt; endl;
  }
  </code></pre>
  <p>Run <code>bash test.sh</code> on my machine and it prints:</p>
  <pre><code>MD5 (main) = e701db90ef8119715a918c97b56e919a
  1
  MD5 (main) = e701db90ef8119715a918c97b56e919a
  1
  MD5 (main) = 962a6a241bb4b39c0a99371ddd422eb4
  3
  MD5 (main) = 3493284e39a9d0ce3ade28201f54c32a
  4
  MD5 (main) = 82ae5011fe74d8612b996b2ba7ada13d
  5
  MD5 (main) = 938639953c59c99237110c606a543a50
  6
  MD5 (main) = 938639953c59c99237110c606a543a50
  6
  MD5 (main) = b1dddef9f2aba5680213f3e7bdce276c
  8
  MD5 (main) = b1dddef9f2aba5680213f3e7bdce276c
  8
  MD5 (main) = b88c362506aaaf6c6d74e3c734826734
  10
  </code></pre>
  <p>I added <code>sleep 5s</code> before <code>make</code> and it still happens:</p>
  <pre><code>++ md5 main
  + echo MD5 '(main)' = b1dddef9f2aba5680213f3e7bdce276c
  MD5 (main) = b1dddef9f2aba5680213f3e7bdce276c
  + ./main
  8
  + rm main
  + for i in '$(seq 1 10)'
  + f 9
  + cmake . -DMY_MACRO=9
  + sleep 5s
  + make main
  Scanning dependencies of target main
  [ 50%] Linking CXX executable main
  [100%] Built target main
  ++ md5 main
  + echo MD5 '(main)' = b1dddef9f2aba5680213f3e7bdce276c
  MD5 (main) = b1dddef9f2aba5680213f3e7bdce276c
  + ./main
  8
  </code></pre>
  <p>Update:
  I use a different <code>make</code> from homebrew and the issue is gone. So it might be a MacOS <code>make</code> issue.</p>