From f8e57f921d237715107db56d7438b763f22b12da Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne <edward@nmr-relax.com> Date: Sun, 25 Mar 2018 14:29:02 +0200 Subject: [PATCH] CMake: Shifted the FlightGear embedded resources code into its own CMake module. This is for simplifying the main src/Main/CMakeLists.txt file and allowing the code to be shared with the test suite. The generated source and header files have also been removed from the main source list and placed in the CMake module as the global variables EMBEDDED_RESOURCE_SOURCES and EMBEDDED_RESOURCE_HEADERS. --- CMakeModules/SetupFGFSEmbeddedResources.cmake | 29 +++++++++++++++ src/Main/CMakeLists.txt | 37 ++++++++----------- test_suite/CMakeLists.txt | 28 ++++---------- 3 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 CMakeModules/SetupFGFSEmbeddedResources.cmake diff --git a/CMakeModules/SetupFGFSEmbeddedResources.cmake b/CMakeModules/SetupFGFSEmbeddedResources.cmake new file mode 100644 index 000000000..c06887a35 --- /dev/null +++ b/CMakeModules/SetupFGFSEmbeddedResources.cmake @@ -0,0 +1,29 @@ +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}) + + # On Windows, make sure fgrcc can be run (it needs third-party libraries) + if(MSVC) + if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR) + set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin) + else() + message(FATAL_ERROR + "Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset") + endif() + endif() + + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx + ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx + COMMAND fgrcc --root=${CMAKE_SOURCE_DIR} --output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx --init-func-name=initFlightGearEmbeddedResources --output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx --output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml + DEPENDS + fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml + ) +endfunction() diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index 34a5fdce1..9c86605e8 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -1,4 +1,5 @@ # CMake module includes. +include(SetupFGFSEmbeddedResources) include(SetupFGFSLibraries) if(MSVC) @@ -24,7 +25,6 @@ set(SOURCES subsystemFactory.cxx util.cxx ${RESOURCE_FILE} - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx ) set(HEADERS @@ -43,29 +43,16 @@ set(HEADERS screensaver_control.hxx subsystemFactory.hxx util.hxx - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx ) -# On Windows, make sure fgrcc can be run (it needs third-party libraries) -if(MSVC) - if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR) - set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin) - else() - message(FATAL_ERROR - "Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset") - endif() -endif() - -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx - COMMAND fgrcc --root=${CMAKE_SOURCE_DIR} --output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx --init-func-name=initFlightGearEmbeddedResources --output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx --output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml - DEPENDS - fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml -) +# Set up the embedded resources. +setup_fgfs_embedded_resources() +# All sources and headers to be built into fgfs. get_property(FG_SOURCES GLOBAL PROPERTY FG_SOURCES) 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) get_property(FG_GROUPS_C GLOBAL PROPERTY FG_GROUPS_C) string(REPLACE "@" ";" groups ${FG_GROUPS_C} ) @@ -92,8 +79,16 @@ source_group("Main\\Sources" FILES ${SOURCES}) # platforms ignore this option. If a console is needed we allocate # it manually via AllocConsole() # similarly pass MACOSX_BUNDLE so we generate a .app on Mac -add_executable(fgfs WIN32 MACOSX_BUNDLE - ${SOURCES} ${FG_SOURCES} ${FG_HEADERS} ${HEADERS}) +add_executable(fgfs + WIN32 + MACOSX_BUNDLE + ${SOURCES} + ${HEADERS} + ${FG_SOURCES} + ${FG_HEADERS} + ${EMBEDDED_RESOURCE_SOURCES} + ${EMBEDDED_RESOURCE_HEADERS} +) #----------------------------------------------------------------------------- # MacOSX bundle packaging diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 36e6cc6c7..6d6ef34f3 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -1,4 +1,5 @@ # CMake module includes. +include(SetupFGFSEmbeddedResources) include(SetupFGFSLibraries) # Add each test suite category. @@ -100,7 +101,6 @@ set(MAIN_SOURCES ${PROJECT_SOURCE_DIR}/src/Main/subsystemFactory.cxx ${PROJECT_SOURCE_DIR}/src/Main/util.cxx ${RESOURCE_FILE} - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx ) set(MAIN_HEADERS @@ -119,30 +119,16 @@ set(MAIN_HEADERS ${PROJECT_SOURCE_DIR}/src/Main/screensaver_control.hxx ${PROJECT_SOURCE_DIR}/src/Main/subsystemFactory.hxx ${PROJECT_SOURCE_DIR}/src/Main/util.hxx - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx ) -# On Windows, make sure fgrcc can be run (it needs third-party libraries) -if(MSVC) - if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR) - set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin) - else() - message(FATAL_ERROR - "Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset") - endif() -endif() +# Set up the embedded resources. +setup_fgfs_embedded_resources() -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx - ${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx - COMMAND fgrcc --root=${CMAKE_SOURCE_DIR} --output-cpp-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.cxx --init-func-name=initFlightGearEmbeddedResources --output-header-file=${CMAKE_BINARY_DIR}/src/EmbeddedResources/FlightGear-resources.hxx --output-header-identifier=_FG_FLIGHTGEAR_EMBEDDED_RESOURCES ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml - DEPENDS - fgrcc ${CMAKE_SOURCE_DIR}/src/EmbeddedResources/FlightGear-resources.xml -) - -# Get the FG 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_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 up the source groups. get_property(FG_GROUPS_C GLOBAL PROPERTY FG_GROUPS_C) @@ -171,6 +157,8 @@ source_group("Main\\Sources" FILES ${SOURCES}) add_executable(run_test_suite ${FG_SOURCES} ${FG_HEADERS} + ${EMBEDDED_RESOURCE_SOURCES} + ${EMBEDDED_RESOURCE_HEADERS} ${MAIN_SOURCES} ${MAIN_HEADERS} ${TESTSUITE_SOURCES}