mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-12 07:49:01 +08:00
CMake: install draco.dll in bin folder (#838)
Fix windows DLL install location and update the install test with the following - Use cxx_std_11 compile feature instead of forcing CXX_STANDARD to C++11. - Move install test prefix handling to test.py (was in the install test CMakeLists.txt). - Use CMAKE_INSTALL_RPATH and add dylib location to PATH instead of copying it only on Windows-- makes test more generic and makes install_test much simpler.
This commit is contained in:
parent
60af0ba480
commit
a737103f52
@ -1,11 +1,6 @@
|
||||
@PACKAGE_INIT@
|
||||
set_and_check(DRACO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
|
||||
set_and_check(DRACO_LIBRARY_DIR "@CMAKE_INSTALL_FULL_LIBDIR@")
|
||||
set(DRACO_NAMES
|
||||
draco.dll libdraco.dylib libdraco.so draco.lib libdraco.dll libdraco.a)
|
||||
find_library(_DRACO_LIBRARY PATHS ${DRACO_LIBRARY_DIR} NAMES ${DRACO_NAMES})
|
||||
find_library(_DRACO_LIBRARY PATHS ${DRACO_LIBRARY_DIR} NAMES draco)
|
||||
set_and_check(DRACO_LIBRARY ${_DRACO_LIBRARY})
|
||||
find_file(DRACO_LIBRARY_DLL
|
||||
PATHS ${DRACO_LIBRARY_DIR}
|
||||
NAMES draco.dll libdraco.dll)
|
||||
set(DRACO_FOUND YES)
|
||||
|
@ -84,12 +84,20 @@ macro(draco_setup_install_target)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
install(TARGETS draco DESTINATION "${libs_path}")
|
||||
install(
|
||||
TARGETS draco
|
||||
RUNTIME DESTINATION "${bin_path}"
|
||||
ARCHIVE DESTINATION "${libs_path}"
|
||||
LIBRARY DESTINATION "${libs_path}")
|
||||
else()
|
||||
install(TARGETS draco_static DESTINATION "${libs_path}")
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS draco_shared DESTINATION "${libs_path}")
|
||||
install(
|
||||
TARGETS draco_shared
|
||||
RUNTIME DESTINATION "${bin_path}"
|
||||
ARCHIVE DESTINATION "${libs_path}"
|
||||
LIBRARY DESTINATION "${libs_path}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -12,45 +12,18 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(install_test C CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Tell find_package() where Draco is installed.
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(CMAKE_PREFIX_PATH
|
||||
"${CMAKE_CURRENT_LIST_DIR}/_draco_install_shared")
|
||||
else()
|
||||
set(CMAKE_PREFIX_PATH
|
||||
"${CMAKE_CURRENT_LIST_DIR}/_draco_install_static")
|
||||
endif()
|
||||
|
||||
find_package(draco REQUIRED)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
# Add rpath to resolve dylib dependency on Linux/MacOS.
|
||||
list(APPEND CMAKE_BUILD_RPATH "${DRACO_LIBRARY_DIR}")
|
||||
list(APPEND CMAKE_INSTALL_RPATH "${DRACO_LIBRARY_DIR}")
|
||||
endif()
|
||||
|
||||
list(APPEND install_test_sources "main.cc")
|
||||
add_executable(install_check ${install_test_sources})
|
||||
find_package(draco REQUIRED CONFIG)
|
||||
|
||||
add_executable(install_check main.cc)
|
||||
# Update include paths and dependencies to allow for successful build of the
|
||||
# install_check target using Draco as configured for the current installation.
|
||||
target_include_directories(install_check PUBLIC "${DRACO_INCLUDE_DIR}")
|
||||
target_link_libraries(install_check "${DRACO_LIBRARY}")
|
||||
target_compile_features(install_check PRIVATE cxx_std_11)
|
||||
|
||||
install(TARGETS install_check DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
|
||||
|
||||
if(BUILD_SHARED_LIBS AND WIN32)
|
||||
# Copy the Draco DLL into the bin dir for Windows: Windows does not really
|
||||
# have a concept of rpath, but it does look in the current directory by
|
||||
# default when a program tries to load a DLL.
|
||||
install(FILES "${DRACO_LIBRARY_DLL}"
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
|
||||
endif()
|
||||
install(TARGETS install_check DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -61,6 +61,10 @@ DRACO_SHARED_INSTALL_PATH = os.path.join(TEST_SOURCES_PATH,
|
||||
DRACO_STATIC_INSTALL_PATH = os.path.join(TEST_SOURCES_PATH,
|
||||
'_draco_install_static')
|
||||
|
||||
DRACO_SHARED_INSTALL_BIN_PATH = os.path.join(DRACO_SHARED_INSTALL_PATH, 'bin')
|
||||
|
||||
DRACO_SHARED_INSTALL_LIB_PATH = os.path.join(DRACO_SHARED_INSTALL_PATH, 'lib')
|
||||
|
||||
# Argument for -j when using make, or -m when using Visual Studio. Number of
|
||||
# build jobs.
|
||||
NUM_PROCESSES = multiprocessing.cpu_count() - 1
|
||||
@ -243,7 +247,11 @@ def run_install_check(install_path):
|
||||
if VERBOSE:
|
||||
print(f'RUN command: {cmd}')
|
||||
|
||||
result = run_process_and_capture_output(cmd)
|
||||
result = run_process_and_capture_output(
|
||||
cmd,
|
||||
# On Windows, add location of draco.dll into PATH env var
|
||||
{"PATH": DRACO_SHARED_INSTALL_BIN_PATH + os.pathsep + os.environ["PATH"]},
|
||||
)
|
||||
if result[0] != 0:
|
||||
raise Exception(
|
||||
f'install_check run failed!\nexit_code: {result[0]}\n{result[1]}')
|
||||
@ -366,20 +374,21 @@ def build_test_project():
|
||||
"""Builds the test application in shared and static configurations."""
|
||||
orig_dir = os.getcwd()
|
||||
|
||||
# Configure the test project in shared mode and build it.
|
||||
# Configure the test project against draco shared and build it.
|
||||
os.chdir(TEST_SHARED_BUILD_PATH)
|
||||
cmake_args = []
|
||||
cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={TEST_SHARED_INSTALL_PATH}')
|
||||
cmake_args.append('-DBUILD_SHARED_LIBS=ON')
|
||||
cmake_args.append(f'-DCMAKE_PREFIX_PATH={DRACO_SHARED_INSTALL_PATH}')
|
||||
cmake_args.append(f'-DCMAKE_INSTALL_RPATH={DRACO_SHARED_INSTALL_LIB_PATH}')
|
||||
cmake_configure(source_path=f'{TEST_SOURCES_PATH}', cmake_args=cmake_args)
|
||||
cmake_build(cmake_args=['--target install'])
|
||||
run_install_check(TEST_SHARED_INSTALL_PATH)
|
||||
|
||||
# Configure in static mode and build it.
|
||||
# Configure the test project against draco static and build it.
|
||||
os.chdir(TEST_STATIC_BUILD_PATH)
|
||||
cmake_args = []
|
||||
cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={TEST_STATIC_INSTALL_PATH}')
|
||||
cmake_args.append('-DBUILD_SHARED_LIBS=OFF')
|
||||
cmake_args.append(f'-DCMAKE_PREFIX_PATH={DRACO_STATIC_INSTALL_PATH}')
|
||||
cmake_configure(source_path=f'{TEST_SOURCES_PATH}', cmake_args=cmake_args)
|
||||
cmake_build(cmake_args=['--target install'])
|
||||
run_install_check(TEST_STATIC_INSTALL_PATH)
|
||||
|
Loading…
x
Reference in New Issue
Block a user