Make cmake build fail if old build system was used
This changes makes a cmake build check for an existing versions.h file in the source directory before it builds anything else. If it finds it it will fail the build. This is to prevent confusion when someone tries to use cmake on a source directory where the old build system was used before (as this is not supported).
This commit is contained in:
parent
fd34626009
commit
4a4af6fb2c
|
@ -0,0 +1,11 @@
|
|||
set(error_msg
|
||||
${CMAKE_SOURCE_DIR}/versions.h exists. This usually means that
|
||||
you did run `make` "(the old build system)" in this directory before.
|
||||
This can result in unexpected behavior. run `make clean` in the
|
||||
source directory to continue)
|
||||
if(EXISTS "${FILE}")
|
||||
list(JOIN error_msg " " err)
|
||||
message(FATAL_ERROR "${err}")
|
||||
else()
|
||||
message(STATUS "${FILE} does not exist")
|
||||
endif()
|
|
@ -68,6 +68,24 @@ function(generate_coverage_xml)
|
|||
add_dependencies(${target_name} coverage_${target_name})
|
||||
endfunction()
|
||||
|
||||
# This function asserts that `versions.h` does not exist in the source
|
||||
# directory. It does this in the prebuild phase of the target.
|
||||
# This is an ugly hack that should make sure that cmake isn't used with
|
||||
# a source directory in which FDB was previously built with `make`.
|
||||
function(assert_no_version_h target)
|
||||
|
||||
message(STATUS "Check versions.h on ${target}")
|
||||
set(target_name "${target}_versions_h_check")
|
||||
add_custom_target("${target_name}"
|
||||
COMMAND "${CMAKE_COMMAND}" -DFILE="${CMAKE_SOURCE_DIR}/versions.h"
|
||||
-P "${CMAKE_SOURCE_DIR}/cmake/AssertFileDoesntExist.cmake"
|
||||
COMMAND echo
|
||||
"${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/AssertFileDoesntExist.cmake"
|
||||
-DFILE="${CMAKE_SOURCE_DIR}/versions.h"
|
||||
COMMENT "Check old build system wasn't used in source dir")
|
||||
add_dependencies(${target} ${target_name})
|
||||
endfunction()
|
||||
|
||||
function(add_flow_target)
|
||||
set(options EXECUTABLE STATIC_LIBRARY
|
||||
DYNAMIC_LIBRARY)
|
||||
|
@ -138,6 +156,7 @@ function(add_flow_target)
|
|||
|
||||
add_custom_target(${AFT_NAME}_actors DEPENDS ${generated_files})
|
||||
add_dependencies(${AFT_NAME} ${AFT_NAME}_actors)
|
||||
assert_no_version_h(${AFT_NAME}_actors)
|
||||
generate_coverage_xml(${AFT_NAME})
|
||||
endif()
|
||||
target_include_directories(${AFT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(FDBMONITOR_SRCS ConvertUTF.h SimpleIni.h fdbmonitor.cpp)
|
||||
|
||||
add_executable(fdbmonitor ${FDBMONITOR_SRCS})
|
||||
assert_no_version_h(fdbmonitor)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(fdbmonitor rt)
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue