Skip to content

Commit

Permalink
[cmake] Fix export-files when building in-source
Browse files Browse the repository at this point in the history
In-source builds were broken due to a mistake in the export-files
logic. Even though this commit resolves the problem, it is recommended
building out-of-source.
  • Loading branch information
fetzerch committed Jul 7, 2016
1 parent bd89024 commit bfb7355
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions project/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ set(CORE_BUILD_DIR build)

message(STATUS "Source directory: ${CORE_SOURCE_DIR}")
message(STATUS "Build directory: ${CMAKE_BINARY_DIR}")
if(CMAKE_BINARY_DIR STREQUAL CORE_SOURCE_DIR)
message(WARNING "In-source build detected. It is recommended to build out-of-source.")
endif()

include(modules/extra/ECMEnableSanitizers.cmake)
include(scripts/common/GeneratorSetup.cmake)
Expand Down
16 changes: 10 additions & 6 deletions project/cmake/scripts/common/Macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ function(copy_file_to_buildtree file relative)
string(REPLACE "${relative}/" "" outfile ${file})
get_filename_component(outdir ${outfile} DIRECTORY)

if(NOT TARGET export-files)
file(REMOVE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
add_custom_target(export-files ALL COMMENT "Copying files into build tree"
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
endif()
if(NOT ${CORE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR})
if(NOT CMAKE_BINARY_DIR STREQUAL CORE_SOURCE_DIR)
if(NOT TARGET export-files)
file(REMOVE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
add_custom_target(export-files ALL COMMENT "Copying files into build tree"
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake)
endif()
if(VERBOSE)
message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_BINARY_DIR}/${outfile}")
endif()
file(APPEND ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake
"file(COPY \"${file}\" DESTINATION \"${CMAKE_BINARY_DIR}/${outdir}\")\n")
else()
if(NOT TARGET export-files)
add_custom_target(export-files ALL)
endif()
endif()
if(NOT arg_NO_INSTALL)
list(APPEND install_data ${outfile})
Expand Down

0 comments on commit bfb7355

Please sign in to comment.