<div dir="ltr">No.<div>CMake tracks each source file name exactly once.  If you set properties on it, it will be treated that way always.  Have to make  a copy of the source to cpp...</div><div><br>copies to cmake_binary_dir/<source name> </div><div>plusplus_file_dup is the resulting list <br></div><div>( <a href="https://github.com/d3x0r/SACK/blob/master/CMakeLists.txt#L655">https://github.com/d3x0r/SACK/blob/master/CMakeLists.txt#L655</a> )</div><div><br></div><div>(really this is just for headers... src/csrc.h should be ${binary}/src/csrc.h in target too because #include "crsc.h"</div><div><br></div><div><div>FOREACH(SOURCE ${PLUSPLUS_FILES_TO_COPY})</div><div>   if( ${SOURCE} MATCHES "${SOURCES_ROOT}(.*)$" )</div><div>       set( BASENAME ${CMAKE_MATCH_1} )</div><div>       set( plusplus_file_dup ${plusplus_file_dup} ${CMAKE_BINARY_DIR}/${BASENAME} )</div><div>       add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/${BASENAME}</div><div>                           DEPENDS ${SOURCE}</div><div>                           COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}</div><div>                           #COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/${BASENAME}</div><div>                           )</div><div>   else()</div><div>   endif()</div><div>ENDFOREACH(SOURCE)</div></div><div><br></div><div><br></div><div>---------------------</div><div>( <a href="https://github.com/d3x0r/SACK/blob/master/CMakeLists.txt#L672">https://github.com/d3x0r/SACK/blob/master/CMakeLists.txt#L672</a> )</div><div>THis make s abetter copy routine; it tests to see the type of header(file) and possible substitutions...  still kinda some debugging coments (#)  in there... this adds it as a rule, so it only generates the target source if the source is referenced.  therefore also onlly when those C files change do new copies get made.</div><div><br></div><div><div>macro( COPY_CPLUSPLUS FILE_LIST )</div><div>FOREACH(SOURCE ${ARGN} )</div><div>   if( ${SOURCE} MATCHES "${SACK_BASE}/(.*)\\.c$" )</div><div>      set( FILEOK 1 )</div><div>      set( BASENAME ${CMAKE_MATCH_1} )</div><div>      set( FILEEXT .cpp )</div><div>   elseif( ${SOURCE} MATCHES "${SACK_BASE}/(.*)\\.h$" )</div><div>      set( FILEOK 1 )</div><div>      set( BASENAME ${CMAKE_MATCH_1} )</div><div>      set( FILEEXT .h )</div><div>   elseif( ${SOURCE} MATCHES "(.*)\\.c$" )</div><div>      set( FILEOK 1 )</div><div>      set( BASENAME ${CMAKE_MATCH_1} )</div><div>      set( FILEEXT .cpp )</div><div>   elseif( ${SOURCE} MATCHES "(.*)\\.h$" )</div><div>      set( FILEOK 1 )</div><div>      set( BASENAME ${CMAKE_MATCH_1} )</div><div>      set( FILEEXT .h )</div><div>   else()</div><div>      set( FILEOK 0 )</div><div>      set( BASENAME "" )</div><div>   endif()</div><div><br></div><div>   if( FILEOK )</div><div>       get_source_file_property(SOURCE_FOLDER ${SOURCE} FOLDER)</div><div><br></div><div>       if( ${SOURCE} MATCHES "^${PROJECT_SOURCE_DIR}.*" )</div><div>          if( NOT ${SOURCE_FOLDER} MATCHES "NOTFOUND" )</div><div>            #message( "err folder : ${SOURCE_FOLDER} " )</div><div>            SOURCE_GROUP( ${SOURCE_FOLDER} FILES ${SOURCE} )</div><div>            SOURCE_GROUP( ${SOURCE_FOLDER} FILES ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div>          endif()</div><div>          add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                              DEPENDS ${SOURCE}</div><div>                              COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                              #COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                              )</div><div>          #EXECUTE_PROCESS(COMMAND cmake -E copy_if_different ${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div><br></div><div>       else( ${SOURCE} MATCHES "^${PROJECT_SOURCE_DIR}.*" )</div><div>         if( NOT ${SOURCE_FOLDER} MATCHES "NOTFOUND" )</div><div>           #message( "err folder : ${SOURCE_FOLDER} " )</div><div>           SOURCE_GROUP( ${SOURCE_FOLDER} FILES ${PROJECT_SOURCE_DIR}/${SOURCE} )</div><div>           SOURCE_GROUP( ${SOURCE_FOLDER} FILES ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div>         endif()</div><div>         add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                             DEPENDS ${PROJECT_SOURCE_DIR}/${SOURCE}</div><div>                             COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                             #COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT}</div><div>                             )</div><div>         #EXECUTE_PROCESS(COMMAND cmake -E copy_if_different ${PROJECT_SOURCE_DIR}/${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div>         #message( "LIB2_SOURCE2 : ${BASENAME}  ${SOURCE}" )</div><div>       endif()</div><div>     set( ${FILE_LIST} ${${FILE_LIST}} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div>     #set( cplusplus_sources ${cplusplus_sources} ${CMAKE_BINARY_DIR}/${BASENAME}${FILEEXT} )</div><div>   else()</div><div>      #message( "NOT THING ${SOURCE}" )</div><div>   endif()</div><div>ENDFOREACH(SOURCE)</div><div>endmacro( COPY_CPLUSPLUS )</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 17, 2018 at 10:05 AM, Jimi Damon <span dir="ltr"><<a href="mailto:jdamon@accesio.com" target="_blank">jdamon@accesio.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I want to use Gtest for some unit tests on a number of the C functions that comprise my C executable.  However, Gtest ( And gMock ) are C++ testing frameworks. </div><div><br></div><div>What I would like to have is a project for my exe and then a separate project for my C++ library and be able to change the source properties to use the language CXX just before compiling.</div><div><br></div><div>The problem I'm having is that CMake uses the CXX compiler for the C files.</div><div><br></div><div><br></div><div>Here's what I would like to have</div><div><br></div><div>project(cexe)</div><div>set(SOURCES foo.c bar.c )</div><div><div>add_executable( cexe  ${SOURCES} )</div></div><div><br></div><div>project(cpplib)</div><div><div>set_source_files_properties(${<wbr>SOURCES} PROPERTIES LANGUAGE CXX )</div></div><div><div>add_library( cpplib SHARED ${SOURCES} )</div></div><div><br></div><div><br></div><div><br></div><div>Is there a way to do this ?  </div><div><br></div><div>Can target_compile_options set the compile type for a given target ? </div><div><br></div><div><br></div><div>In the past I've had to copy the .C files to some renamed .CPP equivalent and then compile off of that.  </div><div><br></div><div>I'm hoping that enough new functionality has been added to Cmake to allow separation between compiles.</div><div><br></div><div><br></div><div>Thanks,</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div><br></div><div><div><br></div>-- <br><div class="m_-1580327637643654833gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><br><span></span><table><tbody><tr><td style="vertical-align:top;width:431px"><div style="font-family:Verdana,"Lucida Sans Unicode","Lucida Sans","DejaVu Sans",sans-serif;color:rgb(0,0,0);width:375px"> <small>
                   <span style="font-weight:bold"><span>Jimi</span>
                    <span>Damon</span></span><br>
                  <a href="http://accesio.com/go.cgi?p=/contact/contact.html" style="font-weight:bold;text-decoration:none;color:rgb(0,0,136)" target="_blank">ACCES I/O Products, Inc.</a><br>
                   <span style="font-style:italic;font-weight:bold">Linux Engineer</span><br>
                   <a href="mailto:JDamon@accesio.com" style="text-decoration:none;color:rgb(0,0,136)" target="_blank">JDamon@accesio.com</a><br>
                   <span><span>(858)
                      550-7320 x3015</span></span><br>
                </small></div>
            </td>
             <td style="text-align:center;width:346px">
              <div style="text-align:center;margin-left:0px;width:339px"><a href="http://accesio.com/" style="text-decoration:none;color:rgb(0,0,136)" target="_blank"><img src="https://mail.google.com/mail/u/1/?ui=2&ik=25da780046&view=fimg&th=14a5619973eb6e26&attid=0.0.1&disp=emb&attbid=ANGjdJ_JtLwbDFSIbILPeAVZHeO8x_MTLvn85jvCOK5AtVfZK1BF9-Qz2NPJput9pNE5YtUa1WsPJcAAY8A-ffStTtVvWFYkQsyUkh924NH7y_aDDAyHta6W-F9Ka1U&sz=w664-h114&ats=1418783753561&rm=14a5619973eb6e26&zw&atsh=1" alt="ACCES I/O Logo" height="34" width="200"><br>
                  <small><span><span>10623
                        Roselle Street</span> <span>San
                        Diego</span> <abbr title="California">CA</abbr> <span>92121-1506</span></span></small></a></div></td></tr></tbody></table><br></div></div></div></div></div></div>
</div></font></span></div><span class="HOEnZb"><font color="#888888">

<br>
<font color="gray" size="1">WARNING - This e-mail or its attachments may contain controlled technical data or controlled technology within the definition of the International Traffic in Arms Regulations (ITAR) or Export Administration Regulations (EAR), and are subject to the export control laws of the U.S. Government. Transfer of this data or technology by any means to a foreign person, whether in the United States or abroad, without an export license or other approval from the U.S. Government, is prohibited. The information contained in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc. Any unauthorized review, use, disclosure or distribution is prohibited without express written consent of ACCES I/O Products, Inc. If you are not the intended recipient, please contact the sender and destroy all copies of the original message and enclosed attachments.</font></font></span><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
<br></blockquote></div><br></div>