title: CMake create and link 32bit and 64bit versions of library
body: <p>I am trying to compile the following code twice, once with <code>-m32</code> and once without:</p>
  
  <pre><code>// File mylib.cc
  
  #include &lt;iostream&gt;
  
  void print_int_size() {
    std::cout &lt;&lt; sizeof(int*) &lt;&lt; std::endl;
  }
  
  
  // File main.cc
  
  void print_int_size();
  
  int main() {
    print_int_size();
    return 0;
  }
  </code></pre>
  
  <p>I have the following in my CMakeLists.txt:</p>
  
  <pre><code>project (Link32b VERSION 0.91 LANGUAGES CXX)
  
  
  add_library ( mylib STATIC mylib.cc )
  add_library ( mylib_32b STATIC mylib.cc )
  
  target_compile_options ( mylib_32b PUBLIC -m32 )
  
  add_executable ( main main.cc )
  add_executable ( main_32b main.cc )
  
  target_compile_options ( main_32b PRIVATE -m32 )
  
  target_link_libraries ( main PRIVATE mylib )
  target_link_libraries ( main_32b PRIVATE mylib_32b )
  </code></pre>
  
  <p>I get the following output when compiling (similar with gcc):</p>
  
  <pre><code>Scanning dependencies of target mylib
  [ 12%] Building CXX object CMakeFiles/mylib.dir/mylib.cc.o
  [ 25%] Linking CXX static library libmylib.a
  [ 25%] Built target mylib
  Scanning dependencies of target main
  [ 37%] Building CXX object CMakeFiles/main.dir/main.cc.o
  [ 50%] Linking CXX executable main
  [ 50%] Built target main
  Scanning dependencies of target mylib_32b
  [ 62%] Building CXX object CMakeFiles/mylib_32b.dir/mylib.cc.o
  [ 75%] Linking CXX static library libmylib_32b.a
  [ 75%] Built target mylib_32b
  Scanning dependencies of target main_32b
  [ 87%] Building CXX object CMakeFiles/main_32b.dir/main.cc.o
  [100%] Linking CXX executable main_32b
  ld: warning: ignoring file CMakeFiles/main_32b.dir/main.cc.o, file was built for i386 which is not the architecture being linked (x86_64): CMakeFiles/main_32b.dir/main.cc.o
  ld: warning: ignoring file libmylib_32b.a, file was built for archive which is not the architecture being linked (x86_64): libmylib_32b.a
  Undefined symbols for architecture x86_64:
    "_main", referenced from:
       implicit entry/start for main executable
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[2]: *** [main_32b] Error 1
  make[1]: *** [CMakeFiles/main_32b.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>
  
  <p>What am I missing here?</p>
  
  <p>===</p>
  
  <p>UPDATE: It is curious that setting <code>CMAKE_CXX_FLAGS</code> to include <code>-m32</code> makes the example work. However, I would like to get it done without setting variables, i.e., follow the mordern target-based approach.</p>