1
0
Fork 0

CMake: overhaul how we find 3rd-party files

Handle the standard windows-3rd-party setup (used by fgmeta) with no
extra options, and also handle the slightly odd setup we use on Jenkins.
Try to tolerate all permutations of setting MSVC_3RDPARTY_ROOT to 
different places in the hierarchy.

We no longer try to guess Boost_INCLUDEDIR by looking at parent dirs of
MSVC_3RDPARTY_ROOT, since this seemed kind of bad to me. Let’s try 
it and see.
This commit is contained in:
James Turner 2020-08-26 13:57:24 +01:00
parent 9d775cdfe7
commit 5dbab6e90e
5 changed files with 130 additions and 54 deletions

View file

@ -1,60 +1,137 @@
# ConfigureMsvc3rdParty.cmake - Configure 3rd Party Library Paths on Windows
# we want to handle various cases here:
# fgmeta layout, where windows-3rd-party is a sibling of our flightgear source dir
# - this should work with no manual options
# explicitly specifying MSVC_3RDPARTY_ROOT: we'll select a subdir based on MSVC version
# and architecture. We want to allow for people specify various paths here:
# - path to windows-3rd-party
# - path to an MSVC versioned subdir, eg -DMSVC_3RDPARTY_ROOT=C:\FGFS\windows-3rd-party\msvc140
# - path to an architecture specific subdir, eg -DMSVC_3RDPARTY_ROOT=C:\FGFS\windows-3rd-party\msvc140\3rdparty.x64
set(_FOUND_3RDPARTY_DIR "NOTFOUND")
set(_FOUND_BOOST_INCLUDE_DIR "NOTFOUND")
# try various suffixes of a base directory, and
# set the variables above on success
function(_check_candidate_msvc_path pathToCheck)
unset (_freeTypeHeader CACHE )
unset (_zlibDll CACHE )
unset (_boostHeaders CACHE )
find_path(_freeTypeHeader include/ft2build.h
PATHS
${pathToCheck}
PATH_SUFFIXES
${ARCH_SUBDIR_NAME}
${MSVC_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
${COMPAT_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
NO_DEFAULT_PATH
)
find_path(_zlibDll bin/zlib.dll
PATHS
${pathToCheck}
PATH_SUFFIXES
${ARCH_SUBDIR_NAME}
${MSVC_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
${COMPAT_SUBDIR_NAME}/${ARCH_SUBDIR_NAME}
NO_DEFAULT_PATH
)
find_path(_boostHeaders boost/atomic.hpp
PATHS
${pathToCheck}
NO_DEFAULT_PATH
)
# for testing, remove me later.
message(STATUS "Found FreeType header at: ${_freeTypeHeader}")
message(STATUS "Found ZLib DLL at: ${_zlibDll}")
if (_freeTypeHeader AND _zlibDll)
set(_FOUND_3RDPARTY_DIR "${_freeTypeHeader}" PARENT_SCOPE)
if (_boostHeaders)
set(_FOUND_BOOST_INCLUDE_DIR "${_boostHeaders}" PARENT_SCOPE)
endif()
endif()
endfunction()
if (MSVC)
get_filename_component(PARENT_DIR ${PROJECT_BINARY_DIR} DIRECTORY)
# compute values for the compiler and arch subdirs
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
string(SUBSTRING ${MSVC_VERSION} 2 2 MSVC_VERSION_MINOR)
if (${MSVC_VERSION_MAJOR} EQUAL "19")
if (${MSVC_VERSION_MINOR} EQUAL "00")
set( MSVC_SUBDIR_NAME msvc140 )
else ()
set( MSVC_SUBDIR_NAME msvc141 )
set( COMPAT_SUBDIR_NAME msvc140 )
endif()
else ()
message(FATAL_ERROR "Visual Studio 2017 is required")
endif ()
if (CMAKE_CL_64)
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
SET(ARCH_SUBDIR_NAME "3rdParty.x64")
else (CMAKE_CL_64)
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
SET(ARCH_SUBDIR_NAME "3rdParty")
endif (CMAKE_CL_64)
if (EXISTS ${TEST_3RDPARTY_DIR})
set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
else (EXISTS ${TEST_3RDPARTY_DIR})
# try the explicitly specified value first
if (EXISTS ${MSVC_3RDPARTY_ROOT})
_check_candidate_msvc_path("${MSVC_3RDPARTY_ROOT}")
endif()
# then try the fgmeta setup: look for a windows-3rdparty sibling of
# our source dir
get_filename_component(PARENT_SOURCE_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
get_filename_component(PARENT_BINARY_DIR ${PROJECT_BINARY_DIR} DIRECTORY)
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_SOURCE_DIR}/windows-3rd-party")
message(STATUS "Trying src 3rdparty")
_check_candidate_msvc_path("${PARENT_SOURCE_DIR}/windows-3rd-party")
endif()
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_BINARY_DIR}/windows-3rd-party")
message(STATUS "Trying bin 3rdparty")
_check_candidate_msvc_path("${PARENT_BINARY_DIR}/windows-3rd-party")
endif()
# try the Jenkins setup, whre the arch dir is copied into the WORKSPACE
if (NOT _FOUND_3RDPARTY_DIR AND EXISTS "${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
message(STATUS "Trying arch subdir ${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
_check_candidate_msvc_path("${PARENT_BINARY_DIR}/${ARCH_SUBDIR_NAME}")
endif()
if (NOT _FOUND_3RDPARTY_DIR)
message(WARNING "Failed to find the Windows 3rdparty files at all.")
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
endif (EXISTS ${TEST_3RDPARTY_DIR})
endif()
list(APPEND PLATFORM_LIBS "winmm.lib")
else (MSVC)
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
endif (MSVC)
if (MSVC AND MSVC_3RDPARTY_ROOT)
message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
string(SUBSTRING ${MSVC_VERSION} 2 2 MSVC_VERSION_MINOR)
set( OSG_MSVC "msvc" )
if (${MSVC_VERSION_MAJOR} EQUAL "19")
if (${MSVC_VERSION_MINOR} EQUAL "00")
set( OSG_MSVC ${OSG_MSVC}140 )
else ()
set( OSG_MSVC ${OSG_MSVC}141 )
endif ()
elseif (${MSVC_VERSION_MAJOR} EQUAL "18")
set( OSG_MSVC ${OSG_MSVC}120 )
else ()
message(FATAL_ERROR "Visual Studio 2013/15/17 is required")
endif ()
if (MSVC AND _FOUND_3RDPARTY_DIR)
message(STATUS "3rdparty files located in ${_FOUND_3RDPARTY_DIR}")
list(APPEND CMAKE_PREFIX_PATH ${_FOUND_3RDPARTY_DIR})
set(FINAL_MSVC_3RDPARTY_DIR ${_FOUND_3RDPARTY_DIR})
if (CMAKE_CL_64)
set( OSG_MSVC ${OSG_MSVC}-64 )
set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
set( BOOST_LIB lib64 )
else (CMAKE_CL_64)
set( MSVC_3RDPARTY_DIR 3rdParty )
set( BOOST_LIB lib )
endif (CMAKE_CL_64)
# ensure 3rdparty/lib/cmake is searched
list(APPEND CMAKE_PREFIX_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR})
if(NOT BOOST_INCLUDEDIR)
# if this variable was not set by the user, set it to 3rdparty root's
# parent dir, which is the normal location for people using our
# windows-3rd-party repo
get_filename_component(MSVC_ROOT_PARENT_DIR ${MSVC_3RDPARTY_ROOT}
DIRECTORY)
set(BOOST_INCLUDEDIR ${MSVC_ROOT_PARENT_DIR})
message(STATUS "BOOST_INCLUDEDIR is ${BOOST_INCLUDEDIR}")
if(NOT BOOST_INCLUDEDIR AND _FOUND_BOOST_INCLUDE_DIR)
set(BOOST_INCLUDEDIR ${_FOUND_BOOST_INCLUDE_DIR})
message(STATUS "found Boost headers at ${_FOUND_BOOST_INCLUDE_DIR}")
endif()
endif ()
endif (MSVC AND MSVC_3RDPARTY_ROOT)

View file

@ -1,11 +1,11 @@
function(setup_fgfs_embedded_resources)
# 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 PARENT_SCOPE)
if (FINAL_MSVC_3RDPARTY_DIR)
set(CMAKE_MSVCIDE_RUN_PATH ${FINAL_MSVC_3RDPARTY_DIR}/bin PARENT_SCOPE)
else()
message(FATAL_ERROR
"Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset")
message(FATAL_ERROR "FINAL_MSVC_3RDPARTY_DIR is empty or unset")
endif()
endif()
endfunction()

View file

@ -4,11 +4,10 @@ target_link_libraries(fgrcc SimGearCore)
# On Windows, make sure fgrcc can be run (it needs third-party libraries) in add_custom_target
if(MSVC)
set_target_properties(fgrcc PROPERTIES DEBUG_POSTFIX d)
if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR)
set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin)
if (FINAL_MSVC_3RDPARTY_DIR)
set(CMAKE_MSVCIDE_RUN_PATH ${FINAL_MSVC_3RDPARTY_DIR}/bin)
else()
message(FATAL_ERROR
"Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset")
message(FATAL_ERROR "FINAL_MSVC_3RDPARTY_DIR is empty or unset")
endif()
endif()

View file

@ -118,7 +118,7 @@ endif()
if (MSVC)
file(TO_NATIVE_PATH "${FG_QT_BIN_DIR}" _qt5_bin_dir_native)
file(TO_NATIVE_PATH "${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin" _msvc_3rdparty_bin_dir)
file(TO_NATIVE_PATH "${FINAL_MSVC_3RDPARTY_DIR}/bin" _msvc_3rdparty_bin_dir)
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}" _install_bin_dir)
set_property(TARGET fgfs PROPERTY

View file

@ -153,7 +153,7 @@ target_link_libraries(fgfs_test_suite ${CPPUNIT_LIBRARIES})
# target to run the tests
if (MSVC)
file(TO_NATIVE_PATH "${FG_QT_BIN_DIR}" _qt5_bin_dir_native)
file(TO_NATIVE_PATH "${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin" _msvc_3rdparty_bin_dir)
file(TO_NATIVE_PATH "${FINAL_MSVC_3RDPARTY_DIR}/bin" _msvc_3rdparty_bin_dir)
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}" _install_bin_dir)
set(CMAKE_MSVCIDE_RUN_PATH "${_install_bin_dir};${_msvc_3rdparty_bin_dir};${_qt5_bin_dir_native}")