VS has ‘Link Objects’ options and this option is set to ‘No’. Is it possible to change it to ‘Yes’?
Now I am working for windows version, but project should support Windows, Mac and Linux.
PS. I spent almost day to google solution with no success.
PSS. I can try to add these object files as source for target, but I think it is not right way, because these files will be visible as source files in IDE.
This variable contains list of output files. It makes as follow:
set( OUTPUT_DIR “${CMAKE_BINARY_DIR}/” )
set( OUTPUT_FILES “” )
<here some code prepares OUT, related vars and first part of COMMANDS>
foreach( OUT ${OUTPUTS} )
set( OUTPUT_FILE “${OUTPUT_DIR}${${OUT}_FILENAME}.obj” )
list( APPEND OUTPUT_FILES ${OUTPUT_FILE} )
list( APPEND COMMANDS COMMAND objcopy -I binary -O pe-x86-64 ${${OUT}_FILENAME}.bin ${${OUT}_FILENAME}.obj )
endforeach()
add_custom_command(…)
endfunction()
This code is placed in a function. The function is called one time per source file. The function may generate different number of output files. OUTPUT_FILES is used in this function only. make and VS properly handle these source files, if these files are modified then script re-build them, all output files are generated properly and I can add them manually in VS by changing ‘Link Objects’ to true in ‘Custom Build Tool’ and everything will build successful. or I can add them as source files into project in VS and also everything will be fine, but if I tried to add these output files as sources in cmake script - nothing is happen and build fails.
I though this is common practice - project has specific files used to generate object files and then add it to target. I am not familiar with cmake and I though community will show right practice how to do it with cmake. I tried to find this with no success.
Sorry, I was wrong regarding “I tried to add these output files as sources in cmake script - nothing is happen and build fails” , because I had error in my code. Some output files were not added.
Now it works with two side effects:
generated VS project has files group “Object Files” which contain all specified object files;
generated files are placed in ./build folder.
I tried to play with file properties (as the Internet suggested it), but nothing was changed. Here is code:
foreach( SHADER ${RENDER_SHADERS} )
add_player_shader( render ${SHADER} “render/” )
list( APPEND SHADERS_OUTPUT ${SHADER_OUTPUT} )
endforeach()
set_property( SOURCE ${SHADERS_OUTPUT} PROPERTY GENERATED true )
set_property( SOURCE ${SHADERS_OUTPUT} PROPERTY EXTERNAL_OBJECT true )
add_library( render STATIC ${RENDER_SOURCES} ${RENDER_SHADERS} ${SHADERS_OUTPUT} )
I am using a Visual Studio generator with this project (it is one of many projects in the solution). The project file that is ultimately generated has an “Object Files” filter, which is a bit annoying. I would like to avoid having this extra list of files.
If I try this instead:
# Create a static library
add_library(myLibrary STATIC ${SOURCES})
target_sources(myLibrary PRIVATE FILE_SET HEADERS BASE_DIRS ../include FILES ${INCLUDES})
# Set the output directory for the library
set_target_properties(myLibrary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CV_LIB}
LINKER_LANGUAGE CXX
)
…then the object files are generated, but they are not linked together into a library. I am not sure why.