Add build options related to executable generation
This commit is contained in:
@ -24,13 +24,50 @@ project(86Box
|
|||||||
HOMEPAGE_URL "https://86box.net"
|
HOMEPAGE_URL "https://86box.net"
|
||||||
LANGUAGES C CXX)
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
if(WIN32 AND VCPKG_TOOLCHAIN)
|
include(CPack)
|
||||||
if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$")
|
include(CMakeDependentOption)
|
||||||
# `-static` triplet, use the statically linked CRT
|
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
# 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()
|
else()
|
||||||
# Regular triplet (or `-static-md`), use the dynamically linked CRT
|
option(STATIC_BUILD "Static build" OFF)
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -42,10 +79,6 @@ if (NOT ARCH)
|
|||||||
set(ARCH unknown)
|
set(ARCH unknown)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CPack)
|
|
||||||
|
|
||||||
include(CMakeDependentOption)
|
|
||||||
|
|
||||||
add_compile_definitions(CMAKE)
|
add_compile_definitions(CMAKE)
|
||||||
add_compile_definitions("$<$<CONFIG:Debug>:DEBUG>")
|
add_compile_definitions("$<$<CONFIG:Debug>:DEBUG>")
|
||||||
|
|
||||||
|
@ -64,9 +64,11 @@ if(WIN32 AND ARCH STREQUAL "i386")
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MINGW)
|
if(STATIC_BUILD)
|
||||||
target_link_options(86Box PRIVATE "-static")
|
if(MINGW OR UNIX)
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".dll.a")
|
target_link_options(86Box PRIVATE "-static")
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
@ -91,7 +93,7 @@ target_link_libraries(86Box ${OPENAL_LIBRARY})
|
|||||||
|
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
include_directories(${SDL2_INCLUDE_DIRS})
|
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)
|
target_link_libraries(86Box SDL2::SDL2-static)
|
||||||
elseif(TARGET SDL2::SDL2)
|
elseif(TARGET SDL2::SDL2)
|
||||||
target_link_libraries(86Box SDL2::SDL2)
|
target_link_libraries(86Box SDL2::SDL2)
|
||||||
@ -143,7 +145,7 @@ if(MINITRACE)
|
|||||||
target_link_libraries(86Box minitrace)
|
target_link_libraries(86Box minitrace)
|
||||||
endif()
|
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
|
# Copy the binary to the root of the install prefix on Windows and macOS
|
||||||
install(TARGETS 86Box DESTINATION ".")
|
install(TARGETS 86Box DESTINATION ".")
|
||||||
else()
|
else()
|
||||||
|
Reference in New Issue
Block a user