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:
parent
9d775cdfe7
commit
5dbab6e90e
5 changed files with 130 additions and 54 deletions
|
@ -1,60 +1,137 @@
|
||||||
# ConfigureMsvc3rdParty.cmake - Configure 3rd Party Library Paths on Windows
|
# 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)
|
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)
|
if (CMAKE_CL_64)
|
||||||
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
|
SET(ARCH_SUBDIR_NAME "3rdParty.x64")
|
||||||
else (CMAKE_CL_64)
|
else (CMAKE_CL_64)
|
||||||
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
|
SET(ARCH_SUBDIR_NAME "3rdParty")
|
||||||
endif (CMAKE_CL_64)
|
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")
|
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")
|
list(APPEND PLATFORM_LIBS "winmm.lib")
|
||||||
else (MSVC)
|
else (MSVC)
|
||||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||||
endif (MSVC)
|
endif (MSVC)
|
||||||
|
|
||||||
if (MSVC AND MSVC_3RDPARTY_ROOT)
|
if (MSVC AND _FOUND_3RDPARTY_DIR)
|
||||||
message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
|
message(STATUS "3rdparty files located in ${_FOUND_3RDPARTY_DIR}")
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${_FOUND_3RDPARTY_DIR})
|
||||||
string(SUBSTRING ${MSVC_VERSION} 0 2 MSVC_VERSION_MAJOR)
|
set(FINAL_MSVC_3RDPARTY_DIR ${_FOUND_3RDPARTY_DIR})
|
||||||
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 (CMAKE_CL_64)
|
if (CMAKE_CL_64)
|
||||||
set( OSG_MSVC ${OSG_MSVC}-64 )
|
|
||||||
set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
|
|
||||||
set( BOOST_LIB lib64 )
|
set( BOOST_LIB lib64 )
|
||||||
else (CMAKE_CL_64)
|
else (CMAKE_CL_64)
|
||||||
set( MSVC_3RDPARTY_DIR 3rdParty )
|
|
||||||
set( BOOST_LIB lib )
|
set( BOOST_LIB lib )
|
||||||
endif (CMAKE_CL_64)
|
endif (CMAKE_CL_64)
|
||||||
|
|
||||||
# ensure 3rdparty/lib/cmake is searched
|
if(NOT BOOST_INCLUDEDIR AND _FOUND_BOOST_INCLUDE_DIR)
|
||||||
list(APPEND CMAKE_PREFIX_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR})
|
set(BOOST_INCLUDEDIR ${_FOUND_BOOST_INCLUDE_DIR})
|
||||||
|
message(STATUS "found Boost headers at ${_FOUND_BOOST_INCLUDE_DIR}")
|
||||||
if(NOT BOOST_INCLUDEDIR)
|
endif()
|
||||||
# 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}")
|
|
||||||
endif ()
|
endif ()
|
||||||
endif (MSVC AND MSVC_3RDPARTY_ROOT)
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
function(setup_fgfs_embedded_resources)
|
function(setup_fgfs_embedded_resources)
|
||||||
# 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 (FINAL_MSVC_3RDPARTY_DIR)
|
||||||
set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin PARENT_SCOPE)
|
set(CMAKE_MSVCIDE_RUN_PATH ${FINAL_MSVC_3RDPARTY_DIR}/bin PARENT_SCOPE)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR "FINAL_MSVC_3RDPARTY_DIR is empty or unset")
|
||||||
"Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset")
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
|
@ -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
|
# On Windows, make sure fgrcc can be run (it needs third-party libraries) in add_custom_target
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set_target_properties(fgrcc PROPERTIES DEBUG_POSTFIX d)
|
set_target_properties(fgrcc PROPERTIES DEBUG_POSTFIX d)
|
||||||
if(MSVC_3RDPARTY_ROOT AND MSVC_3RDPARTY_DIR)
|
if (FINAL_MSVC_3RDPARTY_DIR)
|
||||||
set(CMAKE_MSVCIDE_RUN_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/bin)
|
set(CMAKE_MSVCIDE_RUN_PATH ${FINAL_MSVC_3RDPARTY_DIR}/bin)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR "FINAL_MSVC_3RDPARTY_DIR is empty or unset")
|
||||||
"Either MSVC_3RDPARTY_ROOT or MSVC_3RDPARTY_DIR is empty or unset")
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ endif()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
file(TO_NATIVE_PATH "${FG_QT_BIN_DIR}" _qt5_bin_dir_native)
|
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)
|
file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}" _install_bin_dir)
|
||||||
|
|
||||||
set_property(TARGET fgfs PROPERTY
|
set_property(TARGET fgfs PROPERTY
|
||||||
|
|
|
@ -153,7 +153,7 @@ target_link_libraries(fgfs_test_suite ${CPPUNIT_LIBRARIES})
|
||||||
# target to run the tests
|
# target to run the tests
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
file(TO_NATIVE_PATH "${FG_QT_BIN_DIR}" _qt5_bin_dir_native)
|
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)
|
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}")
|
set(CMAKE_MSVCIDE_RUN_PATH "${_install_bin_dir};${_msvc_3rdparty_bin_dir};${_qt5_bin_dir_native}")
|
||||||
|
|
Loading…
Reference in a new issue