Skip to content

Commit

Permalink
improve cmake config for mingw; add build.sh wrapper for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
Talv committed Nov 11, 2019
1 parent a3a694b commit b6eded0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
39 changes: 20 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
project(STORMEX)
project(stormex)
cmake_minimum_required(VERSION 2.6)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${STORMEX_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${STORMEX_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${STORMEX_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${stormex_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${stormex_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${stormex_BINARY_DIR}/bin")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

set(default_build_type "Release")
Expand All @@ -24,22 +24,23 @@ set(CMAKE_CXX_FLAGS "-std=c++11")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# link statically with mingw

if (MINGW)
# link statically
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static")
# workaround multiple DllMain definitions from libraries
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition")
endif()

# modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMakeModules")

if (NOT EXISTS "${STORMEX_SOURCE_DIR}/CascLib/CMakeLists.txt")
message(FATAL_ERROR "Missing dependency: CascLib")
endif()

# CascLib
set(CASC_BUILD_STATIC_LIB ON CACHE BOOL "Force Static library building to link test app")
set(CASC_BUILD_SHARED_LIB OFF CACHE BOOL "Compile dynamically linked library")

add_subdirectory(CascLib)

# plog
add_subdirectory(plog)

# stormex
Expand All @@ -49,7 +50,7 @@ set(SRC_FILES
src/cascfuse.cc
src/stormex.cc
)
add_executable(stormex ${SRC_FILES})
add_executable(${PROJECT_NAME} ${SRC_FILES})

# FUSE
if (ENABLE_FUSE)
Expand All @@ -66,20 +67,20 @@ if (ENABLE_FUSE)
endif()

include_directories(${FUSE_INCLUDE_DIR})
target_link_libraries(stormex ${FUSE_NAMES})
target_link_libraries(${PROJECT_NAME} ${FUSE_NAMES})
endif()

include_directories("${STORMEX_SOURCE_DIR}/include/"
"${STORMEX_SOURCE_DIR}/CascLib/src/"
"${STORMEX_SOURCE_DIR}/cxxopts/include/"
"${STORMEX_SOURCE_DIR}/plog/include/"
include_directories("${stormex_SOURCE_DIR}/include/"
"${stormex_SOURCE_DIR}/CascLib/src/"
"${stormex_SOURCE_DIR}/cxxopts/include/"
"${stormex_SOURCE_DIR}/plog/include/"
)

target_link_libraries(stormex casc_static)
target_link_libraries(${PROJECT_NAME} casc_static)

# Set the RPATH
if (APPLE)
set_target_properties(stormex PROPERTIES LINK_FLAGS "-Wl,-rpath,@loader_path/.")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,@loader_path/.")
elseif (UNIX)
set_target_properties(stormex PROPERTIES INSTALL_RPATH ".")
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH ".")
endif()
2 changes: 0 additions & 2 deletions CMakeModules/BuildDokany.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cmake_minimum_required(VERSION 2.8.5)
project(dokanfuse1)
include(GNUInstallDirs)

option(FUSE_PKG_CONFIG "Install a libfuse-compatible pkg-config file (fuse.pc)" ON)
Expand Down
28 changes: 24 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
#!/usr/bin/env bash

if [ "$PWD" != "$(dirname "$(realpath "$0")")" ]; then
echo "Run script from the source directory"
exit;
fi

BUILD_TYPE=${BUILD_TYPE:-RELEASE}
DOKANY_DIR=${DOKANY_DIR:-"../dokany/dokan_fuse"}

for arg in "$@"
do
if [ "$arg" = "--mingw64" ]; then
mkdir -p build-mingw64
cmake -S . -B ./build-mingw64 \
mkdir -p build-mingw64-${BUILD_TYPE,,}
cmake -S . -B ./build-mingw64-${BUILD_TYPE,,} \
-DCMAKE_TOOLCHAIN_FILE=./CMakeModules/Toolchain-mingw64.cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DENABLE_FUSE=1 \
-DFUSE_DIR=../dokany/dokan_fuse
-DFUSE_DIR=$DOKANY_DIR
make -j 4 -C build-mingw64-${BUILD_TYPE,,}

elif [ "$arg" = "--native" ]; then
mkdir -p build-native-${BUILD_TYPE,,}
cmake -S . -B ./build-native-${BUILD_TYPE,,} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DENABLE_FUSE=1
make -j 4 -C build-native-${BUILD_TYPE,,}

elif [ "$arg" = "--clean" ]; then
rm -r build-*

fi
done

0 comments on commit b6eded0

Please sign in to comment.