0

I run cmake in the path "${PROJECT_NAME}/build", and I want generate the executable file in "${PROJECT_NAME}/bin" not "${PROJECT_NAME}/build".

When I used "ADD_EXECUTABLE(../bin/${PROJECT_NAME} ${sources})", I got the error: The target name "../bin/xxxx" is reserved or not valid for certain CMake features, such as generator expressions, and may result in undefined behavior.

Then I changed to "ADD_EXECUTABLE(${PROJECT_NAME} ${sources})", it passed, but it's generated in "${PROJECT_NAME}/build".

What can I do?

0

2 Answers 2

0

add_executable, as well as add_library and other functions like target_include_directories expect a name of a target, not path.

To change location of output files you're suggested to change a few properties for each target

set_target_properties(my_target PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin" PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../bin" 

There are also a few properties to control where libraries and archives go to: LIBRARY_OUTPUT_DIRECTORY and ARCHIVE_OUTPUT_DIRECTORY, you can set them to something too

Sign up to request clarification or add additional context in comments.

Comments

0

Try using custom command post build to copy the executable:

set(COPY_TO_PATH ${PROJECT_NAME}/bin) add_custom_command(TARGET xxx POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}/bin/xxx ${COPY_TO_PATH}) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.