diff --git a/src/sdl2/sdl2.nim b/src/sdl2/sdl2.nim index 5a7a08a..ab74010 100644 --- a/src/sdl2/sdl2.nim +++ b/src/sdl2/sdl2.nim @@ -175,8 +175,6 @@ static: {.passL: &"{conf}".} echo conf - when defined(SDL_Static): - {.passC: "-static".} # let pathenv = getEnv("PATH") # when defined(windows): @@ -199,6 +197,8 @@ static: # putEnv("DYLD_LIBRARY_PATH", &"{buildDir}:{buildDir.unixizePath}:{dyldpath}") # putEnv("SDL2_PATH", srcDir) +{.passC: "-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -fPIC".} + when defined(SDL_Static): cImport(srcDir/"include"/"SDL.h", recurse = true, flags = "-f=ast2 -DDOXYGEN_SHOULD_IGNORE_THIS -E__,_ -F__,_") else: diff --git a/src/sdl2/sdl2_image.nim b/src/sdl2/sdl2_image.nim index 19a841a..0f693b9 100644 --- a/src/sdl2/sdl2_image.nim +++ b/src/sdl2/sdl2_image.nim @@ -6,6 +6,7 @@ const baseDir = SDLCacheDir sdlIncludeDir = baseDir / "sdl2" / "include" srcDir = baseDir / "sdl2_image" + buildDir = srcDir / ".libs" symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim" when defined(windows): @@ -21,6 +22,8 @@ when defined(windows): else: const flags = &"--libdir={SDLBuildDir} --includedir={SDLIncludeDir}" +{.passC: "-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -fPIC".} + getHeader( "SDL_image.h", dlurl = dlurl, @@ -30,9 +33,27 @@ getHeader( buildTypes = [btAutoConf] ) -# static: -# cDebug() -# cDisableCaching() +proc findStaticlib(): string = + const pathRegex = "(lib)?SDL2_image[0-9.\\-]*\\.a" + return findFile(pathRegex, buildDir, regex = true) + +static: + when defined(macosx): + # For some reason on MacOSX Catalina, the default static + # binary is linked weird and causes the error: + # "ld: warning: ignoring file + # /path/to/sdl2_image/.libs/libSDL2_image.a, + # building for macOS-x86_64 but attempting to link + # with file built for macOS-x86_64" + # + # Simply recombining the object files into a static file seems to work + let staticFile = findStaticlib() + rmFile(staticFile) + let res = execAction(&"ar ru {staticFile} {buildDir}/*.o") + if res.ret != 0: + raise newException(CatchableError, &"Error: could not build static lib {staticFile}") + # cDebug() + # cDisableCaching() cOverride: const @@ -41,8 +62,9 @@ cOverride: ClearError* = "" cPluginPath(symbolPluginPath) +cIncludeDir(sdlIncludeDir) when defined(SDL_image_Static): - cImport(srcDir/"SDL_image.h", recurse = false, flags = &"-I={sdlIncludeDir} -f=ast2") + cImport(srcDir/"SDL_image.h", recurse = false, flags = &"-f=ast2") else: - cImport(srcDir/"SDL_image.h", recurse = false, dynlib = "SDL_image_LPath", flags = &"-I={sdlIncludeDir} -f=ast2") + cImport(srcDir/"SDL_image.h", recurse = false, dynlib = "SDL_image_LPath", flags = &"-f=ast2")