From: Ryan C. Gordon Date: Thu, 13 May 2010 18:43:12 +0000 (-0400) Subject: Reworked CMakeLists.txt. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=d8d295024cace407fc60127f70f3b92c50cbeb3f;p=lugaru.git Reworked CMakeLists.txt. Now it is all contained in one file, instead of spread over subdirs, and dependencies will fall back to internal versions if they aren't found on the system. This work is still in progress! --- diff --git a/.hgignore b/.hgignore index 0992e3e..795dbe1 100644 --- a/.hgignore +++ b/.hgignore @@ -8,3 +8,4 @@ build *~ .*.swp lugaru-* +cmake-build diff --git a/CMakeLists.txt b/CMakeLists.txt index d6061eb..700e9f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,9 @@ project(lugaru) cmake_minimum_required(VERSION 2.6) +set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source") +set(DEPDIR "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies") + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" @@ -20,39 +23,355 @@ if(NOT LUGARU_INSTALL_PREFIX) endif(WIN32) endif(NOT LUGARU_INSTALL_PREFIX) -set(CMAKE_INSTALL_PREFIX "${LUGARU_INSTALL_PREFIX}" CACHE INTERNAL "Prefix -prepended to install directories" FORCE) +set(CMAKE_INSTALL_PREFIX "${LUGARU_INSTALL_PREFIX}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) if(WIN32) set(OPENGL_gl_LIBRARY "-lopengl32" CACHE STRING "OpenGL library for Win32" FORCE) set(OPENGL_glu_LIBRARY "-lglu32" CACHE STRING "GLU library for Win32" FORCE) endif(WIN32) + + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -find_package(OpenAL REQUIRED) -find_package(PNG REQUIRED) -find_package(JPEG REQUIRED) -find_package(ZLIB REQUIRED) + +set(LUGARU_SRCS + ${SRCDIR}/Frustum.cpp + ${SRCDIR}/GameDraw.cpp + ${SRCDIR}/GameInitDispose.cpp + ${SRCDIR}/GameTick.cpp + ${SRCDIR}/Globals.cpp + ${SRCDIR}/Lights.cpp + ${SRCDIR}/Models.cpp + ${SRCDIR}/Objects.cpp + ${SRCDIR}/pack.c + ${SRCDIR}/pack_private.c + ${SRCDIR}/Person.cpp + ${SRCDIR}/private.c + ${SRCDIR}/Quaternions.cpp + ${SRCDIR}/Random.c + ${SRCDIR}/Skeleton.cpp + ${SRCDIR}/Skybox.cpp + ${SRCDIR}/Sprites.cpp + ${SRCDIR}/Terrain.cpp + ${SRCDIR}/Text.cpp + ${SRCDIR}/TGALoader.cpp + ${SRCDIR}/unpack.c + ${SRCDIR}/unpack_private.c + ${SRCDIR}/Weapons.cpp + ${SRCDIR}/OpenGL_Windows.cpp + ${SRCDIR}/openal_wrapper.cpp + ${SRCDIR}/WinInput.cpp + ${SRCDIR}/MacCompatibility.cpp +) + +set(LUGARU_H + ${SRCDIR}/Constants.h + ${SRCDIR}/Frustum.h + ${SRCDIR}/Game.h + ${SRCDIR}/Lights.h + ${SRCDIR}/LinkedList.h + ${SRCDIR}/MacCompatibility.h + ${SRCDIR}/Models.h + ${SRCDIR}/Objects.h + ${SRCDIR}/Person.h + ${SRCDIR}/PhysicsMath.h + ${SRCDIR}/Pointer.h + ${SRCDIR}/Quaternions.h + ${SRCDIR}/Random.h + ${SRCDIR}/Skeleton.h + ${SRCDIR}/Skybox.h + ${SRCDIR}/Sprites.h + ${SRCDIR}/TGALoader.h + ${SRCDIR}/Terrain.h + ${SRCDIR}/Text.h + ${SRCDIR}/Weapons.h + ${SRCDIR}/WinInput.h + ${SRCDIR}/alstubs.h + ${SRCDIR}/binio.h + ${SRCDIR}/fmod.h + ${SRCDIR}/fmod_errors.h + ${SRCDIR}/fmod_header.h + ${SRCDIR}/fmoddyn.h + ${SRCDIR}/gamegl.h + ${SRCDIR}/glstubs.h + ${SRCDIR}/md5.h + ${SRCDIR}/mmgr.h + ${SRCDIR}/nommgr.h + ${SRCDIR}/pack_private.h + ${SRCDIR}/private.h + ${SRCDIR}/unpack_private.h +) + +if(WIN32) + if(CMAKE_CROSSCOMPILING) + ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + COMMAND i686-pc-mingw32-windres + -I${CMAKE_CURRENT_SOURCE_DIR}/res + -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + -i${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc + ) + endif(CMAKE_CROSSCOMPILING) + if(NOT CMAKE_CROSSCOMPILING) + ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + COMMAND windres + -I${CMAKE_CURRENT_SOURCE_DIR}/res + -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + -i${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc + ) + endif(NOT CMAKE_CROSSCOMPILING) + + # !!! FIXME: get rid of this. + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${SRCDIR}/WinDefs.cpp) + + set(LUGARU_H + ${LUGARU_H} + ${SRCDIR}/WinDefs.h + ${SRCDIR}/res/resource.h) +endif(WIN32) + +if (APPLE) + set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL") +endif (APPLE) + + + +# Deal with dependencies... + find_package(OpenGL REQUIRED) -find_package(GLU REQUIRED) -find_package(SDL REQUIRED) -find_package(OggVorbis REQUIRED) +# force this include dir no matter what, so we get sane headers. +set(OPENGL_INCLUDE_DIR "${DEPDIR}/OpenGL") + +find_package(OpenAL REQUIRED) # !!! FIXME: package a .dll for Windows? + +find_package(SDL) +if (NOT SDL) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} SDL") + message(STATUS "SDL not found, using internal copy") + set(SDLDIR "${DEPDIR}/SDL12") + set(SDL_INCLUDE_DIR "${SDLDIR}/include") + set(SDL_LIBRARY "") + if (APPLE) + set(LUGARU_HAS_INTERNAL_SDL True) + set(SDL_LIBRARY + ${SDLDIR}/lib/macosx/libSDL-1.2.0.dylib + ${SDLDIR}/lib/macosx/libSDLmain-osx.a + ) + endif (APPLE) + + if (WINDOWS) + set(LUGARU_HAS_INTERNAL_SDL True) + set(SDL_LIBRARY + ${SDLDIR}/lib/win32/SDL.lib + ${SDLDIR}/lib/win32/SDLmain.lib + ) + endif (WINDOWS) + + if (NOT LUGARU_HAS_INTERNAL_SDL) + message(ERROR "We don't have a prebuilt SDL for this platform.") + endif (NOT LUGARU_HAS_INTERNAL_SDL) +endif (NOT SDL) + +find_package(PNG) +if (NOT PNG) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} PNG") + message(STATUS "libpng not found, using internal copy") + set(PNGDIR "${DEPDIR}/libpng") + set(PNG_INCLUDE_DIR "${PNGDIR}") + set(PNG_LIBRARY "") + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${PNGDIR}/png.c + ${PNGDIR}/pngerror.c + ${PNGDIR}/pngget.c + ${PNGDIR}/pngmem.c + ${PNGDIR}/pngpread.c + ${PNGDIR}/pngread.c + ${PNGDIR}/pngrio.c + ${PNGDIR}/pngrtran.c + ${PNGDIR}/pngrutil.c + ${PNGDIR}/pngset.c + ${PNGDIR}/pngtrans.c + ${PNGDIR}/pngwio.c + ${PNGDIR}/pngwrite.c + ${PNGDIR}/pngwtran.c + ${PNGDIR}/pngwutil.c + ) +endif (NOT PNG) + +find_package(JPEG) +if (NOT JPEG) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} JPEG") + message(STATUS "libjpeg not found, using internal copy") + set(JPEGDIR "${DEPDIR}/libjpeg") + set(JPEG_INCLUDE_DIR "${JPEGDIR}") + set(JPEG_LIBRARY "") + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${JPEGDIR}/jdapistd.c + ${JPEGDIR}/jdmaster.c + ${JPEGDIR}/jdapimin.c + ${JPEGDIR}/jcapimin.c + ${JPEGDIR}/jdmerge.c + ${JPEGDIR}/jdatasrc.c + ${JPEGDIR}/jdatadst.c + ${JPEGDIR}/jdcoefct.c + ${JPEGDIR}/jdcolor.c + ${JPEGDIR}/jddctmgr.c + ${JPEGDIR}/jdhuff.c + ${JPEGDIR}/jdinput.c + ${JPEGDIR}/jdmainct.c + ${JPEGDIR}/jdmarker.c + ${JPEGDIR}/jdpostct.c + ${JPEGDIR}/jdsample.c + ${JPEGDIR}/jdtrans.c + ${JPEGDIR}/jerror.c + ${JPEGDIR}/jidctflt.c + ${JPEGDIR}/jidctfst.c + ${JPEGDIR}/jidctint.c + ${JPEGDIR}/jmemmgr.c + ${JPEGDIR}/jutils.c + ${JPEGDIR}/jmemnobs.c + ${JPEGDIR}/jquant1.c + ${JPEGDIR}/jquant2.c + ${JPEGDIR}/jcomapi.c + ${JPEGDIR}/jcmarker.c + ${JPEGDIR}/jcapistd.c + ${JPEGDIR}/jcparam.c + ${JPEGDIR}/jcinit.c + ${JPEGDIR}/jcdctmgr.c + ${JPEGDIR}/jccoefct.c + ${JPEGDIR}/jcmainct.c + ${JPEGDIR}/jfdctflt.c + ${JPEGDIR}/jfdctint.c + ${JPEGDIR}/jfdctfst.c + ${JPEGDIR}/jchuff.c + ${JPEGDIR}/jcsample.c + ${JPEGDIR}/jcmaster.c + ${JPEGDIR}/jccolor.c + ${JPEGDIR}/jcprepct.c + ${JPEGDIR}/jcarith.c + ${JPEGDIR}/jdarith.c + ${JPEGDIR}/jaricom.c + ) +endif (NOT JPEG) + +find_package(ZLIB) +if (NOT ZLIB) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} ZLIB") + message(STATUS "zlib not found, using internal copy") + set(ZLIBDIR "${DEPDIR}/zlib") + set(ZLIB_INCLUDE_DIR "${ZLIBDIR}") + set(ZLIB_LIBRARIES "") + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${ZLIBDIR}/adler32.c + ${ZLIBDIR}/compress.c + ${ZLIBDIR}/crc32.c + ${ZLIBDIR}/deflate.c + ${ZLIBDIR}/infback.c + ${ZLIBDIR}/inffast.c + ${ZLIBDIR}/inflate.c + ${ZLIBDIR}/inftrees.c + ${ZLIBDIR}/trees.c + ${ZLIBDIR}/uncompr.c + ${ZLIBDIR}/zutil.c + ) +endif (NOT ZLIB) + +find_package(GLU) +if (NOT GLU) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} GLU") + message(STATUS "GLU not found, using internal copy") + set(GLUDIR "${DEPDIR}/GLU") + set(GLU_INCLUDE_DIR "${GLUDIR}") + set(GLU_LIBRARY "") + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${GLUDIR}/dict.c + ${GLUDIR}/geom.c + ${GLUDIR}/memalloc.c + ${GLUDIR}/mesh.c + ${GLUDIR}/mipmap.c + ${GLUDIR}/normal.c + ${GLUDIR}/priorityq.c + ${GLUDIR}/render.c + ${GLUDIR}/sweep.c + ${GLUDIR}/tess.c + ${GLUDIR}/tessmono.c + ${GLUDIR}/util.c + ) +endif (NOT GLU) + +find_package(OggVorbis) +if (NOT OggVorbis) + set(LUGARU_MISSING_DEPS "${LUGARU_MISSING_DEPS} OggVorbis") + message(STATUS "Ogg Vorbis not found, using internal copy") + set(OGGDIR "${DEPDIR}/libogg") + set(OGG_INCLUDE_DIR "${OGGDIR}/include") + set(OGG_LIBRARY "") + set(VORBISDIR "${DEPDIR}/libvorbis") + set(VORBISFILE_INCLUDE_DIR "${VORBISDIR}/include") + set(VORBISFILE_LIBRARY "") + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${OGGDIR}/src/bitwise.c + ${OGGDIR}/src/framing.c + ${VORBISDIR}/lib/analysis.c + ${VORBISDIR}/lib/bitrate.c + ${VORBISDIR}/lib/block.c + ${VORBISDIR}/lib/codebook.c + ${VORBISDIR}/lib/envelope.c + ${VORBISDIR}/lib/floor0.c + ${VORBISDIR}/lib/floor1.c + ${VORBISDIR}/lib/info.c + ${VORBISDIR}/lib/lpc.c + ${VORBISDIR}/lib/lsp.c + ${VORBISDIR}/lib/mapping0.c + ${VORBISDIR}/lib/mdct.c + ${VORBISDIR}/lib/psy.c + ${VORBISDIR}/lib/registry.c + ${VORBISDIR}/lib/res0.c + ${VORBISDIR}/lib/sharedbook.c + ${VORBISDIR}/lib/smallft.c + ${VORBISDIR}/lib/synthesis.c + ${VORBISDIR}/lib/vorbisfile.c + ${VORBISDIR}/lib/window.c + ) +endif (NOT OggVorbis) include_directories( - ${OPENAL_INCLUDE_DIR} - ${JPEG_INCLUDE_DIR} - ${PNG_INCLUDE_DIR} - ${ZLIB_INCLUDE_DIR} - ${OPENGL_INCLUDE_DIR} - ${GLU_INCLUDE_DIR} - ${SDL_INCLUDE_DIR} - ${VORBISFILE_INCLUDE_DIR} - ${OGG_INCLUDE_DIR} - ${CMAKE_SOURCE_DIR}/Source) + ${OPENAL_INCLUDE_DIR} + ${JPEG_INCLUDE_DIR} + ${PNG_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${OPENGL_INCLUDE_DIR} + ${GLU_INCLUDE_DIR} + ${SDL_INCLUDE_DIR} + ${VORBISFILE_INCLUDE_DIR} + ${OGG_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/Source +) -set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL_LIBRARY} ${GLU_LIBRARY} ${OPENGL_LIBRARY} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY}) +set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL_LIBRARY} ${GLU_LIBRARY} ${OPENGL_LIBRARY} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS}) -add_subdirectory(Source) + +if(WIN32) + add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj) +else(WIN32) + add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H}) +endif(WIN32) + +target_link_libraries(lugaru ${LUGARU_LIBS}) + +if(WIN32) + add_definitions(-DUSE_OPENAL=1 -DUSE_SDL=1 -DBinIO_STDINT_HEADER=) +else(WIN32) + add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DUSE_OPENAL=1 -DUSE_SDL=1 -DBinIO_STDINT_HEADER=) +endif(WIN32) # Install target if(WIN32) @@ -63,3 +382,7 @@ endif(WIN32) install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX}) +if (LUGARU_MISSING_DEPS) + message(STATUS "Using our copy of these libs: ${LUGARU_MISSING_DEPS}") +endif (LUGARU_MISSING_DEPS) + diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt deleted file mode 100644 index 5363642..0000000 --- a/Source/CMakeLists.txt +++ /dev/null @@ -1,157 +0,0 @@ -set(LUGARU_SRCS - Frustum.cpp - GameDraw.cpp - GameInitDispose.cpp - GameTick.cpp - Globals.cpp - Lights.cpp - Models.cpp - Objects.cpp - OpenGL_Windows.cpp - Person.cpp - Quaternions.cpp - Random.c - Skeleton.cpp - Skybox.cpp - Sprites.cpp - TGALoader.cpp - Terrain.cpp - Text.cpp - Weapons.cpp - WinInput.cpp - mmgr.cpp - nsp_network.c - openal_wrapper.cpp - pack.c - pack_private.c - private.c - unpack.c - unpack_private.c) - -set(LUGARU_SRCS - Frustum.cpp - GameDraw.cpp - GameInitDispose.cpp - GameTick.cpp - Globals.cpp - Lights.cpp - Models.cpp - Objects.cpp - pack.c - pack_private.c - Person.cpp - private.c - Quaternions.cpp - Random.c - Skeleton.cpp - Skybox.cpp - Sprites.cpp - Terrain.cpp - Text.cpp - TGALoader.cpp - unpack.c - unpack_private.c - Weapons.cpp - OpenGL_Windows.cpp - openal_wrapper.cpp - WinInput.cpp) - -set(LUGARU_H - Constants.h - Frustum.h - Game.h - Lights.h - LinkedList.h - MacCompatibility.h - Models.h - Objects.h - Person.h - PhysicsMath.h - Pointer.h - Quaternions.h - Random.h - Skeleton.h - Skybox.h - Sprites.h - TGALoader.h - Terrain.h - Text.h - Weapons.h - WinInput.h - alstubs.h - binio.h - fmod.h - fmod_errors.h - fmod_header.h - fmoddyn.h - gamegl.h - glstubs.h - md5.h - mmgr.h - nommgr.h - pack_private.h - private.h - unpack_private.h - wincompat.h) - -if(CMAKE_HOST_APPLE) - set(LUGARU_SRCS - ${LUGARU_SRCS} - MacCompatibility.cpp) - set(LUGARU_H - ${LUGARU_H} - "Carbon Include.h" - CarbonStdCLib.h) -endif(CMAKE_HOST_APPLE) - -if(CMAKE_HOST_UNIX) - set(LUGARU_SRCS - ${LUGARU_SRCS} - MacCompatibility.cpp) -endif(CMAKE_HOST_UNIX) - - -if(WIN32) - if(CMAKE_CROSSCOMPILING) - ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj - COMMAND i686-pc-mingw32-windres - -I${CMAKE_CURRENT_SOURCE_DIR}/res - -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj - -i${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc - ) - endif(CMAKE_CROSSCOMPILING) - if(NOT CMAKE_CROSSCOMPILING) - ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj - COMMAND windres - -I${CMAKE_CURRENT_SOURCE_DIR}/res - -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj - -i${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/res/lugaru.rc - ) - endif(NOT CMAKE_CROSSCOMPILING) - - set(LUGARU_SRCS - ${LUGARU_SRCS} - WinDefs.cpp) - - set(LUGARU_H - ${LUGARU_H} - WinDefs.h - res/resource.h) -endif(WIN32) - -if(WIN32) -add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj) -else(WIN32) -add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H}) -endif(WIN32) - -target_link_libraries(lugaru ${LUGARU_LIBS}) - -if(WIN32) - add_definitions(-DUSE_OPENAL=1 -DUSE_SDL=1 -DBinIO_STDINT_HEADER=) -else(WIN32) - add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DUSE_OPENAL=1 -DUSE_SDL=1 -DBinIO_STDINT_HEADER=) -endif(WIN32) -