diff --git a/.gitignore b/.gitignore index 7023aaa80..3eca1c57a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Win32_LIB_ASM_Release /assets/debian /make /bin +/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e52d740d..915912af5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + message(FATAL_ERROR "In-source builds are blocked. Please build from a separate directory.") +endif() + # Set up CMAKE path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 973fd01d1..c6459de3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32) -if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") +if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") # On MinGW with internal libraries, link the standard library statically target_link_options(SRB2SDL2 PRIVATE "-static") endif() @@ -303,3 +303,27 @@ if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) ) endif() endif() + +# copy DLLs to bin/ directory if building internal shared on windows +if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") + set(ADDITIONAL_DLLS "") + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU) + # also copy implicitly linked system libraries + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + list(APPEND ADDITIONAL_DLLS + "libgcc_s_dw2-1.dll" + "libstdc++-6.dll" + "libwinpthread-1.dll" + ) + list(TRANSFORM ADDITIONAL_DLLS PREPEND "${MINGW_BIN_PATH}/") + endif() + add_custom_command(TARGET SRB2SDL2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + ${ADDITIONAL_DLLS} + + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying runtime DLLs" + ) +endif() diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 208044113..37c36399a 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -57,30 +57,52 @@ if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") VERSION 1.2.13 URL "https://github.com/madler/zlib/archive/refs/tags/v1.2.13.zip" EXCLUDE_FROM_ALL - OPTIONS - # The assembly optimizations are unmaintained and slated to be removed - "ASM686 Off" - "AMD64 Off" - "SKIP_INSTALL_ALL ON" + DOWNLOAD_ONLY YES ) - file(MAKE_DIRECTORY "${zlib_BINARY_DIR}/include") - file(COPY "${zlib_SOURCE_DIR}/zlib.h" DESTINATION "${zlib_BINARY_DIR}/include") - file(COPY "${zlib_BINARY_DIR}/zconf.h" DESTINATION "${zlib_BINARY_DIR}/include") - # honestly this should probably be built like png is - set_target_properties(zlib PROPERTIES EXCLUDE_FROM_ALL ON) - set_target_properties(minigzip PROPERTIES EXCLUDE_FROM_ALL ON) - set_target_properties(example PROPERTIES EXCLUDE_FROM_ALL ON) - # zlib cmake also adds these 64 targets separately - if(HAVE_OFF64_T) - set_target_properties(minigzip64 PROPERTIES EXCLUDE_FROM_ALL ON) - set_target_properties(example64 PROPERTIES EXCLUDE_FROM_ALL ON) - endif() - target_include_directories(zlib INTERFACE "${zlib_BINARY_DIR}/include") - target_include_directories(zlibstatic INTERFACE "${zlib_BINARY_DIR}/include") - if(SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES) - add_library(ZLIB::ZLIB ALIAS zlib) - else() - add_library(ZLIB::ZLIB ALIAS zlibstatic) + if(ZLIB_ADDED) + set(ZLIB_SRCS + crc32.h + deflate.h + gzguts.h + inffast.h + inffixed.h + inflate.h + inftrees.h + trees.h + zutil.h + + adler32.c + compress.c + crc32.c + deflate.c + gzclose.c + gzlib.c + gzread.c + gzwrite.c + inflate.c + infback.c + inftrees.c + inffast.c + trees.c + uncompr.c + zutil.c + ) + list(TRANSFORM ZLIB_SRCS PREPEND "${ZLIB_SOURCE_DIR}/") + + configure_file("${ZLIB_SOURCE_DIR}/zlib.pc.cmakein" "${ZLIB_BINARY_DIR}/zlib.pc" @ONLY) + configure_file("${ZLIB_SOURCE_DIR}/zconf.h.cmakein" "${ZLIB_BINARY_DIR}/include/zconf.h" @ONLY) + + add_library(ZLIB ${SRB2_INTERNAL_LIBRARY_TYPE} ${ZLIB_SRCS}) + set_target_properties(ZLIB PROPERTIES + VERSION 1.2.13 + OUTPUT_NAME "z" + ) + target_include_directories(ZLIB PRIVATE "${ZLIB_SOURCE_DIR}") + target_include_directories(ZLIB PUBLIC "${ZLIB_BINARY_DIR}/include") + if(MSVC) + target_compile_definitions(ZLIB PRIVATE -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) + endif() + add_library(ZLIB::ZLIB ALIAS ZLIB) endif() endif() @@ -470,6 +492,12 @@ if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") # -DLIBOPENMPT_BUILD configure_file("openmpt_svn_version.h" "svn_version.h") add_library(openmpt "${SRB2_INTERNAL_LIBRARY_TYPE}" ${openmpt_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/svn_version.h) + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU OR "${CMAKE_C_COMPILER_ID}" STREQUAL Clang OR "${CMAKE_C_COMPILER_ID}" STREQUAL AppleClang) + target_compile_options(openmpt PRIVATE "-g0") + endif() + if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows) + target_link_libraries(openmpt PRIVATE Rpcrt4) + endif() target_compile_features(openmpt PRIVATE cxx_std_11) target_compile_definitions(openmpt PRIVATE -DLIBOPENMPT_BUILD)