I am using cmake to generate project files for a C++ project that needs to be compiled under Visual Studio 6 and 2010. The files are generated OK for both projects and I can build the projects without a problems.
However, the 2010 vxproj files contain relative paths to the cpp files and when I use Jenkins to build the files the log contains relative paths that Jenkins can not use to find the source files.
I see this:
..\..\source\moduleA\file1.cpp(74): warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
While it should have been either source/moduleA/file.cpp or D:\jenkins\jobs\workspace\source\moduleA\file.cpp for Jenkins to be able to find the file.
Of course, I can make a parser to parse the log file and remove the ..\...\ but I am hoping to find a more elegant solution.
In the end I found a compiler option that can fix this. You can add the /FC flag for Visual Studio 2010. Not sure if it works for VC6. To add it use this:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC")
Related
I am able to CMake build this HelloWorld example project using cmakelists.txt file and generate a visual studio project.
project(helloworld LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.5)
find_package(Idlpp-cxx REQUIRED)
if (NOT TARGET CycloneDDS-CXX::ddscxx)
find_package(CycloneDDS-CXX REQUIRED)
endif()
# Convenience function, provided by the Idlpp-cxx that generates a CMake
# target for the given IDL file. The function calls Idlcpp-cxx to generate
# source files and compiles them into a library.
idl_ddscxx_generate(ddscxxHelloWorldData_lib "HelloWorldData.idl")
add_executable(ddscxxHelloworldPublisher publisher.cpp)
add_executable(ddscxxHelloworldSubscriber subscriber.cpp)
# Link both executables to idl data type library and ddscxx.
target_link_libraries(ddscxxHelloworldPublisher ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
target_link_libraries(ddscxxHelloworldSubscriber ddscxxHelloWorldData_lib CycloneDDS-CXX::ddscxx)
set_property(TARGET ddscxxHelloworldPublisher PROPERTY CXX_STANDARD 11)
set_property(TARGET ddscxxHelloworldSubscriber PROPERTY CXX_STANDARD 11)
I need to create the same project without cmakelists.txt and CMake
How to do this only using visual studio? where to define those commands in CMakelists.txt in visual studio if I create an empty c++ project
I have tried this making an empty project.
I don't know how to idl_ddscxx_generate and target_link_libraries perform in VS....
idl_ddscxx_generate has to run if IDL file has changed
target_link_libraries is required if I added new source files to the project....
Make a new, empty Visual Studio project.
Copy all source files except the CMake files.
Do whatever you do in a Visual Studio project. Add files, targets, dependecies, … If you are not sure, look up what is written in the CMakeLists.txt file.
Delete all CMake files in your original project and copy your Visual Studio project files.
Add these changes (deleted CMake files, added VS project files) to your Subversion repository, maybe do this in a branch that others can test it, report back, and improve the change. Once done, merge the branch.
Probably, add step 0.: Learn how Visual Studio organizes its project. Make a tutorial, take some training.
Remark: Whatever your problem is with CMake, you missed something. But you can find this out later and revert your changes and pick up CMake up again.
The Visual Studio 2019 project, which was built via cmake displays
File Modification Detected
The project ABC has been modified outside the environment
Reload ... Ignore ...
message.
How can I prevent cmake from updating the VS config files, for the project or system wide?
In what section of the cmake build files this behavior is defined (so that I can rebuild the project without this feature)?
No, you cannot prevent this (afaik). Consider the scenario where you add a source file to a target in a CMakeLists.txt file. CMake needs to update the Visual Studio project files it generated which results in project file(s) being overwritten. CMake sets up the solution in a way to ensure such an update on a modification of the cmake files. Visual Studio reacts to the solution/project files being overwritten by displaying the dialog you mentioned.
In general you'll want to click "Reload" which should just update the projects according to the modification in the cmake sources. If for a command line build tool shows up though, you may want to select "Ignore" though, since sometimes the build output is deleted on a reload of projects/the solution and you'll probably want to check the error message.
If you're interested: Overriding the project files happens in the ZERO_CHECK target.
If the dialog is displayed on a build even if you did not modify the cmake files since the last build, you may want to check the console for a warning in the output of cmake though; this may indicate that there may be some issue in your cmake files...
I have a cmake project with many cpp files (around 400+) and using /MP (multithreaded) compiler option speeds up the compilation significantly on CPU's with many cores.
The problem is, that everytime I regenerate the solution files using CMake, the option is disabled, resulting in compilation being very slow. I can fix that by changing option of EVERY single project (solution consist of many various projects) by hand inside of Visual Studio. However, everytime I regenerate the solution files by running CMake (for example when I git pull someone else's changes which added / removed some files) this change gets overwritten.
How can I make it persistent so that CMake always enable multithreaded compilation inside of VS projects?
Put the following add_compile_options() at the top of your project's main CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.12)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
or with older CMake versions < 2.8.12:
project(...)
if (MSVC)
add_definitions("/MP")
endif()
If you can't or don't want to change the main CMakeLists.txt file, you could always add your flags manually to CMAKE_CXX_FLAGS cached variable e.g. by using CMake's GUI (assuming that your CMake project itself is not forcing the values of CMAKE_CXX_FLAGS).
References
Is Cmake set variable recursive?
Change default value of CMAKE_CXX_FLAGS_DEBUG and friends in CMake
What's the CMake syntax to set and use variables?
I have a cross-platform project which uses CMake. I am doing out-of-source builds so basically I have a source directory "src" which contains the CMakeLists.txt and then I have a "src/build" directory where I generate the out-of-source build.
However when using Visual Studio (2013) it does not place the executable in the build dir but to "src/build/Debug" for example (depends on the selected configuration). I think this was referred as "$(OutDir)" inside VS. How do I refer to the (runtime) output directory in my CMakeLists.txt so I can copy DLLs and shaders where my executable is?
Edit: The suggested duplicate answer does not seem correct to me. In that answer you just force the output directories to be static which sounds wrong if you are using a multi-configuration build system like Visual Studio.
I solved my problem by copying the files with the "file (GENERATE OUTPUT)" which supports the cmake-generator-expressions suggested by StAlphonzo:
foreach (file ${SHADER_SOURCES})
file (GENERATE OUTPUT $<CONFIG>/${file} INPUT ${PROJECT_SOURCE_DIR}/${file})
endforeach()
I would also like to mention a second way of solving this problem I discovered that I think is actually more correct, by adding a custom command:
add_custom_command(TARGET target ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCES_DIR}/foo $<TARGET_FILE_DIR:target>)
whene ever i try to build project generated by cmake it generate errors like
"*error MSB6006: "cmd.exe" exited with code -1073741515
and error C1083: Cannot open include file: 'bigrecord.hh': No such file or directory"*
My cmake is 2.8.12.2
my Boost c++ library is 1_55_0
i am using visual studio 2010 in windows xp.
please help me for to solve this problam .. i need this for avro serialize...
if any one have other option then also reply me...
thank you in advance.
CMakeLists.txt states that bigrecord.hh is generated by custom target bigrecord_hh, used only for testing. If you really want to also build testing suite, download all input files you need (e.g. jsonschemas/bigrecord needed in target bigrecord.hh)
To specify to cmake that a file is generated and hence not present during configuration, GENERATED property must be set to TRUE. Try add this to your CMakeLists.txt (and similarly for other generated files)
SET_SOURCE_FILE_PROPERTIES(${BUILD_DIRECTORY}/bigrecord.hh PROPERTIES GENERATED TRUE)