[CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only
Hi there, in the hope of achieving platform independence of my plain-C project I have started looking into CMake, trying to duplicate what my manually created makefiles do. A minimalistic description of my problem is the following: * I have 2 executable targets * both having the same main program source MAIN/main.c * both linking to a library libvehicle.a that is built from the same set of sources, e.g. VEHICLE/read_hydrodynamic_coeffs.c The difference between both targets is a compiler definition -D_TYPE1_ or -D_TYPE2_ that is used in the sourcecode, e.g. hydro_par_t read_hydrodynamic_coeffs(sys_par_t sys_par) { #if defined(_TYPE1_) return(read_hydrodynamic_coeffs_type1(sys_par)); #elif defined(_TYPE2_) return(read_hydrodynamic_coeffs_type2(sys_par)); #endif } So the in both cases the library libvehicle.a will contain a function read_hydrodynamic_coeffs but the actual content of this function will be different. [ In realiter it's more complicated because there are more executables and combinations of several switches, so I really don't want to change the sources. ] What I've done so far is * in the main CMakeLists.txt: add_subdirectory(CMakeTargets/sim_type1) * in CMakeTargets/sim_type1/CMakeLists.txt: add_definitions(-D_TYPE1_) include_directories(../../VEHICLE/INCLUDE) add_subdirectory(../../VEHICLE VEHICLE) add_executable(sim_type1 ../../MAIN/main) target_link_libraries(sim_type1 vehicle) * in CMakeTargets/VEHICLE/CMakeLists.txt: set(SRC read_hydrodynamic_coeffs) set(SRC ${SRC} read_hydrodynamic_coeffs_type1) set(SRC ${SRC} read_hydrodynamic_coeffs_type2) add_library(vehicle ${SRC}) For one target only this gives a executable CMakeTargets/sim_type1/sim_type1 that is working as expected. As specified by add_subdirectory(../../VEHICLE VEHICLE), object file and library are created locally: ./CMakeTargets/sim_type1/VEHICLE/CMakeFiles/vehicle.dir/read_hydrodynamic_coeffs.c.o ./CMakeTargets/sim_type1/VEHICLE/libvehicle.a But as soon as I try to add_subdirectory(CMakeTargets/sim_type2) [rest as above, only 1-2] I get an error message add_library cannot create target vehicle because another target with the same name already exists. The existing target is a static library created in source directory ./VEHICLE. See documentation for policy CMP0002 for more details. Trying to cheat with cmake_policy(SET CMP0002 OLD) I can compile both executables but they are messed up, obviously trying to execute read_hydrodynamic_coeffs for the wrong type. So, how do I define a set of executable make targets, differing only in the -D_defines_ that are used to build all of the source needed? Thanks in advance, Eike ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only
Hi Eike, I think the only safe and reliable way to do this is create several build directories, e.g. build/type_1 and build/type_2. When running cmake in build/type_1, you should add -D_TYPE1_ to the preprocessor flags; same for build/type_2. Best regards, Marcel Loose. On Thu, 2009-08-27 at 12:28 +0200, Eike Kroemer wrote: Hi there, in the hope of achieving platform independence of my plain-C project I have started looking into CMake, trying to duplicate what my manually created makefiles do. A minimalistic description of my problem is the following: * I have 2 executable targets * both having the same main program source MAIN/main.c * both linking to a library libvehicle.a that is built from the same set of sources, e.g. VEHICLE/read_hydrodynamic_coeffs.c The difference between both targets is a compiler definition -D_TYPE1_ or -D_TYPE2_ that is used in the sourcecode, e.g. hydro_par_t read_hydrodynamic_coeffs(sys_par_t sys_par) { #if defined(_TYPE1_) return(read_hydrodynamic_coeffs_type1(sys_par)); #elif defined(_TYPE2_) return(read_hydrodynamic_coeffs_type2(sys_par)); #endif } So the in both cases the library libvehicle.a will contain a function read_hydrodynamic_coeffs but the actual content of this function will be different. [ In realiter it's more complicated because there are more executables and combinations of several switches, so I really don't want to change the sources. ] What I've done so far is * in the main CMakeLists.txt: add_subdirectory(CMakeTargets/sim_type1) * in CMakeTargets/sim_type1/CMakeLists.txt: add_definitions(-D_TYPE1_) include_directories(../../VEHICLE/INCLUDE) add_subdirectory(../../VEHICLE VEHICLE) add_executable(sim_type1 ../../MAIN/main) target_link_libraries(sim_type1 vehicle) * in CMakeTargets/VEHICLE/CMakeLists.txt: set(SRC read_hydrodynamic_coeffs) set(SRC ${SRC} read_hydrodynamic_coeffs_type1) set(SRC ${SRC} read_hydrodynamic_coeffs_type2) add_library(vehicle ${SRC}) For one target only this gives a executable CMakeTargets/sim_type1/sim_type1 that is working as expected. As specified by add_subdirectory(../../VEHICLE VEHICLE), object file and library are created locally: ./CMakeTargets/sim_type1/VEHICLE/CMakeFiles/vehicle.dir/read_hydrodynamic_coeffs.c.o ./CMakeTargets/sim_type1/VEHICLE/libvehicle.a But as soon as I try to add_subdirectory(CMakeTargets/sim_type2) [rest as above, only 1-2] I get an error message add_library cannot create target vehicle because another target with the same name already exists. The existing target is a static library created in source directory ./VEHICLE. See documentation for policy CMP0002 for more details. Trying to cheat with cmake_policy(SET CMP0002 OLD) I can compile both executables but they are messed up, obviously trying to execute read_hydrodynamic_coeffs for the wrong type. So, how do I define a set of executable make targets, differing only in the -D_defines_ that are used to build all of the source needed? Thanks in advance, Eike ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only
Von: Marcel Loose lo...@astron.nl CC: cmake@cmake.org Betreff: Re: [CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only Hi Eike, I think the only safe and reliable way to do this is create several build directories, e.g. build/type_1 and build/type_2. When running cmake in build/type_1, you should add -D_TYPE1_ to the preprocessor flags; same for build/type_2. Why? Does SET_TARGET_PROPERTIES() with COMPILE_FLAGS not work? Christian -- Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02 ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] VS 2008 x64, Boost 1.39 - Can not find boost libraries
First: Sorry for the cross-post but the problem involves projects from all three lists. Comments are below: On Thu, Aug 27, 2009 at 12:01 AM, Philip Lowmanphi...@yhbt.com wrote: Mike, Sorry, I didn't realize you were using the CMake build for Boost. I wouldn't be surprised if there were issues with it as it's still experimental. You could report (both?) bugs to the boost-cmake list and/or try to reproduce with 1.40beta? http://lists.boost.org/mailman/listinfo.cgi/boost-cmake I used Visual Studio (Express) 2005 2008 (32bit) command prompts with bjam. On Tue, Aug 25, 2009 at 8:01 AM, Mike Jackson mike.jack...@bluequartz.net wrote: Just to be clear, did you build them with the 64bit command prompt from Visual Studio? Otherwise how did you build them? I ended up tweaking the cmake files that come with boost 1.39 in order to remove the -s that is tagged onto the unittest libraries. Otherwise not really sure what to do as this is all new to me (the windows side of things any ways...) _ Mike Jackson mike.jack...@bluequartz.net On Tue, Aug 25, 2009 at 12:26 AM, Philip Lowmanphi...@yhbt.com wrote: Mike, Let us know what you find out. I've built 1.39 and 1.40beta using the standard bootstrap bjam build system using VS9 and both times they came out in the form [lib]boost_foo-vc90-mt-1_39.lib. On Mon, Aug 24, 2009 at 2:39 PM, Mike Jackson mike.jack...@bluequartz.net wrote: Setup is as follows: Windows 7 x64 Visual Studio 2008 standard Edition Boost 1.39.0 download from source CMake 2.6.4 Compiled boost libraries as usual using the x64 command prompt that comes with VS 2008. Compiled fine except the library naming is a bit off from usual. Instead of having -vc90- in the name the boost libraries only have -vc- in them. This throws off FindBoost. The quick fix was to use: cmake -DBoost_COMPILER=-vc ../ and at least cmake could configure my project. Just a heads up in case anyone else runs into this situation. Pinged the boost-build list to see if this is a bug, feature or over-sight... _ Mike Jackson mike.jack...@bluequartz.net BlueQuartz Software www.bluequartz.net Principal Software Engineer Dayton, Ohio -- Philip Lowman -- Philip Lowman I probably should have been a bit more verbose about what happened. All of this was on a Windows 7 x64 machine with VS 2008 standard Ed installed and using the VS x64 command prompt. First tried to use the standard bjam to compile boost. All seemed to compile fine except the library naming had the -vc- instead of the -vc90- as would be expected. Ok. It is just a name, what harm could that cause Well I used cmake to configure my own project using the command cmake -DBoost_COMPILER=-vc ../ to let it configure. My project configured and I attempted the build with VS 9. The problem came at linking. Although the boost libraries had the -vc- in the name something embedded in the library was really pointing to boost libraries with -vc90- in the name so the linking could never finish. Next I tried using the CMake build system that comes with boost 1.39.0. Again the libraries built but the unit-testing libraries had the -s tacked onto the end of the names which again throws off the FindBoost that come standard with CMake 2.6.4. I hacked through the boost-cmake sources to remove the -s on the unit testing libraries, recompiled and now all is working and all libraries have the correct naming conventions. I don't know the root cause of the problem with bjam. I posted some traces to the boost.build mailing list but have not heard anything back. Maybe it has something to do with Windows 7 or x64 command prompt. If I had time I would probably install VS 2008 on Windows XP (32 bit) and try to use the x64 Cross Tools command prompt to compile a 64 bit boost library set and see what happens there. Just a heads up that there might be some problems when Windows 7 is release to greater numbers and the specific combination of: boost compiled in x64 mode and a CMake based project is used. _ Mike Jackson mike.jack...@bluequartz.net BlueQuartz Softwarewww.bluequartz.net Principal Software Engineer Dayton, Ohio ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only
Hi Marcel, Christian, Am 08/27/2009 01:30 PM Marcel Loose wrote: I think the only safe and reliable way to do this is create several build directories, e.g. build/type_1 and build/type_2. When running cmake in build/type_1, you should add -D_TYPE1_ to the preprocessor flags; same for build/type_2. By 'build directories' you mean to duplicate the library sourcecodes? Using the approach sketched in the original post, I have tried to create different directories for holding objects and libs - so far without success. - Am 08/27/2009 01:37 PM Christian Ehrlicher wrote: Why? Does SET_TARGET_PROPERTIES() with COMPILE_FLAGS not work? I tried something with SET_TARGET_PROPERTIES but when used on the target sim_type1 the define-flag won't be inherited by the library the target depends on, thus I used add_definitions instead I think the problem comes with using add_subdirectory(../../VEHICLE VEHICLE) and the subsequent add_library(vehicle ${SRC}) While this sets up a binary directory local to the make-target, it also creates CMake*-files 'globally', for all targets. A brute-force-approach would be to remove those sources from the ${SRC} in the add_library commands that need the -D_TYPE*_ defines and add them to the source-list of add_executable(sim_type1 ...). This would be awkward, would it work? Thanks again, Eike ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] How to build 2 targets from the same source, differing in -D_SWITCHES_ only
On Thu, Aug 27, 2009 at 8:55 AM, Eike Kroemereike-michael.kroe...@atlas-elektronik.com wrote: Hi Marcel, Christian, Am 08/27/2009 01:30 PM Marcel Loose wrote: I think the only safe and reliable way to do this is create several build directories, e.g. build/type_1 and build/type_2. When running cmake in build/type_1, you should add -D_TYPE1_ to the preprocessor flags; same for build/type_2. By 'build directories' you mean to duplicate the library sourcecodes? Not the source just the output. You put your source in a single folder and then create 1 build tree for each different type of build you want. On windows I use this to build my projects with different compilers and on top of that I use this to create separate 32 and 64 bit builds. John ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
[CMake] How does interaction between UseXXX.cmake, XXXBuildSettings.cmake and XXXConfig.cmake supposedly work.
I use some classes of vtkINRIA3D library for an ITK/VTK/KWWidgets application. If you haven't heard of it: http://www-sop.inria.fr/asclepios/software/vtkINRIA3D/ I had always been building against vtkINRIA3D 'in place' -- i.e. including the UsevtkINRIA3D.cmake from its build directory. I'm changing this to instead install the library in a common directory with the other prerequisite libraries for our applications. This is primarily an issue of delivery -- it makes it marginally easier to collect all the shared libraries our app depends on for installation. But if I try and build against this installed copy of vtkINRIA3D, the compiler can't find the include files. In looking at UsevtkINRIA3D.cmake, it has this clause: INCLUDE_DIRECTORIES(${vtkINRIA3D_INCLUDE_DIRS}) but that variable is not defined. It IS defined in vtkINRIA3DConfig.cmake, but that file is not included by UsevtkINRIA3D.cmake. So I assumed there was something wrong with how vtkINRIA3D is set up or built, in that vtkINRIA3DConfig.cmake is not included. So I looked at what ITK and VTK do, and there's a similar setup -- I don't see where either of them include the *Config.cmake file. So I'm down in the maze of CMake's deep structure, lost. How is this all supposed to work? ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
[CMake] Unknown origin of compiler flag on Cray
Hi All, I am experiencing a strange problem on Cray XT machines running CNL compute nodes with the PGI compiler. It appears that something is adding the flags -Bstatic -Bdynamic (in that order) to the link line. It looks like the Linux.cmake platform module sets the the variable CMAKE_${type}_DYNAMIC_C_FLAGS to -Bdynamic. But that's the only reference to the flags that I can find anywhere in the project. The cache does not contain the flags, my list files do not contain the flags, and as far as I can tell, none of the modules I am using add the flags (the only modules I call are a custom exodus find module, a custom netcdf find module, and the HDF5 find module I submitted earlier this week). Also, all of the libraries built by my projects and the libraries found by cmake with find_package are static. The flags are causing problems because we use the Cray provided wrapper compilers, which add a few additional libraries to the link line, and the ordering of the flags causes the linker to use the dynamic version of some libraries, which is unsupported by the CNL compute nodes. Has anyone seen something like this before, or does anyone have any suggestions on where else I should look to find the culprit? Thanks, --Will -- Will Dicharry Software Developer Stellar Science Ltd Co smime.p7s Description: S/MIME Cryptographic Signature ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Compiled file cannot be executed
Use full path file names as DEPENDS arguments. Also: depend on the executable file too so that cmake knows not to try to run the custom command before the executable is built... i.e. : DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} HTH, David On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra swaroo...@gmail.comwrote: Hi Michael, Thanks for your reply. I still have the same problem. * * gmake-3.81[2]: bin/generate: Command not found lin: gmake-3.81[2]: *** [bin/generate] Error 127 lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2 Here's my code as is: #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS server/someinput.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) Still the same issue. I guess it is trying to execute my generate even before it is compiled. Does CMake see that in the line COMMAND generate refers to the compiled one? Again, since generate is created in round one of make, the second run sees the generate and runs fine. Any help is greatly appreciated! Thanks for your time! Regards, Swaroop 2009/8/27 Michael Wild them...@gmail.com On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote: Hi, I'm trying to do the following in my CMake file: 1. Generate a xyz.txt file 2. Compile a generate.c file to give out a generate binary in my bin directory. 3. Execute the generate binary (The binary just reads contents of xyz.txt and creates a copy of xyz.txtusing read() and write() functions in C) The problem: When I do a fresh build, 1 and 2 succeed. 3 fails with the following error *bin/generate: Command not found* However, if I *re-run the build immediately* after, since the generate binary is already created, all 3 successfully execute. Here's a snippet of what I have written. /* Code to generate xyz.txt -- Successfully generated each time--*/ -- - ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c) set(GEN ${CMAKE_BINARY_DIR}/bin/generate) ADD_CUSTOM_COMMAND( TARGET generate POST_BUILD COMMAND ${GEN} DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt} ) In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the generate binary. That's the wrong way to go about it. the TARGET form of the add_custom_command is intended to finish the actual target. What you want is something like this: # no need for absolute paths... add_executable(generate server/generate.c) add_custom_command( # tell cmake you want to generate xyz.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt # only run if xyz.txt changed DEPENDS xyz.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # some nice comment in the output COMMENT Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c VERBATIM ) And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your other targets. CMake will then know that it first needs to create target generate, then run the program on xyz.txt to create ${CMAKE_CURRENT_BINARY_DIR}/xyz.c, and finally use that to build the actual target. HTH Michael -- Samuel Goldwynhttp://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html - I'm willing to admit that I may not always be right, but I am never wrong. ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Compiled file cannot be executed
Still no luck :( . I really wonder why it is trying to execute my generate binary even before it is built. Here are my updated lines of code. #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) 2009/8/27 David Cole david.c...@kitware.com Use full path file names as DEPENDS arguments. Also: depend on the executable file too so that cmake knows not to try to run the custom command before the executable is built... i.e. : DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} HTH, David On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra swaroo...@gmail.com wrote: Hi Michael, Thanks for your reply. I still have the same problem. * * gmake-3.81[2]: bin/generate: Command not found lin: gmake-3.81[2]: *** [bin/generate] Error 127 lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2 Here's my code as is: #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS server/someinput.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) Still the same issue. I guess it is trying to execute my generate even before it is compiled. Does CMake see that in the line COMMAND generate refers to the compiled one? Again, since generate is created in round one of make, the second run sees the generate and runs fine. Any help is greatly appreciated! Thanks for your time! Regards, Swaroop 2009/8/27 Michael Wild them...@gmail.com On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote: Hi, I'm trying to do the following in my CMake file: 1. Generate a xyz.txt file 2. Compile a generate.c file to give out a generate binary in my bin directory. 3. Execute the generate binary (The binary just reads contents of xyz.txt and creates a copy of xyz.txtusing read() and write() functions in C) The problem: When I do a fresh build, 1 and 2 succeed. 3 fails with the following error *bin/generate: Command not found* However, if I *re-run the build immediately* after, since the generate binary is already created, all 3 successfully execute. Here's a snippet of what I have written. /* Code to generate xyz.txt -- Successfully generated each time--*/ -- - ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c) set(GEN ${CMAKE_BINARY_DIR}/bin/generate) ADD_CUSTOM_COMMAND( TARGET generate POST_BUILD COMMAND ${GEN} DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt} ) In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the generate binary. That's the wrong way to go about it. the TARGET form of the add_custom_command is intended to finish the actual target. What you want is something like this: # no need for absolute paths... add_executable(generate server/generate.c) add_custom_command( # tell cmake you want to generate xyz.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt # only run if xyz.txt changed DEPENDS xyz.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # some nice comment in the output COMMENT Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c VERBATIM ) And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your other targets. CMake will then know that it first needs to create target generate, then run the program on xyz.txt to create ${CMAKE_CURRENT_BINARY_DIR}/xyz.c, and finally use that to build the actual target. HTH Michael --
Re: [CMake] Compiled file cannot be executed
Hi Michael, Thanks for your reply. I still have the same problem. * * gmake-3.81[2]: bin/generate: Command not found lin: gmake-3.81[2]: *** [bin/generate] Error 127 lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2 Here's my code as is: #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS server/someinput.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) Still the same issue. I guess it is trying to execute my generate even before it is compiled. Does CMake see that in the line COMMAND generate refers to the compiled one? Again, since generate is created in round one of make, the second run sees the generate and runs fine. Any help is greatly appreciated! Thanks for your time! Regards, Swaroop 2009/8/27 Michael Wild them...@gmail.com On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote: Hi, I'm trying to do the following in my CMake file: 1. Generate a xyz.txt file 2. Compile a generate.c file to give out a generate binary in my bin directory. 3. Execute the generate binary (The binary just reads contents of xyz.txt and creates a copy of xyz.txtusing read() and write() functions in C) The problem: When I do a fresh build, 1 and 2 succeed. 3 fails with the following error *bin/generate: Command not found* However, if I *re-run the build immediately* after, since the generate binary is already created, all 3 successfully execute. Here's a snippet of what I have written. /* Code to generate xyz.txt -- Successfully generated each time--*/ -- - ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c) set(GEN ${CMAKE_BINARY_DIR}/bin/generate) ADD_CUSTOM_COMMAND( TARGET generate POST_BUILD COMMAND ${GEN} DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt} ) In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the generate binary. That's the wrong way to go about it. the TARGET form of the add_custom_command is intended to finish the actual target. What you want is something like this: # no need for absolute paths... add_executable(generate server/generate.c) add_custom_command( # tell cmake you want to generate xyz.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt # only run if xyz.txt changed DEPENDS xyz.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # some nice comment in the output COMMENT Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c VERBATIM ) And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your other targets. CMake will then know that it first needs to create target generate, then run the program on xyz.txt to create ${CMAKE_CURRENT_BINARY_DIR}/xyz.c, and finally use that to build the actual target. HTH Michael -- Samuel Goldwynhttp://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html - I'm willing to admit that I may not always be right, but I am never wrong. ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
[CMake] Setting target properties
My case: I have one file which can be compiled into 4 different binaries using macros. For this I use add_definitions() and remove_definitions() commands. But as I understand these commands has global effect in CMakeLists file. How can I define and undefine macros in *one* CMakeLists file? For this case more useful another command - set_target_properties() with property COMPILE_FLAGS. It really helped me, but I was confronted with difficulties in this way. I can't call it with 2 parameters, like set_target_properties( target PROPERTIES COMPILE_FLAGS -D__flag1__ COMPILE_FLAGS -D__flag2__ ). In this case no keys were defined... It's very strange, because CMake's documentation present usage example with multiple properties in one command. I solved this issue with variable which contains all needed keys. -- -- Andrey ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Compiled file cannot be executed
David is probably right, that you need to add the dependency on generate. However, only add it's target name to both the COMMAND and DEPENDS arguments, CMake should figure this out. Michael On 27. Aug, 2009, at 21:31, Swaroop Ramachandra wrote: Still no luck :( . I really wonder why it is trying to execute my generate binary even before it is built. Here are my updated lines of code. #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) 2009/8/27 David Cole david.c...@kitware.com Use full path file names as DEPENDS arguments. Also: depend on the executable file too so that cmake knows not to try to run the custom command before the executable is built... i.e. : DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt $ {CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} HTH, David On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra swaroo...@gmail.com wrote: Hi Michael, Thanks for your reply. I still have the same problem. * * gmake-3.81[2]: bin/generate: Command not found lin: gmake-3.81[2]: *** [bin/generate] Error 127 lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2 Here's my code as is: #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS server/someinput.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) Still the same issue. I guess it is trying to execute my generate even before it is compiled. Does CMake see that in the line COMMAND generate refers to the compiled one? Again, since generate is created in round one of make, the second run sees the generate and runs fine. Any help is greatly appreciated! Thanks for your time! Regards, Swaroop 2009/8/27 Michael Wild them...@gmail.com On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote: Hi, I'm trying to do the following in my CMake file: 1. Generate a xyz.txt file 2. Compile a generate.c file to give out a generate binary in my bin directory. 3. Execute the generate binary (The binary just reads contents of xyz.txt and creates a copy of xyz.txtusing read() and write() functions in C) The problem: When I do a fresh build, 1 and 2 succeed. 3 fails with the following error *bin/generate: Command not found* However, if I *re-run the build immediately* after, since the generate binary is already created, all 3 successfully execute. Here's a snippet of what I have written. /* Code to generate xyz.txt -- Successfully generated each time--*/ -- - ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/ generate.c) set(GEN ${CMAKE_BINARY_DIR}/bin/generate) ADD_CUSTOM_COMMAND( TARGET generate POST_BUILD COMMAND ${GEN} DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt} ) In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the generate binary. That's the wrong way to go about it. the TARGET form of the add_custom_command is intended to finish the actual target. What you want is something like this: # no need for absolute paths... add_executable(generate server/generate.c) add_custom_command( # tell cmake you want to generate xyz.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt # only run if xyz.txt changed DEPENDS xyz.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # some nice comment in the output COMMENT Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c VERBATIM ) And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your other targets. CMake will then know that it first needs to create
Re: [CMake] Setting target properties
On Thu, Aug 27, 2009 at 11:11:54PM +0400, Andrey Maslennikov wrote: file. How can I define and undefine macros in *one* CMakeLists file? For this case more useful another command - set_target_properties() with property COMPILE_FLAGS. It really helped me, but I was confronted with difficulties in this way. I can't call it with 2 parameters, like set_target_properties( target PROPERTIES COMPILE_FLAGS -D__flag1__ COMPILE_FLAGS -D__flag2__ ). In this case no keys were defined... It's very strange, because CMake's documentation present usage example with multiple properties in one command. I solved this issue with variable which contains all needed keys. You probably want set_source_files_properties(). In y our set_target_properties example, how about: set_target_properties( target PROPERTIES COMPILE_FLAGS -Dflag1 -Dflag2) tyler ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Build problem with cmake-2.6.2 on Centos 5.x system
On Mon, Jan 5, 2009 at 11:22 PM, Bill Hoffmanbill.hoff...@kitware.com wrote: George R Goffe wrote: Howdy, I just downloaded cmake 2.6.2 on one of my Centos systems and tried to build it... I got the following msgs for my trouble. I see that the problem was reported for the CVS version but I'm not sure I want to run what could be a less than stable version on my production systems. Does anyone know of a work around or fix for this problem? Am I missing something here? Something went wrong with the build. I have not seen that problem before even in CVS. You should look at this file: /tools/cmake/cmake-2.6.2/Bootstrap.cmk/cmake_bootstrap.log The problem is that cmSystemTools.cxx should not be using cmELF.cxx during bootstrap. That symbol should only be required if CMAKE_USE_ELF_PARSER is defined, which it should not be during bootstrap. One thing you could try is to figure out the command line used to compile cmSystemTools.cxx during bootstrap, and then change it to use g++ -E and look at the pre-processed file. It should not have the elf stuff used. #if defined(CMAKE_USE_ELF_PARSER) # include cmELF.h #endif This happens every time for me on Red Hat 5.3 if I run the configure script on an already configured project. -- Andrew Sayman Jabber: gnu_lor...@jabber.org ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Passing svn password to ctest
David Rawlins wrote: My svn repository requires a password. How do I pass the password to ctest in order to do a ctest -D Nightly from a cron job? You could always set your svn config to allow saving passwords, then do something that makes it ask for your password (e.g. 'svn log'), type your password, and it will be saved. But it is saved in cleartext (in ~/.subversion). -- Matthew Please do not quote my e-mail address unobfuscated in message bodies. -- For great justice!! -- Captain (Zero Wing) ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Setting target properties
On Thu, Aug 27, 2009 at 3:11 PM, Andrey Maslennikov andrew.maslenni...@gmail.com wrote: My case: I have one file which can be compiled into 4 different binaries using macros. For this I use add_definitions() and remove_definitions() commands. But as I understand these commands has global effect in CMakeLists file. How can I define and undefine macros in *one* CMakeLists file? For this case more useful another command - set_target_properties() with property COMPILE_FLAGS. It really helped me, but I was confronted with difficulties in this way. I can't call it with 2 parameters, like set_target_properties( target PROPERTIES COMPILE_FLAGS -D__flag1__ COMPILE_FLAGS -D__flag2__ ). In this case no keys were defined... It's very strange, because CMake's documentation present usage example with multiple properties in one command. I solved this issue with variable which contains all needed keys. You could write a small CMakeLists function that uses get_target_property() followed by set_target_properties() to append flags to the COMPILE_FLAGS property. Give this a shot: function(append_compile_flags_to_target _target) get_target_property(_existing ${_target} COMPILE_FLAGS) if(_existing) set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_existing} ${ARGN}) else() set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${ARGN}) endif() endfunction() Overall though I agree with you, it should be possible to append multiple properties to the same set_target_properties() command. -- Philip Lowman ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Compiled file cannot be executed
I did. The same problem persists. Is there a work-around - maybe some other command that I can use? 2009/8/27 Michael Wild them...@gmail.com David is probably right, that you need to add the dependency on generate. However, only add it's target name to both the COMMAND and DEPENDS arguments, CMake should figure this out. Michael On 27. Aug, 2009, at 21:31, Swaroop Ramachandra wrote: Still no luck :( . I really wonder why it is trying to execute my generate binary even before it is built. Here are my updated lines of code. #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) 2009/8/27 David Cole david.c...@kitware.com Use full path file names as DEPENDS arguments. Also: depend on the executable file too so that cmake knows not to try to run the custom command before the executable is built... i.e. : DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX} HTH, David On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra swaroo...@gmail.com wrote: Hi Michael, Thanks for your reply. I still have the same problem. * * gmake-3.81[2]: bin/generate: Command not found lin: gmake-3.81[2]: *** [bin/generate] Error 127 lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2 Here's my code as is: #Trying to compile and run generate.c. generate.c creates a new file someoutput.txt and copies all data from someinput.txt to someoutput.txt add_executable(generate server/generate.c) add_custom_command( # I want to generate someoutput.txt OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt # only run if sominput.txt changed DEPENDS server/someinput.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin # some nice comment in the output COMMENT Generating ${CMAKE_BINARY_DIR}/someoutput.txt VERBATIM ) Still the same issue. I guess it is trying to execute my generate even before it is compiled. Does CMake see that in the line COMMAND generate refers to the compiled one? Again, since generate is created in round one of make, the second run sees the generate and runs fine. Any help is greatly appreciated! Thanks for your time! Regards, Swaroop 2009/8/27 Michael Wild them...@gmail.com On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote: Hi, I'm trying to do the following in my CMake file: 1. Generate a xyz.txt file 2. Compile a generate.c file to give out a generate binary in my bin directory. 3. Execute the generate binary (The binary just reads contents of xyz.txt and creates a copy of xyz.txtusing read() and write() functions in C) The problem: When I do a fresh build, 1 and 2 succeed. 3 fails with the following error *bin/generate: Command not found* However, if I *re-run the build immediately* after, since the generate binary is already created, all 3 successfully execute. Here's a snippet of what I have written. /* Code to generate xyz.txt -- Successfully generated each time--*/ -- - ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c) set(GEN ${CMAKE_BINARY_DIR}/bin/generate) ADD_CUSTOM_COMMAND( TARGET generate POST_BUILD COMMAND ${GEN} DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt} ) In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the generate binary. That's the wrong way to go about it. the TARGET form of the add_custom_command is intended to finish the actual target. What you want is something like this: # no need for absolute paths... add_executable(generate server/generate.c) add_custom_command( # tell cmake you want to generate xyz.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c # using the generate program. cmake knows that generate refers to the above target COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt # only run if xyz.txt changed DEPENDS xyz.txt # tell to run in current binary dir WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # some nice comment in the