Skip to content

Commit

Permalink
build: CMake: Add option for static runtime
Browse files Browse the repository at this point in the history
Enabled by default on Windows.
  • Loading branch information
CyberTailor committed Jan 28, 2024
1 parent 5b36ce3 commit b617435
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ if(MSVC)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(FATAL_ERROR "It's not yet possible to build Gridcoin with MSVC")
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_compile_options(/U NDEBUG)
else()
add_compile_options(-UNDEBUG)
Expand Down Expand Up @@ -85,6 +84,7 @@ option(ENABLE_GUI "Enable Qt-based GUI" OFF)
option(ENABLE_DOCS "Build Doxygen documentation" OFF)
option(ENABLE_TESTS "Build tests" OFF)
option(LUPDATE "Update translation files" OFF)
option(STATIC_RUNTIME "Link runtime statically" ${WIN32})

# CPU-dependent options
option(ENABLE_SSE41 "Build code that uses SSE4.1 intrinsics" ${HAS_SSE41})
Expand Down Expand Up @@ -245,12 +245,20 @@ endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIE})

# Set compiler flags
if (APPLE)
if(APPLE)
add_compile_options(-Wno-error=deprecated-declarations)
add_compile_options(-Wno-error=thread-safety-analysis)
add_compile_options(-Wno-error=thread-safety-reference)
endif()

if(STATIC_RUNTIME)
if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$")
list(APPEND RUNTIME_LIBS -static-libgcc -static-libstdc++)
elseif(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()

# Set endianness
if(CMAKE_CXX_BYTE_ORDER EQUAL BIG_ENDIAN)
set(WORDS_BIGENDIAN 1)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ endif()

if(ENABLE_DAEMON)
add_executable(gridcoinresearchd gridcoinresearchd.cpp)
target_link_libraries(gridcoinresearchd PUBLIC gridcoin_util)
target_link_libraries(gridcoinresearchd PUBLIC ${RUNTIME_LIBS} gridcoin_util)

if(WIN32)
target_sources(gridcoinresearchd PRIVATE gridcoinresearchd-res.rc)
Expand Down
1 change: 1 addition & 0 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ add_dependencies(gridcoinqt gridcoinqt_l10n)
add_executable(gridcoinresearch WIN32 MACOSX_BUNDLE bitcoin.cpp)

target_link_libraries(gridcoinresearch PRIVATE
${RUNTIME_LIBS}
Qt5::Widgets
gridcoin_util
gridcoinqt
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set_target_properties(test_gridcoin-qt PROPERTIES
)

target_link_libraries(test_gridcoin-qt PRIVATE
${RUNTIME_LIBS}
Qt5::Test
Qt5::Widgets
gridcoin_util
Expand Down
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ add_executable(test_gridcoin
add_subdirectory(data)

target_link_libraries(test_gridcoin PRIVATE
${RUNTIME_LIBS}
Boost::unit_test_framework
gridcoin_util
)
Expand Down

0 comments on commit b617435

Please sign in to comment.