Embedded resources: better cmake command
Use add_custom_command and an intermediate OBJECT library to avoid rerunning fgrcc unless the XML input file has actually changed.
This commit is contained in:
parent
eb55f25997
commit
218df89b29
5 changed files with 22 additions and 38 deletions
CMakeModules
src
test_suite
|
@ -1,21 +1,4 @@
|
||||||
function(setup_fgfs_embedded_resources)
|
function(setup_fgfs_embedded_resources)
|
||||||
# The source and header files.
|
|
||||||
set(SOURCES
|
|
||||||
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
|
||||||
)
|
|
||||||
set(HEADERS
|
|
||||||
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
|
|
||||||
)
|
|
||||||
set_property(GLOBAL APPEND PROPERTY EMBEDDED_RESOURCE_SOURCES ${SOURCES})
|
|
||||||
set_property(GLOBAL APPEND PROPERTY EMBEDDED_RESOURCE_HEADERS ${HEADERS})
|
|
||||||
|
|
||||||
# set the flag for CMake policy 00071, ensure Qt AUTOfoo don't process
|
|
||||||
# generated files
|
|
||||||
foreach(sourcefile IN LISTS ${SOURCES} ${HEADERS})
|
|
||||||
set_property(SOURCE ${sourcefile} PROPERTY SKIP_AUTOMOC ON)
|
|
||||||
set_property(SOURCE ${sourcefile} PROPERTY SKIP_AUTOUIC ON)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# On Windows, make sure fgrcc can be run (it needs third-party libraries)
|
# On Windows, make sure fgrcc can be run (it needs third-party libraries)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR)
|
if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR)
|
||||||
|
|
|
@ -26,7 +26,7 @@ function(setup_fgfs_libraries target)
|
||||||
target_link_libraries(${target} ${X11_LIBRARIES})
|
target_link_libraries(${target} ${X11_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${target} fgsqlite3 fgvoicesynth)
|
target_link_libraries(${target} fgsqlite3 fgvoicesynth fgembeddedresources)
|
||||||
|
|
||||||
target_link_libraries(${target}
|
target_link_libraries(${target}
|
||||||
SimGearCore
|
SimGearCore
|
||||||
|
|
|
@ -12,8 +12,7 @@ if(MSVC)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_command(
|
||||||
embeddedresources
|
|
||||||
COMMAND
|
COMMAND
|
||||||
fgrcc --root=${CMAKE_SOURCE_DIR}
|
fgrcc --root=${CMAKE_SOURCE_DIR}
|
||||||
--output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
--output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
||||||
|
@ -21,9 +20,25 @@ add_custom_target(
|
||||||
--output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
|
--output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
|
||||||
--output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES
|
--output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES
|
||||||
${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
|
${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
|
||||||
BYPRODUCTS
|
OUTPUT
|
||||||
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
||||||
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
|
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx
|
||||||
DEPENDS
|
MAIN_DEPENDENCY
|
||||||
fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
|
fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml
|
||||||
|
COMMENT
|
||||||
|
"Re-generating embedded resources"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# set automatically by add_custom_command?
|
||||||
|
#set_source_files_properties(${EMBEDDED_RESOURCE_SOURCES} PROPERTIES GENERATED TRUE)
|
||||||
|
#set_source_files_properties(${EMBEDDED_RESOURCE_HEADERS} PROPERTIES GENERATED TRUE)
|
||||||
|
|
||||||
|
add_library(fgembeddedresources OBJECT
|
||||||
|
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx
|
||||||
|
${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx)
|
||||||
|
|
||||||
|
target_link_libraries(fgembeddedresources SimGearCore)
|
||||||
|
|
||||||
|
# don't try to Automoc these files, it confuses the dependency logic
|
||||||
|
set_property(TARGET fgembeddedresources PROPERTY AUTOMOC OFF)
|
||||||
|
|
||||||
|
|
|
@ -71,11 +71,6 @@ setup_msvc_grouping()
|
||||||
# All sources and headers to be built into fgfs.
|
# All sources and headers to be built into fgfs.
|
||||||
get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
|
get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
|
||||||
get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS)
|
get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS)
|
||||||
get_property(EMBEDDED_RESOURCE_SOURCES GLOBAL PROPERTY EMBEDDED_RESOURCE_SOURCES)
|
|
||||||
get_property(EMBEDDED_RESOURCE_HEADERS GLOBAL PROPERTY EMBEDDED_RESOURCE_HEADERS)
|
|
||||||
|
|
||||||
set_source_files_properties(${EMBEDDED_RESOURCE_SOURCES} PROPERTIES GENERATED TRUE)
|
|
||||||
set_source_files_properties(${EMBEDDED_RESOURCE_HEADERS} PROPERTIES GENERATED TRUE)
|
|
||||||
|
|
||||||
# important we pass WIN32 here so the console is optional. Other
|
# important we pass WIN32 here so the console is optional. Other
|
||||||
# platforms ignore this option. If a console is needed we allocate
|
# platforms ignore this option. If a console is needed we allocate
|
||||||
|
@ -87,11 +82,9 @@ add_executable(fgfs
|
||||||
${MAIN_SOURCE}
|
${MAIN_SOURCE}
|
||||||
${FG_SOURCES}
|
${FG_SOURCES}
|
||||||
${FG_HEADERS}
|
${FG_HEADERS}
|
||||||
${EMBEDDED_RESOURCE_SOURCES}
|
|
||||||
${EMBEDDED_RESOURCE_HEADERS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(fgfs buildId embeddedresources)
|
add_dependencies(fgfs buildId)
|
||||||
# explicitly disable automoc for main fgfs target
|
# explicitly disable automoc for main fgfs target
|
||||||
set_property(TARGET fgfs PROPERTY AUTOMOC OFF)
|
set_property(TARGET fgfs PROPERTY AUTOMOC OFF)
|
||||||
|
|
||||||
|
|
|
@ -116,23 +116,16 @@ setup_msvc_grouping()
|
||||||
# All sources and headers to be built into the test suite.
|
# All sources and headers to be built into the test suite.
|
||||||
get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
|
get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES)
|
||||||
get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS)
|
get_property(FG_HEADERS GLOBAL PROPERTY FG_HEADERS)
|
||||||
get_property(EMBEDDED_RESOURCE_SOURCES GLOBAL PROPERTY EMBEDDED_RESOURCE_SOURCES)
|
|
||||||
get_property(EMBEDDED_RESOURCE_HEADERS GLOBAL PROPERTY EMBEDDED_RESOURCE_HEADERS)
|
|
||||||
|
|
||||||
set_source_files_properties(${EMBEDDED_RESOURCE_SOURCES} PROPERTIES GENERATED TRUE)
|
|
||||||
set_source_files_properties(${EMBEDDED_RESOURCE_HEADERS} PROPERTIES GENERATED TRUE)
|
|
||||||
|
|
||||||
# Set up the separate executable for running the test suite.
|
# Set up the separate executable for running the test suite.
|
||||||
add_executable(fgfs_test_suite
|
add_executable(fgfs_test_suite
|
||||||
${FG_SOURCES}
|
${FG_SOURCES}
|
||||||
${FG_HEADERS}
|
${FG_HEADERS}
|
||||||
${EMBEDDED_RESOURCE_SOURCES}
|
|
||||||
${EMBEDDED_RESOURCE_HEADERS}
|
|
||||||
${TESTSUITE_SOURCES}
|
${TESTSUITE_SOURCES}
|
||||||
${TESTSUITE_HEADERS}
|
${TESTSUITE_HEADERS}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(fgfs_test_suite buildId embeddedresources)
|
add_dependencies(fgfs_test_suite buildId)
|
||||||
set_target_properties(fgfs_test_suite
|
set_target_properties(fgfs_test_suite
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${TESTSUITE_OUTPUT_DIR}"
|
RUNTIME_OUTPUT_DIRECTORY "${TESTSUITE_OUTPUT_DIR}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue