title: duplicate compile flag in CMAKE_CXX_FLAGS
body: <p>I am trying to use cmake to link my project. </p>
  
  <p>I need to find a package <code>mypack</code>, it will give me <code>mypack_definitions</code>, <code>mypack_flags</code>, <code>mypack_include_dirs</code> , and <code>mypack_libraries</code>. Here <code>mypack_flags</code> contains relevant flags for linking mypack. I will add <code>mypack_flags</code> to <code>CMAKE_CXX_FLAGS</code>. </p>
  
  <p>Please see the CMakeLists.txt below:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  project(QMCLIB C CXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")
  
  find_package(mypack REQUIRED)
  
  add_executable(QMC codeA.cpp codeB.cpp )
  add_definitions(${mypack_definitions})
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${mypack_flags}")
  target_link_libraries(QMC ${mypack_libraries})
  target_include_directories(QMC PUBLIC ${mypack_include_dirs})
  </code></pre>
  
  <p>However depend on the systems, <code>mypack_flags</code> might or not contain <code>-fopenmp</code>, when it contains <code>-fopenmp</code>, my <code>CMAKE_CXX_FLAGS</code> will have two <code>-fopenmp</code>. I can not remove <code>-fopenmp</code> in</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")
  </code></pre>
  
  <p>If I remove it, when <code>mypack_flags</code> does not contains <code>-fopenmp</code>, then I will have no <code>-fopenmp</code> in CMAKE_CXX_FLAGS.</p>
  
  <p>Is there a way to force cmake only use one <code>-fopenmp</code>? Or is it okay to have two <code>-fopenmp</code>? Thank you for your suggestion.</p>
  
  <p>======================================================================</p>
  
  <p>Thanks to Robert Prévost, here is a general function to remove duplicate substrings:</p>
  
  <pre><code>function(removeDuplicateSubstring stringIn stringOut)
      separate_arguments(stringIn)
      list(REMOVE_DUPLICATES stringIn)
      string(REPLACE ";" " " stringIn "${stringIn}")
      set(${stringOut} "${stringIn}" PARENT_SCOPE)
  endfunction()
  </code></pre>
  
  <p>We can call this function by:</p>
  
  <pre><code> removeDuplicateSubstring(${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
  </code></pre>