Skip to content

Commit

Permalink
Tune CMakeLists.txt so it builds on linux (well, wsl)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Nov 20, 2017
1 parent 576e86e commit 2663229
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 26 additions & 6 deletions Lib7Zip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.2)

project(lib7zip)

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
Expand All @@ -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})
Expand All @@ -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
Expand All @@ -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
12 changes: 12 additions & 0 deletions Test7Zip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2663229

Please sign in to comment.