From 0dc7286fa4fd24a200b31f5ecb4dea18714b9197 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Fri, 25 Oct 2024 10:53:53 -0400 Subject: [PATCH 1/7] use import targets for zlib --- rts/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/rts/CMakeLists.txt b/rts/CMakeLists.txt index dfc2344342..a43fea1349 100644 --- a/rts/CMakeLists.txt +++ b/rts/CMakeLists.txt @@ -86,7 +86,6 @@ endif (UNIX AND NOT MINGW) find_package_static(ZLIB 1.2.7 REQUIRED) list(APPEND engineCommonLibraries DevIL::IL) - list(APPEND engineCommonLibraries 7zip prd::jsoncpp ${SPRING_MINIZIP_LIBRARY} ZLIB::ZLIB Tracy::TracyClient) list(APPEND engineCommonLibraries lua luasocket archives assimp gflags_nothreads_static) From f2ea85dddbfde584e18eaf5fd95d881fc900239d Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Fri, 1 Nov 2024 15:07:00 -0400 Subject: [PATCH 2/7] use imported targets for SDL2 --- CMakeLists.txt | 2 +- rts/Sim/CMakeLists.txt | 4 +- rts/System/Sound/CMakeLists.txt | 4 +- rts/build/cmake/FindSDL2.cmake | 210 +++------------------------ rts/builds/dedicated/CMakeLists.txt | 6 - rts/builds/headless/CMakeLists.txt | 2 - rts/builds/legacy/CMakeLists.txt | 8 +- rts/lib/headlessStubs/CMakeLists.txt | 5 +- test/headercheck/CMakeLists.txt | 1 - tools/unitsync/CMakeLists.txt | 4 +- 10 files changed, 29 insertions(+), 217 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e934a3c004..8ef9212b62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,7 +291,7 @@ endif (RECOIL_DETAILED_TRACY_ZONING) # Note the missing REQUIRED, as headless & dedi may not depend on those. # So req. checks are done in the build target's CMakeLists.txt. -find_package(SDL2) +find_package(SDL2 MODULE) find_package_static(DevIL 1.8.0 REQUIRED) diff --git a/rts/Sim/CMakeLists.txt b/rts/Sim/CMakeLists.txt index 2a847d1189..493a185419 100644 --- a/rts/Sim/CMakeLists.txt +++ b/rts/Sim/CMakeLists.txt @@ -154,9 +154,7 @@ add_library(engineSim STATIC "${CMAKE_CURRENT_SOURCE_DIR}/Weapons/WeaponTarget.cpp" ) -target_include_directories(engineSim - PRIVATE ${SDL2_INCLUDE_DIR}) -target_link_libraries(engineSim Tracy::TracyClient) +target_link_libraries(engineSim SDL2::SDL2 Tracy::TracyClient) if( CMAKE_COMPILER_IS_GNUCXX) # FIXME: hack to avoid linkers to remove not referenced symbols. required because of diff --git a/rts/System/Sound/CMakeLists.txt b/rts/System/Sound/CMakeLists.txt index 26ddced347..b389bc10c6 100644 --- a/rts/System/Sound/CMakeLists.txt +++ b/rts/System/Sound/CMakeLists.txt @@ -48,13 +48,13 @@ if (NOT NO_SOUND) include_directories(${OPENAL_INCLUDE_DIR}) find_package_static(OggVorbis 1.3.4 REQUIRED) - find_package(SDL2 REQUIRED) - include_directories(${SDL2_INCLUDE_DIR}) + find_package(SDL2 MODULE REQUIRED) include_directories(${CMAKE_SOURCE_DIR}/include/) include_directories(${CMAKE_SOURCE_DIR}/include/AL) add_library(sound STATIC EXCLUDE_FROM_ALL ${soundSources}) + target_link_libraries(sound SDL2::SDL2) target_link_libraries(sound vorbis::vorbisfile vorbis::vorbis Ogg::ogg) target_link_libraries(sound ${OPENAL_LIBRARY}) target_link_libraries(sound Tracy::TracyClient) diff --git a/rts/build/cmake/FindSDL2.cmake b/rts/build/cmake/FindSDL2.cmake index 77486a7ebf..465e270a93 100644 --- a/rts/build/cmake/FindSDL2.cmake +++ b/rts/build/cmake/FindSDL2.cmake @@ -1,196 +1,24 @@ -# Locate SDL2 library -# This module defines -# SDL2_LIBRARY, the name of the library to link against -# SDL2_FOUND, if false, do not try to link to SDL2 -# SDL2_INCLUDE_DIR, where to find SDL.h -# SDL2_VERSION_STRING the version found -# -# This module responds to the the flag: -# SDL2_BUILDING_LIBRARY -# If this is defined, then no SDL2_main will be linked in because -# only applications need main(). -# Otherwise, it is assumed you are building an application and this -# module will attempt to locate and set the the proper link flags -# as part of the returned SDL2_LIBRARY variable. -# -# Don't forget to include SDL2main.h and SDL2main.m your project for the -# OS X framework based version. (Other versions link to -lSDL2main which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. -# -# -# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration -# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library -# (SDL2.dll, libsdl2.so, SDL2.framework, etc). -# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. -# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value -# as appropriate. These values are used to generate the final SDL2_LIBRARY -# variable, but when these values are unset, SDL2_LIBRARY does not get created. -# -# -# $SDL2DIR is an environment variable that would -# correspond to the ./configure --prefix=$SDL2DIR -# used in building SDL2. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added code to assist with automated building by using environmental variables -# and providing a more controlled/consistent search behavior. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL2 guidelines. -# Added a search for SDL2main which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. -# -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL2_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. -# -# Note that the header path has changed from SDL2/SDL.h to just SDL.h -# This needed to change because "proper" SDL2 convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL2/ (see FreeBSD). -# -# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake -# module with the minor edit of changing "SDL" to "SDL2" where necessary. This -# was not created for redistribution, and exists temporarily pending official -# SDL2 CMake modules. +# The version of SDL we have is too old +# and doesn't provide a proper config file. +# We need to create imported targets for the config +find_package(SDL2 QUIET CONFIG) -#============================================================================= -# Copyright 2003-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - - -FIND_PATH(SDL2_INCLUDE_DIR SDL.h - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES include/SDL2 include - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include/SDL2 - /usr/include/SDL2 - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt -) - -if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") - set(SDL2_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH}) - unset(SDL2_VERSION_MAJOR_LINE) - unset(SDL2_VERSION_MINOR_LINE) - unset(SDL2_VERSION_PATCH_LINE) - unset(SDL2_VERSION_MAJOR) - unset(SDL2_VERSION_MINOR) - unset(SDL2_VERSION_PATCH) -endif() - - - -FIND_LIBRARY(SDL2_LIBRARY_TEMP - NAMES SDL2 - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES lib64 lib - PATHS - /sw - /opt/local - /opt/csw - /opt +find_library(SDL2_LIBRARY + NAMES + SDL2 + PATHS + ${SDL2_LIBDIR} ) -IF(NOT SDL2_BUILDING_LIBRARY) - IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") - # Non-OS X framework versions expect you to also dynamically link to - # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms - # seem to provide SDL2main for compatibility even though they don't - # necessarily need it. - FIND_LIBRARY(SDL2MAIN_LIBRARY - NAMES SDL2main - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES lib64 lib - PATHS - /sw - /opt/local - /opt/csw - /opt - ) - ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") -ENDIF(NOT SDL2_BUILDING_LIBRARY) - - -# SDL2 may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -IF(NOT APPLE) - FIND_PACKAGE(Threads) -ENDIF(NOT APPLE) - -SET(SDL2_FOUND "NO") -IF(SDL2_LIBRARY_TEMP) - SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} CACHE INTERNAL "") - - # For SDL2main - IF(NOT SDL2_BUILDING_LIBRARY) - IF(SDL2MAIN_LIBRARY) - SET(SDL2_LIBRARY ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY}) - ENDIF(SDL2MAIN_LIBRARY) - ENDIF(NOT SDL2_BUILDING_LIBRARY) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 DEFAULT_MSG SDL2_INCLUDE_DIRS SDL2_LIBRARIES SDL2_LIBRARY) +mark_as_advanced(SDL2_LIBRARIES SDL2_LIBRARY) - - # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. - # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there if I modify a pre-used variable. - # I think it has something to do with the CACHE STRING. - # So I use a temporary variable until the end so I can set the - # "real" variable in one-shot. - IF(APPLE) - SET(SDL2_LIBRARY ${SDL2_LIBRARY} "-framework Cocoa") - ENDIF(APPLE) - - - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if I used the Threads package - # and try using this line, so I'm just skipping it entirely for OS X. - IF(NOT APPLE) - SET(SDL2_LIBRARY ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(NOT APPLE) - - - # For MinGW library - IF(MINGW) - SET(SDL2_LIBRARY ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) - ENDIF(MINGW) - - SET(SDL2_FOUND "YES") -ENDIF(SDL2_LIBRARY_TEMP) - - -INCLUDE(FindPackageHandleStandardArgs) - - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 - REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR - VERSION_VAR SDL2_VERSION_STRING) +if (SDL2_FOUND AND NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" + IMPORTED_LOCATION ${SDL2_LIBRARY} + ) +endif() diff --git a/rts/builds/dedicated/CMakeLists.txt b/rts/builds/dedicated/CMakeLists.txt index 6562b6ab4b..3662f07d6d 100644 --- a/rts/builds/dedicated/CMakeLists.txt +++ b/rts/builds/dedicated/CMakeLists.txt @@ -54,12 +54,6 @@ if (UNIX AND NOT MINGW) endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD") endif (UNIX AND NOT MINGW) -find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIR}) -if("${SDL2_VERSION_STRING}" VERSION_LESS "2") - message(FATAL_ERROR "Found SDL v${SDL2_VERSION_STRING} while 2 is required!") -endif() - ### Assemble the incude dirs include_directories(${ENGINE_SRC_ROOT_DIR}/) include_directories(${ENGINE_SRC_ROOT_DIR}/lib/lua/include) diff --git a/rts/builds/headless/CMakeLists.txt b/rts/builds/headless/CMakeLists.txt index a3baad55f4..854784ad55 100644 --- a/rts/builds/headless/CMakeLists.txt +++ b/rts/builds/headless/CMakeLists.txt @@ -15,8 +15,6 @@ set(OpenGL_GL_PREFERENCE LEGACY) include_directories(${OPENAL_INCLUDE_DIR}) find_package(OpenGL 3.0 REQUIRED) -find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIR}) # headlessstubs are our stubs that replace libGL, libGLU, libGLEW, libSDL (yes really!) list(APPEND engineHeadlessLibraries headlessStubs) diff --git a/rts/builds/legacy/CMakeLists.txt b/rts/builds/legacy/CMakeLists.txt index a58e1bc255..c76d5ae362 100644 --- a/rts/builds/legacy/CMakeLists.txt +++ b/rts/builds/legacy/CMakeLists.txt @@ -9,12 +9,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") ### Assemble libraries -find_package(SDL2 REQUIRED) -set(engineIncludes ${SDL2_INCLUDE_DIR}) -set(engineLibraries ${SDL2_LIBRARY}) -if("${SDL2_VERSION_STRING}" VERSION_LESS "2") - message(FATAL_ERROR "Found SDL v${SDL2_VERSION_STRING} while 2 is required!") -endif() +find_package(SDL2 MODULE REQUIRED) +set(engineLibraries SDL2::SDL2) set(OpenGL_GL_PREFERENCE LEGACY) find_package_static(OpenGL 3.0 REQUIRED) diff --git a/rts/lib/headlessStubs/CMakeLists.txt b/rts/lib/headlessStubs/CMakeLists.txt index 63a6b2d25b..1adceb839a 100644 --- a/rts/lib/headlessStubs/CMakeLists.txt +++ b/rts/lib/headlessStubs/CMakeLists.txt @@ -4,9 +4,8 @@ SET(headlessStubsSources "sdlstub.c" ) -FIND_PACKAGE(SDL2 REQUIRED) -INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR}) +find_package(SDL2 MODULE REQUIRED) ADD_LIBRARY(headlessStubs STATIC EXCLUDE_FROM_ALL ${headlessStubsSources}) +target_link_libraries(headlessStubs PUBLIC SDL2::SDL2) SET_TARGET_PROPERTIES(headlessStubs PROPERTIES COMPILE_FLAGS "${PIC_FLAG}") - diff --git a/test/headercheck/CMakeLists.txt b/test/headercheck/CMakeLists.txt index 709ae96c6b..016515bf3b 100644 --- a/test/headercheck/CMakeLists.txt +++ b/test/headercheck/CMakeLists.txt @@ -7,7 +7,6 @@ include_directories( ${Spring_SOURCE_DIR}/include ${Spring_SOURCE_DIR}/rts/lib ${Spring_SOURCE_DIR}/rts/lib/lua/include - ${SDL2_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} ) diff --git a/tools/unitsync/CMakeLists.txt b/tools/unitsync/CMakeLists.txt index cb07b5d0df..337e5eac00 100644 --- a/tools/unitsync/CMakeLists.txt +++ b/tools/unitsync/CMakeLists.txt @@ -23,8 +23,8 @@ if (WIN32) list(APPEND unitsync_libs ${WINMM_LIBRARY}) endif (WIN32) -find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIR}) +find_package(SDL2 MODULE REQUIRED) +list(APPEND unitsync_libs SDL2::SDL2) if (MINGW) #list(APPEND unitsync_lib_flags -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) From 694223e1eccd510dadb307bb58decb7da7df6d2b Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 2 Nov 2024 11:39:27 -0400 Subject: [PATCH 3/7] convert OpenAL to import targets --- rts/System/Sound/CMakeLists.txt | 5 ++--- rts/builds/headless/CMakeLists.txt | 1 - rts/builds/legacy/CMakeLists.txt | 1 - test/headercheck/CMakeLists.txt | 1 - 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rts/System/Sound/CMakeLists.txt b/rts/System/Sound/CMakeLists.txt index b389bc10c6..bd71969f25 100644 --- a/rts/System/Sound/CMakeLists.txt +++ b/rts/System/Sound/CMakeLists.txt @@ -44,8 +44,7 @@ if (NOT NO_SOUND) OpenAL/VorbisShared.cpp ) - find_package_static(OpenAL REQUIRED) - include_directories(${OPENAL_INCLUDE_DIR}) + find_package_static(OpenAL 1.18.2 REQUIRED) find_package_static(OggVorbis 1.3.4 REQUIRED) find_package(SDL2 MODULE REQUIRED) @@ -56,6 +55,6 @@ if (NOT NO_SOUND) add_library(sound STATIC EXCLUDE_FROM_ALL ${soundSources}) target_link_libraries(sound SDL2::SDL2) target_link_libraries(sound vorbis::vorbisfile vorbis::vorbis Ogg::ogg) - target_link_libraries(sound ${OPENAL_LIBRARY}) + target_link_libraries(sound OpenAL::OpenAL) target_link_libraries(sound Tracy::TracyClient) endif (NOT NO_SOUND) diff --git a/rts/builds/headless/CMakeLists.txt b/rts/builds/headless/CMakeLists.txt index 854784ad55..adcfb0b1db 100644 --- a/rts/builds/headless/CMakeLists.txt +++ b/rts/builds/headless/CMakeLists.txt @@ -12,7 +12,6 @@ add_definitions(-DNO_SOUND) remove_definitions(-DAVI_CAPTURING) set(OpenGL_GL_PREFERENCE LEGACY) -include_directories(${OPENAL_INCLUDE_DIR}) find_package(OpenGL 3.0 REQUIRED) diff --git a/rts/builds/legacy/CMakeLists.txt b/rts/builds/legacy/CMakeLists.txt index c76d5ae362..2da8e7993b 100644 --- a/rts/builds/legacy/CMakeLists.txt +++ b/rts/builds/legacy/CMakeLists.txt @@ -55,7 +55,6 @@ list(APPEND engineLibraries RmlUi::Debugger) list(APPEND engineLibraries lunasvg) ### Assemble external incude dirs -list(APPEND engineIncludes ${OPENAL_INCLUDE_DIR}) list(APPEND engineIncludes ${ENGINE_SRC_ROOT_DIR}/lib/asio/include) list(APPEND engineIncludes ${ENGINE_SRC_ROOT_DIR}/lib/slimsig/include) list(APPEND engineIncludes ${ENGINE_SRC_ROOT_DIR}/lib/cereal/include) diff --git a/test/headercheck/CMakeLists.txt b/test/headercheck/CMakeLists.txt index 016515bf3b..b7938b446e 100644 --- a/test/headercheck/CMakeLists.txt +++ b/test/headercheck/CMakeLists.txt @@ -7,7 +7,6 @@ include_directories( ${Spring_SOURCE_DIR}/include ${Spring_SOURCE_DIR}/rts/lib ${Spring_SOURCE_DIR}/rts/lib/lua/include - ${OPENAL_INCLUDE_DIR} ) file(GLOB_RECURSE headers From 077849c88865e16c2aeb85ac50b950d67f1e125d Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sun, 24 Nov 2024 09:39:30 -0500 Subject: [PATCH 4/7] switch to COMPILE_ONLY for headlessStub link to SDL2 --- rts/lib/headlessStubs/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rts/lib/headlessStubs/CMakeLists.txt b/rts/lib/headlessStubs/CMakeLists.txt index 1adceb839a..3facb9eec4 100644 --- a/rts/lib/headlessStubs/CMakeLists.txt +++ b/rts/lib/headlessStubs/CMakeLists.txt @@ -7,5 +7,5 @@ SET(headlessStubsSources find_package(SDL2 MODULE REQUIRED) ADD_LIBRARY(headlessStubs STATIC EXCLUDE_FROM_ALL ${headlessStubsSources}) -target_link_libraries(headlessStubs PUBLIC SDL2::SDL2) +target_link_libraries(headlessStubs PUBLIC $) SET_TARGET_PROPERTIES(headlessStubs PROPERTIES COMPILE_FLAGS "${PIC_FLAG}") From 2a38f63e76c4c44035b47258364b75b50dfe2af4 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 2 Nov 2024 15:46:52 -0400 Subject: [PATCH 5/7] setup initial conan build --- conanfile.py | 85 +++++++++++++++++++ docker-build-v2/amd64-linux/Dockerfile | 35 ++++++-- .../amd64-linux/conan_build_profile | 12 +++ docker-build-v2/build.sh | 26 ++++-- docker-build-v2/conan_profile | 12 +++ docker-build-v2/scripts/configure.sh | 1 + docker-build-v2/scripts/deps.sh | 11 +++ docker-build-v2/scripts/graph-deps.sh | 9 ++ 8 files changed, 178 insertions(+), 13 deletions(-) create mode 100644 conanfile.py create mode 100644 docker-build-v2/amd64-linux/conan_build_profile create mode 100644 docker-build-v2/conan_profile create mode 100755 docker-build-v2/scripts/deps.sh create mode 100755 docker-build-v2/scripts/graph-deps.sh diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000000..15786d7e85 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,85 @@ +from conan import ConanFile, __version__ as conan_version +from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout +from conan.tools.files import load +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +import os + +required_conan_version = ">=2.0.0" + +class RecoilConan(ConanFile): + name = "recoil" + license = "GPL-2.0-or-later" + homepage = "https://github.com/beyond-all-reason/spring" + description = "Recoil is an open source real time strategy game engine." + topics = ("game-engine", "open-source") + package_type = "application" + version="105.0" + + exports_sources = "CMakeLists.txt", "src/*", "cmake/*", "cpack/*", "docs/*", "examples/*", "share/*", "tests/*",\ + "VERSION", "README.md" + no_copy_source = True + settings = "os", "compiler", "build_type", "arch" + options = { + } + default_options = { + } + + @property + def _testing_enabled(self): + return not self.conf.get("tools.build:skip_test", default=True, check_type=bool) + + def requirements(self): + self.requires("opengl/system") + self.requires("glew/2.2.0") + self.requires("zlib/1.2.13") + self.requires("devil/1.8.0") + self.requires("libunwind/1.8.1", force=True) + self.requires("zstd/1.5.6", override=True) + #self.requires("libpng/1.6.37") + #self.requires("giflib/5.2.1") + self.requires("ogg/1.3.5") + self.requires("vorbis/1.3.7") + self.requires("sdl/2.0.20") + + def configure(self): + if self.settings.os == "Linux": + self.options["sdl"].wayland = False # Disable wayland build for now + self.options["sdl"].pulse = False + self.options["sdl"].alsa = False + + def build_requirements(self): + pass + + def generate(self): + tc = CMakeToolchain(self) + tc.user_presets_path = False + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + def validate(self): + check_min_cppstd(self, "20") + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + if self._testing_enabled: + cmake.test() + + def package(self): + cmake = CMake(self) + cmake.install() + + def layout(self): + cmake_layout(self) + build_folder = self.conf.get("user.cmake.cmake_layout:build_folder", + default=f"cmake-build-{str(self.settings.build_type).lower()}") + + self.folders.build = build_folder + self.folders.generators = f"{build_folder}/conan" + self.folders.source = "." + self.cpp.source.includedirs = "src" diff --git a/docker-build-v2/amd64-linux/Dockerfile b/docker-build-v2/amd64-linux/Dockerfile index 0af01bb1e8..dde65b2907 100644 --- a/docker-build-v2/amd64-linux/Dockerfile +++ b/docker-build-v2/amd64-linux/Dockerfile @@ -9,13 +9,32 @@ RUN apt-get update \ && add-apt-repository ppa:ubuntu-toolchain-r/test --yes \ && apt-get update \ && apt-get install --no-install-recommends --yes \ - curl gcc-13 g++-13 git ninja-build curl p7zip-full python3-pip python3-setuptools \ - libsdl2-dev libopenal-dev libfreetype6-dev libfontconfig1-dev \ + curl gcc-13 g++-13 git ninja-build curl p7zip-full python3.8 python3.8-distutils \ + xz-utils build-essential \ + libgl-dev \ + xorg-dev \ + libxcb1-dev \ + libxcb-util-dev \ + libxcb-render-util0-dev \ + libxcb-xkb-dev \ + libxcb-icccm4-dev \ + libxcb-image0-dev \ + libxcb-keysyms1-dev \ + libxcb-xinerama0-dev \ + libxcb-cursor-dev \ + libxcb-composite0-dev \ + libxcb-ewmh-dev \ + libxcb-res0-dev \ + uuid-dev \ && apt-get remove --purge --yes software-properties-common \ && apt-get autoremove --purge --yes \ && apt-get upgrade --yes \ && rm -rf /var/lib/apt/lists/* +# pip for python3.8 +RUN curl -L -O https://bootstrap.pypa.io/get-pip.py && python3.8 get-pip.py && rm get-pip.py +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 10 + # We need a newer ccache for compression support ARG CCACHE_VERSION="4.10.2" RUN curl -L -O https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz \ @@ -33,16 +52,17 @@ RUN git clone --depth 1 --branch v1.5.6 https://github.com/facebook/zstd.git \ RUN pip3 install --upgrade pip \ && pip3 install scikit-build \ - && pip3 install cmake==3.27.* + && pip3 install cmake==3.27.* \ + && pip3 install conan==2.9.1 WORKDIR /build RUN mkdir src cache out artifacts && chmod a+rwx cache out artifacts # Fetch library dependencies and configure resolution -RUN git clone --depth=1 https://github.com/beyond-all-reason/spring-static-libs.git -b 18.04 spring-static-libs -ENV PKG_CONFIG_LIBDIR=/build/spring-static-libs/lib/pkgconfig -ENV PKG_CONFIG="pkg-config --define-prefix --static" -ENV CMAKE_PREFIX_PATH=/build/spring-static-libs/ +#RUN git clone --depth=1 https://github.com/beyond-all-reason/spring-static-libs.git -b 18.04 spring-static-libs +#ENV PKG_CONFIG_LIBDIR=/build/spring-static-libs/lib/pkgconfig +#ENV PKG_CONFIG="pkg-config --define-prefix --static" +#ENV CMAKE_PREFIX_PATH=/build/spring-static-libs/ ENV PREFER_STATIC_LIBS=TRUE # Set up default cmake toolchain @@ -54,3 +74,4 @@ COPY ccache.conf . ENV CCACHE_CONFIGPATH=/build/ccache.conf ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache ENV CMAKE_C_COMPILER_LAUNCHER=ccache +ENV CONAN_HOME=/build/.conan2 diff --git a/docker-build-v2/amd64-linux/conan_build_profile b/docker-build-v2/amd64-linux/conan_build_profile new file mode 100644 index 0000000000..501ce07885 --- /dev/null +++ b/docker-build-v2/amd64-linux/conan_build_profile @@ -0,0 +1,12 @@ +[settings] +arch=x86_64 +build_type=RelWithDebInfo +compiler=gcc +compiler.cppstd=gnu20 +compiler.libcxx=libstdc++11 +compiler.version=13 +os=Linux + +[conf] +tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++13' } +user.cmake.cmake_layout:build_folder=/build/out diff --git a/docker-build-v2/build.sh b/docker-build-v2/build.sh index bf608c72c2..a79a6b003f 100755 --- a/docker-build-v2/build.sh +++ b/docker-build-v2/build.sh @@ -2,18 +2,27 @@ set -e -u -o pipefail -USAGE="Usage: $0 [--help] [--configure|--compile] {windows|linux} [cmake_flag...]" +USAGE="Usage: $0 [--help] [--deps|--configure|--compile] {windows|linux} [cmake_flag...]" +export DEPS=true export CONFIGURE=true export COMPILE=true -OS= +export OS= for arg in "$@"; do case $arg in + --deps) + DEPS=true + CONFIGURE=false + COMPILE=false + shift + ;; --configure) + DEPS=false CONFIGURE=true COMPILE=false shift ;; --compile) + DEPS=false CONFIGURE=false COMPILE=true shift @@ -22,6 +31,7 @@ for arg in "$@"; do echo $USAGE echo "Options:" echo " --help print this help message" + echo " --deps only install conan dependencies, don't configure or compile" echo " --configure only configure, don't compile" echo " --compile only compile, don't configure" exit 0 @@ -40,7 +50,9 @@ if [[ -z $OS ]]; then fi cd "$(dirname "$(readlink -f "$0")")/.." -mkdir -p build-$OS .cache/ccache-$OS +mkdir -p build-$OS .cache/ccache-$OS .conan2-$OS/profiles +cp docker-build-v2/conan_profile .conan2-$OS/profiles +cp docker-build-v2/amd64-$OS/conan_build_profile .conan2-$OS/profiles # Use localy build image if available, and pull from upstream if not image=recoil-build-amd64-$OS:latest @@ -50,20 +62,22 @@ if [[ -z "$(docker images -q $image 2> /dev/null)" ]]; then fi docker run -it --rm \ - -v /etc/passwd:/etc/passwd:ro \ - -v /etc/group:/etc/group:ro \ - --user=$(id -u):$(id -g) \ -v $(pwd):/build/src:ro \ -v $(pwd)/.cache/ccache-$OS:/build/cache:rw \ -v $(pwd)/build-$OS:/build/out:rw \ + -v $(pwd)/.conan2-$OS:/build/.conan2:rw \ -e CONFIGURE \ -e COMPILE \ + -e OS \ $image \ bash -c ' set -e echo "$@" cd /build/src/docker-build-v2/scripts +$DEPS && ./graph-deps.sh "$@" +$DEPS && ./deps.sh "$@" $CONFIGURE && ./configure.sh "$@" +export OS if $COMPILE; then ./compile.sh # When compiling for windows, we must strip debug info because windows does diff --git a/docker-build-v2/conan_profile b/docker-build-v2/conan_profile new file mode 100644 index 0000000000..6e676b768a --- /dev/null +++ b/docker-build-v2/conan_profile @@ -0,0 +1,12 @@ +[settings] +arch=x86_64 +build_type=RelWithDebInfo +compiler=gcc +compiler.cppstd=gnu20 +compiler.libcxx=libstdc++11 +compiler.version=13 +os=Linux + +[conf] +tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++-13' } +user.cmake.cmake_layout:build_folder=/build/out diff --git a/docker-build-v2/scripts/configure.sh b/docker-build-v2/scripts/configure.sh index f44da06948..1bcd04206d 100755 --- a/docker-build-v2/scripts/configure.sh +++ b/docker-build-v2/scripts/configure.sh @@ -7,5 +7,6 @@ cmake --fresh -S /build/src -B /build/out \ -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \ -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \ + -DCMAKE_TOOLCHAIN_FILE="conan/conan_toolchain.cmake" -G Ninja \ "$@" diff --git a/docker-build-v2/scripts/deps.sh b/docker-build-v2/scripts/deps.sh new file mode 100755 index 0000000000..ed1a709646 --- /dev/null +++ b/docker-build-v2/scripts/deps.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +export CMAKE_TOOLCHAIN_FILE= + +conan install \ + -u \ + -r conancenter \ + -pr:h conan_profile \ + -pr:b conan_build_profile \ + --build=missing \ + /build/src diff --git a/docker-build-v2/scripts/graph-deps.sh b/docker-build-v2/scripts/graph-deps.sh new file mode 100755 index 0000000000..2037045aa7 --- /dev/null +++ b/docker-build-v2/scripts/graph-deps.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +conan graph info \ + -u \ + -r conancenter \ + -pr:h conan_profile \ + -pr:b conan_build_profile \ + --format=html \ + /build/src > /build/out/graph.html From e31663cf91ade30f02a181618bd913ee0730991f Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Fri, 13 Dec 2024 15:59:04 -0500 Subject: [PATCH 6/7] link to opngl and glew include directories in a couple of sublibraries --- conanfile.py | 4 ++++ docker-build-v2/amd64-linux/Dockerfile | 5 +++-- docker-build-v2/amd64-linux/conan_build_profile | 4 +++- docker-build-v2/conan_profile | 2 ++ docker-build-v2/scripts/configure.sh | 3 ++- rts/Sim/CMakeLists.txt | 3 +++ rts/System/Sound/CMakeLists.txt | 4 +++- rts/lib/headlessStubs/CMakeLists.txt | 3 ++- 8 files changed, 22 insertions(+), 6 deletions(-) diff --git a/conanfile.py b/conanfile.py index 15786d7e85..0d0f5f35bc 100644 --- a/conanfile.py +++ b/conanfile.py @@ -41,8 +41,12 @@ def requirements(self): self.requires("ogg/1.3.5") self.requires("vorbis/1.3.7") self.requires("sdl/2.0.20") + self.requires("libcurl/7.88.1") + self.requires("openal-soft/1.23.1") def configure(self): + self.options["glew"].with_glu = "system" + self.options["openal-soft"].shared = True if self.settings.os == "Linux": self.options["sdl"].wayland = False # Disable wayland build for now self.options["sdl"].pulse = False diff --git a/docker-build-v2/amd64-linux/Dockerfile b/docker-build-v2/amd64-linux/Dockerfile index dde65b2907..c5128ec71b 100644 --- a/docker-build-v2/amd64-linux/Dockerfile +++ b/docker-build-v2/amd64-linux/Dockerfile @@ -9,9 +9,10 @@ RUN apt-get update \ && add-apt-repository ppa:ubuntu-toolchain-r/test --yes \ && apt-get update \ && apt-get install --no-install-recommends --yes \ - curl gcc-13 g++-13 git ninja-build curl p7zip-full python3.8 python3.8-distutils \ + curl gcc-13 g++-13 git ninja-build p7zip-full python3.8 python3.8-distutils \ xz-utils build-essential \ libgl-dev \ + libglu-dev \ xorg-dev \ libxcb1-dev \ libxcb-util-dev \ @@ -53,7 +54,7 @@ RUN git clone --depth 1 --branch v1.5.6 https://github.com/facebook/zstd.git \ RUN pip3 install --upgrade pip \ && pip3 install scikit-build \ && pip3 install cmake==3.27.* \ - && pip3 install conan==2.9.1 + && pip3 install conan==2.10.2 WORKDIR /build RUN mkdir src cache out artifacts && chmod a+rwx cache out artifacts diff --git a/docker-build-v2/amd64-linux/conan_build_profile b/docker-build-v2/amd64-linux/conan_build_profile index 501ce07885..47803f564c 100644 --- a/docker-build-v2/amd64-linux/conan_build_profile +++ b/docker-build-v2/amd64-linux/conan_build_profile @@ -8,5 +8,7 @@ compiler.version=13 os=Linux [conf] -tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++13' } +tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++-13' } +tools.cmake.cmaketoolchain:user_toolchain+=/build/toolchain.cmake user.cmake.cmake_layout:build_folder=/build/out +tools.build.cross_building:cross_build=True diff --git a/docker-build-v2/conan_profile b/docker-build-v2/conan_profile index 6e676b768a..47803f564c 100644 --- a/docker-build-v2/conan_profile +++ b/docker-build-v2/conan_profile @@ -9,4 +9,6 @@ os=Linux [conf] tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++-13' } +tools.cmake.cmaketoolchain:user_toolchain+=/build/toolchain.cmake user.cmake.cmake_layout:build_folder=/build/out +tools.build.cross_building:cross_build=True diff --git a/docker-build-v2/scripts/configure.sh b/docker-build-v2/scripts/configure.sh index 1bcd04206d..00510b57a3 100755 --- a/docker-build-v2/scripts/configure.sh +++ b/docker-build-v2/scripts/configure.sh @@ -4,9 +4,10 @@ cmake --fresh -S /build/src -B /build/out \ -DCMAKE_INSTALL_PREFIX:PATH=/build/out/install \ -DAI_EXCLUDE_REGEX="^CppTestAI$" \ -DUSERDOCS_PLAIN=ON \ + -DPR_DOWNLOADER_FIND_CURL_NO_PKGCONFIG=ON \ -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \ -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \ - -DCMAKE_TOOLCHAIN_FILE="conan/conan_toolchain.cmake" + -DCMAKE_TOOLCHAIN_FILE="conan/conan_toolchain.cmake" \ -G Ninja \ "$@" diff --git a/rts/Sim/CMakeLists.txt b/rts/Sim/CMakeLists.txt index 493a185419..b58bf46f5b 100644 --- a/rts/Sim/CMakeLists.txt +++ b/rts/Sim/CMakeLists.txt @@ -156,6 +156,9 @@ add_library(engineSim STATIC target_link_libraries(engineSim SDL2::SDL2 Tracy::TracyClient) +find_package_static(GLEW 2.2.0 REQUIRED) +target_link_libraries(engineSim $) + if( CMAKE_COMPILER_IS_GNUCXX) # FIXME: hack to avoid linkers to remove not referenced symbols. required because of # https://springrts.com/mantis/view.php?id=4511 diff --git a/rts/System/Sound/CMakeLists.txt b/rts/System/Sound/CMakeLists.txt index bd71969f25..b52c364cc2 100644 --- a/rts/System/Sound/CMakeLists.txt +++ b/rts/System/Sound/CMakeLists.txt @@ -46,7 +46,8 @@ if (NOT NO_SOUND) find_package_static(OpenAL 1.18.2 REQUIRED) find_package_static(OggVorbis 1.3.4 REQUIRED) - + + find_package_static(GLEW 2.2.0 REQUIRED) find_package(SDL2 MODULE REQUIRED) include_directories(${CMAKE_SOURCE_DIR}/include/) @@ -57,4 +58,5 @@ if (NOT NO_SOUND) target_link_libraries(sound vorbis::vorbisfile vorbis::vorbis Ogg::ogg) target_link_libraries(sound OpenAL::OpenAL) target_link_libraries(sound Tracy::TracyClient) + target_link_libraries(sound $) endif (NOT NO_SOUND) diff --git a/rts/lib/headlessStubs/CMakeLists.txt b/rts/lib/headlessStubs/CMakeLists.txt index 3facb9eec4..d213c6a0c3 100644 --- a/rts/lib/headlessStubs/CMakeLists.txt +++ b/rts/lib/headlessStubs/CMakeLists.txt @@ -5,7 +5,8 @@ SET(headlessStubsSources ) find_package(SDL2 MODULE REQUIRED) +find_package(OpenGL REQUIRED) ADD_LIBRARY(headlessStubs STATIC EXCLUDE_FROM_ALL ${headlessStubsSources}) -target_link_libraries(headlessStubs PUBLIC $) +target_link_libraries(headlessStubs PUBLIC $ $ $) SET_TARGET_PROPERTIES(headlessStubs PROPERTIES COMPILE_FLAGS "${PIC_FLAG}") From 79acf1d389153c8c4e6aee63b99cb5709f41c569 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Fri, 13 Dec 2024 16:01:16 -0500 Subject: [PATCH 7/7] add a workaround so the build script works with podman --- docker-build-v2/build.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docker-build-v2/build.sh b/docker-build-v2/build.sh index a79a6b003f..86d513398e 100755 --- a/docker-build-v2/build.sh +++ b/docker-build-v2/build.sh @@ -61,8 +61,22 @@ if [[ -z "$(docker images -q $image 2> /dev/null)" ]]; then docker pull $image fi +# Podman assigns root id to the user so trying to set the user +# Won't work +check_is_podman() { + docker --version | grep -c "podman version" +} +set_usr_args="" +if [[ "$(check_is_podman)" -eq 0 ]]; then + echo "Using non-emulated docker" + set_usr_args="-v /etc/passwd:/etc/passwd:ro \ + -v /etc/group:/etc/group:ro \ + --user=$(id -u):$(id -g)" +fi + docker run -it --rm \ -v $(pwd):/build/src:ro \ + ${set_usr_args} \ -v $(pwd)/.cache/ccache-$OS:/build/cache:rw \ -v $(pwd)/build-$OS:/build/out:rw \ -v $(pwd)/.conan2-$OS:/build/.conan2:rw \