Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
static link msvc runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Apr 26, 2020
1 parent 07bc8c7 commit ade1f49
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
66 changes: 36 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
option(BUILD_TEST "build test" OFF)

if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "")
# FIXME: This block should go away after a transition period.
if(NOT CMAKE_VERSION VERSION_LESS 3.15)
# Filter out MSVC runtime library flags that may have come from the cache of an existing build tree or from scripts.
foreach(l C CXX)
foreach(c DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
string(REGEX REPLACE "[-/]M[DT]d?( |$)" "" "CMAKE_${l}_FLAGS_${c}" "${CMAKE_${l}_FLAGS_${c}}")
endforeach()
endforeach()
endif()
# http://stackoverflow.com/a/32128977/486990
add_compile_options(
"$<$<CONFIG:Debug>:/MTd>" # -MTd
"$<$<CONFIG:RelWithDebInfo>:/MT>" # -MT
"$<$<CONFIG:Release>:/MT>" # * MT
"$<$<CONFIG:MinSizeRel>:/MT>")
add_compile_options("-D_CRT_SECURE_NO_WARNINGS=1")
add_compile_options("-utf-8")
add_compile_options("-permissive-")
add_compile_options("-Zc:__cplusplus")
add_compile_options("-DUNICODE=1")
add_compile_options("-D_UNICODE=1")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -c65001")
else()
add_compile_options("-g")
add_compile_options("-Wall")
add_compile_options("-Wextra")
if(USE_SANITIZE)
add_compile_options("-fsanitize=address")
add_compile_options("-fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ")
endif()
endif()

set(BAULKTAR_VERSION_MAJOR 1)
set(BAULKTAR_VERSION_MINOR 0)
set(BAULKTAR_VERSION_PATCH 0)
Expand Down Expand Up @@ -51,38 +86,9 @@ if(lto_supported)
endif()
endif()

if(MSVC)
add_compile_options("-D_CRT_SECURE_NO_WARNINGS=1")
add_compile_options("-utf-8")
add_compile_options("-permissive-")
add_compile_options("-Zc:__cplusplus")
add_compile_options("-DUNICODE=1")
add_compile_options("-D_UNICODE=1")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -c65001")
set(WIN_COMPILER_FLAGS
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE)
foreach(WIN_COMPILER_FLAG ${WIN_COMPILER_FLAGS})
string(REPLACE "/MD" "/MT" ${WIN_COMPILER_FLAG} "${${WIN_COMPILER_FLAG}}")
endforeach()
else()
add_compile_options("-g")
add_compile_options("-Wall")
add_compile_options("-Wextra")
if(USE_SANITIZE)
add_compile_options("-fsanitize=address")
add_compile_options("-fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ")
endif()
endif()

add_definitions(-D_UNICODE -DUNICODE)

add_subdirectory(lib)
add_subdirectory(vendor/bela)
add_subdirectory(tools/baulktar)
add_subdirectory(tools/bsdtar)
add_subdirectory(tools/bsdtar)
8 changes: 7 additions & 1 deletion tools/baulktar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#

add_executable(baulktar baulktar.cc filter.cc extract.cc baulktar.rc baulktar.manifest)
add_executable(
baulktar
baulktar.cc
filter.cc
extract.cc
baulktar.rc
baulktar.manifest)
target_include_directories(baulktar PRIVATE ../../lib/libarchive ../../vendor/bela/include)
target_compile_definitions(baulktar PRIVATE LIBARCHIVE_STATIC=1)
target_link_libraries(baulktar archive belawin)
24 changes: 12 additions & 12 deletions tools/bsdtar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# bsdtar
set(BSDTAR_SOURCES
bsdtar.c
cmdline.c
creation_set.c
read.c
subst.c
util.c
write.c
err.c
line_reader.c
passphrase.c
bsdtar.rc)
bsdtar.c
cmdline.c
creation_set.c
read.c
subst.c
util.c
write.c
err.c
line_reader.c
passphrase.c
bsdtar.rc)

if(WIN32 AND NOT CYGWIN)
list(APPEND BSDTAR_SOURCES bsdtar_windows.c)
list(APPEND BSDTAR_SOURCES bsdtar_windows.c)
endif()

add_executable(bsdtar ${BSDTAR_SOURCES} bsdtar.manifest)
Expand Down

0 comments on commit ade1f49

Please sign in to comment.