From 2663229c23f65852c88889403085d32475eb99da Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Mon, 20 Nov 2017 13:13:09 +0100 Subject: [PATCH] Tune CMakeLists.txt so it builds on linux (well, wsl) --- CMakeLists.txt | 2 ++ Lib7Zip/CMakeLists.txt | 32 ++++++++++++++++++++++++++------ Test7Zip/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 578d9ca..45d387c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(lib7zip) option(LIB7ZIP_BUILD_TESTS "Build tests for lib7zip" OFF) +set(UPSTREAM_DIR ${PROJECT_BINARY_DIR}/upstream-7zip) + add_subdirectory(Lib7Zip) if (LIB7ZIP_BUILD_TESTS) diff --git a/Lib7Zip/CMakeLists.txt b/Lib7Zip/CMakeLists.txt index 87ff98b..1f05d2e 100644 --- a/Lib7Zip/CMakeLists.txt +++ b/Lib7Zip/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.2) project(lib7zip) @@ -6,8 +6,14 @@ set (SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # ==> 7-zip source download start +if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") set(UPSTREAM_SRC_URL http://www.7-zip.org/a/7z1604-src.7z) -set(UPSTREAM_DIR ${PROJECT_BINARY_DIR}/upstream-7zip) +set(UPSTREAM_PATCH_CMD dos2unix ${CMAKE_CURRENT_SOURCE_DIR}/001_avoid_duplicate_guids.patch COMMAND patch --ignore-whitespace --strip 1 < ${CMAKE_CURRENT_SOURCE_DIR}/001_avoid_duplicate_guids.patch COMMAND unix2dos ${UPSTREAM_DIR}/CPP/Windows/FileIO.h) +else() # Windows +set(UPSTREAM_SRC_URL https://downloads.sourceforge.net/project/p7zip/p7zip/16.02/p7zip_16.02_src_all.tar.bz2) +set(UPSTREAM_PATCH_CMD ) +endif() # not Windows + include(ExternalProject) ExternalProject_Add( upstream @@ -16,7 +22,7 @@ ExternalProject_Add( CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" - PATCH_COMMAND dos2unix ${CMAKE_CURRENT_SOURCE_DIR}/001_avoid_duplicate_guids.patch COMMAND patch --ignore-whitespace --strip 1 < ${CMAKE_CURRENT_SOURCE_DIR}/001_avoid_duplicate_guids.patch COMMAND unix2dos ${UPSTREAM_DIR}/CPP/Windows/FileIO.h + PATCH_COMMAND ${UPSTREAM_PATCH_CMD} ) set(UPSTREAM_INCLUDE_DIR ${UPSTREAM_DIR}) @@ -26,6 +32,8 @@ set(UPSTREAM_INCLUDE_DIR ${UPSTREAM_DIR}) include_directories( ${UPSTREAM_INCLUDE_DIR} ${UPSTREAM_INCLUDE_DIR}/CPP + ${UPSTREAM_INCLUDE_DIR}/CPP/myWindows + ${UPSTREAM_INCLUDE_DIR}/CPP/include_windows ) # TODO: includes @@ -45,17 +53,29 @@ set (lib7zip_SOURCES ${SOURCE_DIR}/OSFunctions_UnixLike.cpp ${SOURCE_DIR}/OSFunctions_Win32.cpp ${SOURCE_DIR}/7ZipInStreamWrapper.cpp - - ${UPSTREAM_DIR}/CPP/Common/MyWindows.cpp - ${UPSTREAM_DIR}/CPP/Windows/PropVariant.cpp ) add_library(7zip STATIC ${lib7zip_SOURCES}) add_dependencies(7zip upstream) +set(ADDITIONAL_SOURCES + # this is all a terrible hack, but it lets us get away with + # a regular ExternalProject instead of using a trick like + # https://github.com/Crascit/DownloadProject + -I${UPSTREAM_INCLUDE_DIR} + -I${UPSTREAM_INCLUDE_DIR}/CPP + -I${UPSTREAM_INCLUDE_DIR}/CPP/myWindows + -I${UPSTREAM_INCLUDE_DIR}/CPP/include_windows + ${UPSTREAM_DIR}/CPP/Common/MyWindows.cpp + ${UPSTREAM_DIR}/CPP/Windows/PropVariant.cpp +) +target_link_libraries(7zip ${ADDITIONAL_SOURCES}) + target_compile_options(7zip PRIVATE -std=c++11) if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_link_libraries(7zip -lole32 -loleaut32 -luuid) target_compile_options(7zip PRIVATE -DUNICODE -D_UNICODE) +else() + target_link_libraries(7zip -ldl) endif() # Windows diff --git a/Test7Zip/CMakeLists.txt b/Test7Zip/CMakeLists.txt index 0268a40..842efaf 100644 --- a/Test7Zip/CMakeLists.txt +++ b/Test7Zip/CMakeLists.txt @@ -39,6 +39,18 @@ set(test7ziprar5_SOURCES ${SRC}/Test7ZipRar5.cpp ) +if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") +# nothing to do +message(STATUS "Not adding include_windows") +else() +message(STATUS "Adding include_windows") +include_directories( + # contains a stub "windows.h" among other things + ${UPSTREAM_INCLUDE_DIR}/CPP/include_windows + ${UPSTREAM_INCLUDE_DIR}/CPP/myWindows +) +endif() + add_executable(test7zip ${test7zip_SOURCES}) target_link_libraries(test7zip 7zip)