[build] Fix RPATH in linux when building shared library and some problems with visual studio

This commit is contained in:
Marko Viitanen 2022-04-29 10:49:17 +03:00
parent f694a63cc0
commit 3abf6c4b3b
3 changed files with 26 additions and 11 deletions

View file

@ -7,7 +7,7 @@ test-kvazaar: &test-template
script: script:
- bash .travis-install.bash - bash .travis-install.bash
- export PATH="${HOME}/bin:${PATH}" - export PATH="${HOME}/bin:${PATH}"
- cmake -DUSE_SHARED_LIB=OFF -DCMAKE_INSTALL_PREFIX=./ . || (cat config.log && false) - cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=./ . || (cat config.log && false)
- make install - make install
- env CTEST_PARALLEL_LEVEL=8 CTEST_OUTPUT_ON_FAILURE=1 make test - env CTEST_PARALLEL_LEVEL=8 CTEST_OUTPUT_ON_FAILURE=1 make test
artifacts: artifacts:

View file

@ -10,7 +10,7 @@ VERSION 0.2.3 )
configure_file("${PROJECT_SOURCE_DIR}/src/uvg266.pc.in" "${PROJECT_SOURCE_DIR}/src/uvg266.pc" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/src/uvg266.pc.in" "${PROJECT_SOURCE_DIR}/src/uvg266.pc" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_SOURCE_DIR}/src/version.h" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/src/version.h.in" "${PROJECT_SOURCE_DIR}/src/version.h" @ONLY)
option(USE_SHARED_LIB "Build using shared uvg266 library" ON) option(BUILD_SHARED_LIBS "Build using shared uvg266 library" ON)
find_package(Git QUIET) find_package(Git QUIET)
@ -49,8 +49,10 @@ list(APPEND LIB_SOURCES ${LIB_SOURCES_STRATEGIES})
# We also need the libmd5 # We also need the libmd5
list(APPEND LIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/extras/libmd5.c) list(APPEND LIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/extras/libmd5.c)
if(NOT USE_SHARED_LIB) add_definitions(-DUVG_DLL_EXPORTS)
add_definitions(-DPIC -DKVZ_DLL_EXPORTS)
if(BUILD_SHARED_LIBS)
add_definitions(-DPIC)
endif() endif()
# For visual studio / windows we also need our own pthread implementation and getopt # For visual studio / windows we also need our own pthread implementation and getopt
@ -62,10 +64,16 @@ endif()
# ToDo: allow compiling on other than x86 # ToDo: allow compiling on other than x86
add_definitions(-DCOMPILE_INTEL) add_definitions(-DCOMPILE_INTEL)
if(USE_SHARED_LIB) if(BUILD_SHARED_LIBS)
list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" "./" "../lib" )
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_library(uvg266 SHARED ${LIB_SOURCES}) add_library(uvg266 SHARED ${LIB_SOURCES})
else() else()
add_library(uvg266 STATIC ${LIB_SOURCES}) add_library(uvg266 STATIC ${LIB_SOURCES})
if(MSVC) # Fix a linking problem with visual studio when the library is the same name as the binary
set_target_properties(uvg266 PROPERTIES OUTPUT_NAME libuvg266)
endif()
endif() endif()
target_include_directories(uvg266 PUBLIC src) target_include_directories(uvg266 PUBLIC src)
@ -83,10 +91,11 @@ endif()
add_executable(uvg266-bin ${CLI_SOURCES}) add_executable(uvg266-bin ${CLI_SOURCES})
target_link_libraries(uvg266-bin PUBLIC uvg266)
set_target_properties(uvg266-bin PROPERTIES OUTPUT_NAME uvg266) set_target_properties(uvg266-bin PROPERTIES OUTPUT_NAME uvg266)
set_target_properties(uvg266-bin PROPERTIES RUNTIME_OUTPUT_NAME uvg266) set_target_properties(uvg266-bin PROPERTIES RUNTIME_OUTPUT_NAME uvg266)
target_link_libraries(uvg266-bin PUBLIC uvg266)
if(MSVC) if(MSVC)
target_include_directories(uvg266 PUBLIC src/threadwrapper/include) target_include_directories(uvg266 PUBLIC src/threadwrapper/include)
@ -115,8 +124,10 @@ endif()
install(FILES ${PROJECT_SOURCE_DIR}/src/uvg266.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig) install(FILES ${PROJECT_SOURCE_DIR}/src/uvg266.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig)
install(TARGETS uvg266-bin DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS uvg266-bin DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS uvg266 DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) install(TARGETS uvg266 DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
if(USE_SHARED_LIB) # Just add the lib to the bin directory for now if(BUILD_SHARED_LIBS) # Just add the lib to the bin directory for now
install(TARGETS uvg266 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) if(MSVC)
install(TARGETS uvg266 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif()
endif() endif()
install(FILES ${PROJECT_SOURCE_DIR}/src/uvg266.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) install(FILES ${PROJECT_SOURCE_DIR}/src/uvg266.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(FILES ${PROJECT_SOURCE_DIR}/doc/uvg266.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man) install(FILES ${PROJECT_SOURCE_DIR}/doc/uvg266.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man)

View file

@ -9,12 +9,16 @@ target_include_directories(uvg266_tests PUBLIC ${PROJECT_SOURCE_DIR})
target_include_directories(uvg266_tests PUBLIC ${PROJECT_SOURCE_DIR}/src) target_include_directories(uvg266_tests PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_include_directories(uvg266_tests PUBLIC ${PROJECT_SOURCE_DIR}/src/extras) target_include_directories(uvg266_tests PUBLIC ${PROJECT_SOURCE_DIR}/src/extras)
if(USE_SHARED_LIB) add_definitions(-DUVG_DLL_EXPORTS)
message(INFO " tests do not work with shared lib at the moment")
add_definitions(-DPIC -DKVZ_DLL_EXPORTS) if(BUILD_SHARED_LIBS)
add_definitions(-DPIC)
endif() endif()
if(MSVC) if(MSVC)
if(BUILD_SHARED_LIBS)
message(INFO " tests do not work with shared lib at the moment")
endif()
target_include_directories(uvg266_tests PUBLIC ../src/threadwrapper/include) target_include_directories(uvg266_tests PUBLIC ../src/threadwrapper/include)
set_property( SOURCE ${TEST_SOURCES} APPEND PROPERTY COMPILE_FLAGS "/arch:AVX2" ) set_property( SOURCE ${TEST_SOURCES} APPEND PROPERTY COMPILE_FLAGS "/arch:AVX2" )