#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( Unrar VERSION 5.8.5 DESCRIPTION "Popular compression algorithm that beats many older algorithms" ) include("../../BuildSystem/cmake/cplusplus.cmake") set(BUILD_CMD OFF CACHE BOOL "Whether to build a command-line unrar-cmd tool") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/unrarsrc-5.8.5.tar.gz) message(STATUS "Downloading Unrar sources") file( DOWNLOAD https://www.rarlab.com/rar/unrarsrc-5.8.5.tar.gz ${PROJECT_SOURCE_DIR}/downloads/unrarsrc-5.8.5.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=64a290c14640f3bb95acc2954661fe98d55d440c78c39b932926b94082f4f804 ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting Unrar sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/unrarsrc-5.8.5.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/unrar ${PROJECT_SOURCE_DIR}/build ) endif() # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/archive.cpp" "build/arcread.cpp" "build/blake2s.cpp" "build/crypt.cpp" "build/crc.cpp" "build/cmddata.cpp" "build/consio.cpp" "build/extinfo.cpp" "build/extract.cpp" "build/encname.cpp" "build/errhnd.cpp" "build/find.cpp" "build/file.cpp" "build/filefn.cpp" "build/filcreat.cpp" "build/filestr.cpp" "build/global.cpp" "build/getbits.cpp" "build/hash.cpp" "build/headers.cpp" "build/isnt.cpp" "build/list.cpp" "build/match.cpp" "build/options.cpp" "build/pathfn.cpp" "build/qopen.cpp" "build/rdwrfn.cpp" "build/rawread.cpp" "build/rarvm.cpp" "build/recvol.cpp" "build/resource.cpp" "build/rijndael.cpp" "build/rs.cpp" "build/rs16.cpp" "build/secpassword.cpp" "build/scantree.cpp" "build/strlist.cpp" "build/strfn.cpp" "build/system.cpp" "build/sha1.cpp" "build/sha256.cpp" "build/smallfn.cpp" "build/threadpool.cpp" "build/timefn.cpp" "build/unicode.cpp" "build/ui.cpp" "build/unpack.cpp" "build/volume.cpp" ) set( headerFiles "build/archive.hpp" "build/array.hpp" "build/blake2s.hpp" "build/cmddata.hpp" "build/coder.hpp" "build/compress.hpp" "build/consio.hpp" "build/crc.hpp" "build/crypt.hpp" "build/dll.hpp" "build/encname.hpp" "build/errhnd.hpp" "build/extinfo.hpp" "build/extract.hpp" "build/filcreat.hpp" "build/file.hpp" "build/filefn.hpp" "build/filestr.hpp" "build/find.hpp" "build/getbits.hpp" "build/global.hpp" "build/hash.hpp" "build/headers.hpp" "build/headers5.hpp" "build/rartypes.hpp" "build/rarvm.hpp" "build/rawint.hpp" "build/rawread.hpp" "build/rdwrfn.hpp" "build/recvol.hpp" "build/resource.hpp" "build/rijndael.hpp" "build/threadpool.hpp" "build/timefn.hpp" "build/ui.hpp" "build/unicode.hpp" "build/unpack.hpp" "build/version.hpp" "build/volume.hpp" "build/isnt.hpp" "build/rs.hpp" "build/list.hpp" "build/loclang.hpp" "build/log.hpp" "build/match.hpp" "build/model.hpp" "build/options.hpp" "build/os.hpp" "build/pathfn.hpp" "build/qopen.hpp" "build/rar.hpp" "build/rardefs.hpp" "build/rarlang.hpp" "build/raros.hpp" "build/rs16.hpp" "build/savepos.hpp" "build/scantree.hpp" "build/secpassword.hpp" "build/sha1.hpp" "build/sha256.hpp" "build/smallfn.hpp" "build/strfn.hpp" "build/strlist.hpp" "build/suballoc.hpp" "build/system.hpp" ) # ------------------------------------------------------------------------------------------------- add_library(Unrar STATIC) add_library(Unrar::Static ALIAS Unrar) if(${CMAKE_PROJECT_NAME} STREQUAL "Unrar") enable_target_compiler_warnings(Unrar) else() disable_target_compiler_warnings(Unrar) endif() # PUBLIC FILE_OFFSET_BITS=64 used by original Makefile, but it's a dead define # RARDLL disables stand-alone application stuff, it has nothing to do with DLL exports target_compile_definitions( Unrar PRIVATE _LARGEFILE_SOURCE PRIVATE RARDLL ) target_include_directories( Unrar PUBLIC "build" ) target_sources( Unrar PUBLIC ${headerFiles} PRIVATE ${sourceFiles} PRIVATE "build/dll.cpp" ) #set_target_properties(Unrar PROPERTIES PREFIX "") set_target_properties(Unrar PROPERTIES OUTPUT_NAME "unrar") # ------------------------------------------------------------------------------------------------- if(BUILD_CMD) add_executable(Unrar-cmd) if(${CMAKE_PROJECT_NAME} STREQUAL "Unrar") enable_target_compiler_warnings(Unrar-cmd) else() disable_target_compiler_warnings(Unrar-cmd) endif() # PUBLIC FILE_OFFSET_BITS=64 used by original Makefile, but it's a dead define target_compile_definitions( Unrar-cmd PRIVATE _LARGEFILE_SOURCE ) target_include_directories( Unrar-cmd PUBLIC "build" ) target_sources( Unrar-cmd PUBLIC ${headerFiles} PRIVATE ${sourceFiles} PRIVATE "build/rar.cpp" ) #set_target_properties(Unrar-cmd PROPERTIES PREFIX "") set_target_properties(Unrar-cmd PROPERTIES OUTPUT_NAME "unrar-cmd") endif() # ------------------------------------------------------------------------------------------------- install( FILES ${headerFiles} DESTINATION ${PROJECT_SOURCE_DIR}/Include ) install( TARGETS Unrar ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${CMAKE_COMPILER_TAG} ) if(BUILD_CMD) install( TARGETS Unrar-cmd RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/bin/${CMAKE_COMPILER_TAG} ) endif() # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/UnrarConfig.cmake" "#!/usr/bin/cmake # Configuration to include Unrar in a CMake-based project. If you want to # reference Unrar as an externally compiled static library, do this: # # set(Unrar_DIR \"../ThirdParty/unrar\") # find_package(Unrar REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE Unrar::Static # ) # # Alternatively, if you want to build Unrar together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/unrar\" # \"\${CMAKE_BINARY_DIR}/unrar\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE Unrar # ) # # ------------------------------------------------------------------------------------------------- if(NOT DEFINED NUCLEX_COMPILER_TAG) message( FATAL_ERROR \"NUCLEX_COMPILER_TAG not defined! Include cplusplus.cmake before importing this package \\ in order to generate a tag identifying the platform/compiler/architecture/variant!\" ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}\") # TODO: Warn and link release build when compiling in debug mode # TODO: Warn and link build for older compiler version if found message( FATAL_ERROR \"Directory '\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}' not found. \\ Please either build and install this project before importing it via \\ find_package() or use this project's main CMakeFiles.txt via add_subdirectory()!\" ) endif() # ------------------------------------------------------------------------------------------------- add_library(Unrar::Static STATIC IMPORTED) # This may cause warnings on recent GCC versions (10.0.0+?) with LTO because GCC detects # that the headers used during build (residing in build/) are not the same used when # linking the library (copies resising in Include/). # # CMake doesn't run the install step during build, so the only way to get the headers # in place before building would be by copying them rather than installing them. set_target_properties( Unrar::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"C\" ) if(WIN32) set_target_properties( Unrar::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/unrar.lib\" ) else() set_target_properties( Unrar::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libunrar.a\" ) endif() message(STATUS \"Imported Unrar targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------