Add build options related to executable generation
This commit is contained in:
parent
f9ef6a2408
commit
9f03225e5a
@ -24,13 +24,50 @@ project(86Box
|
||||
HOMEPAGE_URL "https://86box.net"
|
||||
LANGUAGES C CXX)
|
||||
|
||||
if(WIN32 AND VCPKG_TOOLCHAIN)
|
||||
if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$")
|
||||
# `-static` triplet, use the statically linked CRT
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
include(CPack)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
# Basic build options
|
||||
if(WIN32)
|
||||
if(VCPKG_TOOLCHAIN)
|
||||
# For vcpkg builds we have to respect the linking method used by the
|
||||
# specified triplet.
|
||||
set(NO_STATIC_OPTION ON)
|
||||
if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$")
|
||||
# `-static` triplet, use static linking
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
set(STATIC_BUILD ON)
|
||||
elseif(VCPKG_TARGET_TRIPLET MATCHES "-windows-static-md$")
|
||||
# `-static-md` triplet, use static linking with dynamic CRT
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
set(STATIC_BUILD ON)
|
||||
elseif()
|
||||
# Regular triplet, use dynamic linking
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
set(STATIC_BUILD OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Prefer static builds on Windows
|
||||
set(PREFER_STATIC ON)
|
||||
|
||||
# Default value for the `WIN32` target property, which specifies whether
|
||||
# to build the application for the Windows GUI or console subsystem
|
||||
option(CMAKE_WIN32_EXECUTABLE "Build a Windows GUI executable" ON)
|
||||
else()
|
||||
# Prefer dynamic builds everywhere else
|
||||
set(PREFER_STATIC OFF)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
option(CMAKE_MACOSX_BUNDLE "Build a macOS bundle (.app)" ON)
|
||||
endif()
|
||||
|
||||
if(NOT NO_STATIC_OPTION)
|
||||
if(PREFER_STATIC)
|
||||
option(STATIC_BUILD "Static build" ON)
|
||||
else()
|
||||
# Regular triplet (or `-static-md`), use the dynamically linked CRT
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
option(STATIC_BUILD "Static build" OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -42,10 +79,6 @@ if (NOT ARCH)
|
||||
set(ARCH unknown)
|
||||
endif()
|
||||
|
||||
include(CPack)
|
||||
|
||||
include(CMakeDependentOption)
|
||||
|
||||
add_compile_definitions(CMAKE)
|
||||
add_compile_definitions("$<$<CONFIG:Debug>:DEBUG>")
|
||||
|
||||
|
@ -64,9 +64,11 @@ if(WIN32 AND ARCH STREQUAL "i386")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
target_link_options(86Box PRIVATE "-static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".dll.a")
|
||||
if(STATIC_BUILD)
|
||||
if(MINGW OR UNIX)
|
||||
target_link_options(86Box PRIVATE "-static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
@ -91,7 +93,7 @@ target_link_libraries(86Box ${OPENAL_LIBRARY})
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
if(WIN32 AND TARGET SDL2::SDL2-static)
|
||||
if(STATIC_BUILD AND TARGET SDL2::SDL2-static)
|
||||
target_link_libraries(86Box SDL2::SDL2-static)
|
||||
elseif(TARGET SDL2::SDL2)
|
||||
target_link_libraries(86Box SDL2::SDL2)
|
||||
@ -143,7 +145,7 @@ if(MINITRACE)
|
||||
target_link_libraries(86Box minitrace)
|
||||
endif()
|
||||
|
||||
if(WIN32 OR APPLE)
|
||||
if(WIN32 OR (APPLE AND CMAKE_MACOSX_BUNDLE))
|
||||
# Copy the binary to the root of the install prefix on Windows and macOS
|
||||
install(TARGETS 86Box DESTINATION ".")
|
||||
else()
|
||||
|
Loading…
x
Reference in New Issue
Block a user