I'm trying to learn how to create archives with CMake. I wrote this piece of code:
cmake_minimum_required(VERSION 3.5.1)
project(hello)
message("Creating archieve in: " ${CMAKE_CURRENT_BINARY_DIR})
message("Source dir is: " ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(hello main.cpp)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(create_tar ALL COMMAND
${CMAKE_COMMAND} -E tar "cfvz" "archieve.tgz")
add_dependencies(create_tar hello)
My project structure is like this: I have a main folder in which I have a CMakeLists.txt, a main.cpp and a build folder. I go into build and run the cmake file above by 'cmake ..' and then make. My archive is created in the build folder but as you can see I have specified that I want it in the CMAKE_CURRENT_SOURCE_DIR which is along with the main, cmakelists and build folder not in the actual build folder.
Please explain to me why is that happening and how can I make the archive be created in the CMAKE_CURRENT_SOURCE_DIR and not CMAKE_CURRENT_BINARY_DIR. Thanks.