From fa8b9084581ae2738580ebf0bb4f7afb366407eb Mon Sep 17 00:00:00 2001 From: Saveliy Skresanov Date: Mon, 25 Mar 2013 21:10:14 +0700 Subject: [PATCH] First try to adapt jacksonmk's cmake script. --- CMakeLists.txt | 227 +++++++++++++++++++++++ cmake/modules/FindClockGettime.cmake | 37 ++++ cmake/modules/FindFFTW3F.cmake | 16 ++ cmake/modules/FindGnuRegex.cmake | 22 +++ cmake/modules/FindSDL.cmake | 176 ++++++++++++++++++ cmake/modules/FindSDL_static_extra.cmake | 26 +++ cmake/modules/FindThreads.cmake | 164 ++++++++++++++++ cmake/modules/FindWinsock.cmake | 24 +++ cmake/toolchain-cross-mingw-linux.cmake | 46 +++++ 9 files changed, 738 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/modules/FindClockGettime.cmake create mode 100644 cmake/modules/FindFFTW3F.cmake create mode 100644 cmake/modules/FindGnuRegex.cmake create mode 100644 cmake/modules/FindSDL.cmake create mode 100644 cmake/modules/FindSDL_static_extra.cmake create mode 100644 cmake/modules/FindThreads.cmake create mode 100644 cmake/modules/FindWinsock.cmake create mode 100644 cmake/toolchain-cross-mingw-linux.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..71ce32a91 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,227 @@ +project(powder) + +cmake_minimum_required(VERSION 2.8) + +# TODO: mingw windres? + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") + +file(GLOB powder_SRC + "src/elements/*.cpp" + "src/*.cpp" + "src/*/*.cpp" + "src/simulation/*/*.cpp" +) + +# TODO: remove this once everything is C++, this is needed because the C++ stuff interacts with stuff in .c files and not all the headers for .c files have extern "C" +# set_source_files_properties(${powder_SRC} PROPERTIES LANGUAGE CXX ) + +include_directories(includes) +include_directories(data) +include_directories(generated) +include_directories(src) +add_executable(powder ${powder_SRC}) + + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_definitions(-DLIN32) + add_definitions(-DLINUX) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + add_definitions(-DWIN32) + add_definitions(-DWINDOWS) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + add_definitions(-DMACOSX) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + + +option(PreferStatic "Prefer linking to static libraries in most cases" ON) +set(CMAKE_FIND_LIBRARY_SUFFIXES_ORIG ${CMAKE_FIND_LIBRARY_SUFFIXES}) +set(CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC .a;) + + +if(PreferStatic AND (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) + if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -static-libstdc++ -static-libgcc") + endif(CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -static-libstdc++ -static-libgcc") + endif(CMAKE_COMPILER_IS_GNUCXX) +endif(PreferStatic AND (${CMAKE_SYSTEM_NAME} MATCHES "Windows")) + + +if(PreferStatic) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC}) + find_package(GnuRegex) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) +endif(PreferStatic) +if(NOT GNUREGEX_FOUND) + find_package(GnuRegex REQUIRED) +endif(NOT GNUREGEX_FOUND) +include_directories(${GNUREGEX_INCLUDE_DIR}) +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + target_link_libraries(powder ${GNUREGEX_LIBRARIES}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + + +if(PreferStatic) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC}) + find_package(SDL) + if(SDL_FOUND) + find_package(SDL_static_extra) + if(NOT SDL_STATIC_EXTRA_LIBRARIES) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) + find_package(SDL_static_extra REQUIRED) + endif(NOT SDL_STATIC_EXTRA_LIBRARIES) + if(SDL_STATIC_EXTRA_LIBRARIES) + include_directories(${SDL_INCLUDE_DIR}) + target_link_libraries(powder ${SDL_LIBRARY}) + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + target_link_libraries(powder ${SDL_STATIC_EXTRA_LIBRARIES}) + endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + else() + set(SDL_FOUND false) + endif() + endif(SDL_FOUND) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) +endif(PreferStatic) +if(NOT SDL_FOUND) + find_package(SDL REQUIRED) + include_directories(${SDL_INCLUDE_DIR}) + target_link_libraries(powder ${SDL_LIBRARY}) +endif(NOT SDL_FOUND) + + +find_package(Threads REQUIRED) +target_link_libraries(powder ${CMAKE_THREAD_LIBS_INIT}) + + +option(GravityFFT "Enable FFTs for Newtonian gravity (makes it faster)" ON) +if (GravityFFT) + if(PreferStatic) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC}) + find_package(FFTW3F) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) + endif(PreferStatic) + if(NOT FFTW3F_FOUND) + find_package(FFTW3F) + endif(NOT FFTW3F_FOUND) + if (FFTW3F_FOUND) + include_directories(${FFTW3F_INCLUDE_DIR}) + target_link_libraries(powder ${FFTW3F_LIBRARIES}) + add_definitions(-DGRAVFFT) + else (FFTW3F_FOUND) + message(STATUS "Package FFTW3F not found, compiling without FFTs for Newtonian gravity") + endif (FFTW3F_FOUND) +endif (GravityFFT) + + +# lm + +if(PreferStatic) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC}) + find_package(BZip2) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) +endif(PreferStatic) +if(NOT BZIP2_FOUND) + find_package(BZip2 REQUIRED) +endif(NOT BZIP2_FOUND) +include_directories(${BZIP2_INCLUDE_DIR}) +target_link_libraries(powder ${BZIP2_LIBRARIES}) + + +option(LuaConsole "Enable Lua console" ON) +if (LuaConsole) + if(PreferStatic) + IF(UNIX AND NOT APPLE) + # For Linux, find maths library first, because otherwise find_package(Lua51) will fail to find the static Lua library if there isn't a static libm + find_library(LUA_MATH_LIBRARY m) + ENDIF(UNIX AND NOT APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ONLY_STATIC}) + find_package(Lua51) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_ORIG}) + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + if(LUA51_FOUND) + FIND_LIBRARY(LUA_EXTRA_LIBS dl) + if(LUA_EXTRA_LIBS STREQUAL "LUA_EXTRA_LIBS-NOTFOUND") + message(STATUS "Could not find libdl, trying dynamic lua51") + unset(LUA51_FOUND) + unset(LUA_LIBRARY CACHE) + unset(LUA_LIBRARIES CACHE) + endif() + endif(LUA51_FOUND) + else(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(LUA_EXTRA_LIBS "") + endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + endif(PreferStatic) + if(NOT LUA51_FOUND) + find_package(Lua51) + set(LUA_EXTRA_LIBS "") + endif(NOT LUA51_FOUND) + if (LUA51_FOUND) + include_directories(${LUA_INCLUDE_DIR}) + target_link_libraries(powder ${LUA_LIBRARIES};${LUA_EXTRA_LIBS}) + add_definitions(-DLUACONSOLE) + else (LUA51_FOUND) + message(STATUS "Package lua51 not found, compiling without Lua console") + endif (LUA51_FOUND) +endif (LuaConsole) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + find_package(ClockGettime REQUIRED) + include_directories(${CLOCK_GETTIME_INCLUDE_DIR}) + target_link_libraries(powder ${CLOCK_GETTIME_LIBRARIES}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + find_package(X11 REQUIRED) + include_directories(${X11_X11_INCLUDE_PATH}) + target_link_libraries(powder ${X11_X11_LIB}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + find_package(Winsock REQUIRED) + include_directories(${WINSOCK_INCLUDE_DIR}) + target_link_libraries(powder ${WINSOCK_LIBRARIES}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + + +option(Optimisations "Enable optimisations" ON) +if (Optimisations) + if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations") + endif(CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations") + endif(CMAKE_COMPILER_IS_GNUCXX) +endif(Optimisations) + +option(Debug "Enable debug symbols" ON) +if (Debug) + if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + endif(CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") + endif(CMAKE_COMPILER_IS_GNUCXX) +endif(Debug) + +option(NoWarnings "Disable compiler warnings" OFF) +if (NoWarnings) + if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") + endif(CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") + endif(CMAKE_COMPILER_IS_GNUCXX) +else(NoWarnings) + if(CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + endif(CMAKE_COMPILER_IS_GNUCC) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + endif(CMAKE_COMPILER_IS_GNUCXX) +endif(NoWarnings) diff --git a/cmake/modules/FindClockGettime.cmake b/cmake/modules/FindClockGettime.cmake new file mode 100644 index 000000000..19cc0f0ab --- /dev/null +++ b/cmake/modules/FindClockGettime.cmake @@ -0,0 +1,37 @@ + +include(CheckFunctionExists) + +if(NOT CLOCK_GETTIME_FOUND) + check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) + if(HAVE_CLOCK_GETTIME) + set(CLOCK_GETTIME_FOUND TRUE) + set(CLOCK_GETTIME_LIBRARIES "") + else() + message(STATUS "clock_gettime() not found, searching for library") + endif() + + if(NOT CLOCK_GETTIME_FOUND) + find_path(CLOCK_GETTIME_INCLUDE_DIR + NAMES + time.h + PATHS + ${LIBRT_PREFIX}/include/ + ) + + find_library( + CLOCK_GETTIME_LIBRARIES rt + PATHS + ${LIBRT_PREFIX}/lib/ + /usr/local/lib64/ + /usr/local/lib/ + /usr/lib/i386-linux-gnu/ + /usr/lib/x86_64-linux-gnu/ + /usr/lib64/ + /usr/lib/ + ) + + find_package_handle_standard_args (clock_gettime DEFAULT_MSG CLOCK_GETTIME_LIBRARIES CLOCK_GETTIME_INCLUDE_DIR) + + mark_as_advanced(CLOCK_GETTIME_LIBRARIES CLOCK_GETTIME_INCLUDE_DIR) + endif() +endif() diff --git a/cmake/modules/FindFFTW3F.cmake b/cmake/modules/FindFFTW3F.cmake new file mode 100644 index 000000000..118de8b1d --- /dev/null +++ b/cmake/modules/FindFFTW3F.cmake @@ -0,0 +1,16 @@ +# - Find FFTW3F +# Find the native FFTW includes and library (single precision version) +# +# FFTW3F_INCLUDE_DIR - where to find fftw3.h +# FFTW3F_LIBRARIES - List of libraries when using FFTW. +# FFTW3F_FOUND - True if FFTW found. + +find_path (FFTW3F_INCLUDE_DIR fftw3.h) +find_library (FFTW3F_LIBRARIES NAMES fftw3f) + +# handle the QUIETLY and REQUIRED arguments and set FFTW3F_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (FFTW3F DEFAULT_MSG FFTW3F_LIBRARIES FFTW3F_INCLUDE_DIR) + +mark_as_advanced (FFTW3F_LIBRARIES FFTW3F_INCLUDE_DIR) diff --git a/cmake/modules/FindGnuRegex.cmake b/cmake/modules/FindGnuRegex.cmake new file mode 100644 index 000000000..48c12482b --- /dev/null +++ b/cmake/modules/FindGnuRegex.cmake @@ -0,0 +1,22 @@ +# - Find GnuRegex +# Find the native GnuRegex includes and library +# +# GNUREGEX_INCLUDE_DIR - where to find regex.h +# GNUREGEX_LIBRARIES - List of libraries when using GnuRegex. +# GNUREGEX_FOUND - True if GnuRegex found. + +find_path (GNUREGEX_INCLUDE_DIR regex.h) +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # Windows, library needed + find_library(GNUREGEX_LIBRARIES NAMES regex gnurx) +else(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # library not needed + set(GNUREGEX_LIBRARIES TRUE) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +# handle the QUIETLY and REQUIRED arguments and set GNUREGEX_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (GnuRegex DEFAULT_MSG GNUREGEX_LIBRARIES GNUREGEX_INCLUDE_DIR) + +mark_as_advanced (GNUREGEX_LIBRARIES GNUREGEX_INCLUDE_DIR) diff --git a/cmake/modules/FindSDL.cmake b/cmake/modules/FindSDL.cmake new file mode 100644 index 000000000..d7d713f7c --- /dev/null +++ b/cmake/modules/FindSDL.cmake @@ -0,0 +1,176 @@ +# Locate SDL library +# This module defines +# SDL_LIBRARY, the name of the library to link against +# SDL_FOUND, if false, do not try to link to SDL +# SDL_INCLUDE_DIR, where to find SDL.h +# +# This is nearly identical to the FindSDL included with cmake +# This is in Powder Toy to avoid warnings when FindThreads is overridden +# +# This module responds to the the flag: +# SDL_BUILDING_LIBRARY +# If this is defined, then no SDL_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 SDL_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDLmain 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 SDL_LIBRARY_TEMP in your configuration +# and no SDL_LIBRARY, it means CMake did not find your SDL library +# (SDL.dll, libsdl.so, SDL.framework, etc). +# Set SDL_LIBRARY_TEMP to point to your SDL library, and configure again. +# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL_LIBRARY +# variable, but when these values are unset, SDL_LIBRARY does not get created. +# +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# 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" SDL guidelines. +# Added a search for SDLmain 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 +# SDL_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 SDL/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL/ (see FreeBSD). + +#============================================================================= +# 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(SDL_INCLUDE_DIR SDL.h + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES include/SDL include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL12 + /usr/local/include/SDL11 # FreeBSD ports + /usr/include/SDL12 + /usr/include/SDL11 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# SDL-1.1 is the name used by FreeBSD ports... +# don't confuse it for the version number. +FIND_LIBRARY(SDL_LIBRARY_TEMP + NAMES SDL SDL-1.1 + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt +) + +IF(NOT SDL_BUILDING_LIBRARY) + IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDLmain for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDLMAIN_LIBRARY + NAMES SDLmain SDLmain-1.1 + HINTS + $ENV{SDLDIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) + ENDIF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL_BUILDING_LIBRARY) + +# SDL 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) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL_LIBRARY_TEMP) + # For SDLmain + IF(NOT SDL_BUILDING_LIBRARY) + IF(SDLMAIN_LIBRARY) + SET(SDL_LIBRARY_TEMP ${SDLMAIN_LIBRARY} ${SDL_LIBRARY_TEMP}) + ENDIF(SDLMAIN_LIBRARY) + ENDIF(NOT SDL_BUILDING_LIBRARY) + + # For OS X, SDL 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(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "-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(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL + REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR) diff --git a/cmake/modules/FindSDL_static_extra.cmake b/cmake/modules/FindSDL_static_extra.cmake new file mode 100644 index 000000000..913c33516 --- /dev/null +++ b/cmake/modules/FindSDL_static_extra.cmake @@ -0,0 +1,26 @@ +# Find some extra libraries needed when linking SDL statically on Windows +# +# SDL_STATIC_EXTRA_LIBRARIES - List of libraries to link +# SDL_STATIC_EXTRA_FOUND - True if all the necessary libraries were found + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + find_library(SDL_STATIC_EXTRA_LIBRARY_DXGUID NAMES dxguid + HINTS + C:/MinGW/lib/) + find_library(SDL_STATIC_EXTRA_LIBRARY_WINMM NAMES winmm + HINTS + C:/MinGW/lib/) + if(SDL_STATIC_EXTRA_LIBRARY_DXGUID AND SDL_STATIC_EXTRA_LIBRARY_WINMM) + set(SDL_STATIC_EXTRA_LIBRARIES "${SDL_STATIC_EXTRA_LIBRARY_DXGUID};${SDL_STATIC_EXTRA_LIBRARY_WINMM}") + endif() +else(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # Do nothing if not on Windows + set(SDL_STATIC_EXTRA_LIBRARY_DXGUID TRUE) + set(SDL_STATIC_EXTRA_LIBRARY_WINMM TRUE) + set(SDL_STATIC_EXTRA_LIBRARIES TRUE) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args (SDL_static_extra DEFAULT_MSG SDL_STATIC_EXTRA_LIBRARY_DXGUID SDL_STATIC_EXTRA_LIBRARY_WINMM SDL_STATIC_EXTRA_LIBRARIES) + +mark_as_advanced(SDL_STATIC_EXTRA_LIBRARY_DXGUID SDL_STATIC_EXTRA_LIBRARY_WINMM SDL_STATIC_EXTRA_LIBRARIES) diff --git a/cmake/modules/FindThreads.cmake b/cmake/modules/FindThreads.cmake new file mode 100644 index 000000000..f99396aad --- /dev/null +++ b/cmake/modules/FindThreads.cmake @@ -0,0 +1,164 @@ +# - This module determines the thread library of the system. +# The following variables are set +# CMAKE_THREAD_LIBS_INIT - the thread library +# CMAKE_USE_SPROC_INIT - are we using sproc? +# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads? +# CMAKE_USE_PTHREADS_INIT - are we using pthreads +# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads + +# custom FindThreads to allow static linking of PTW32 +# (prefers static PTW32 library) + +INCLUDE (CheckIncludeFiles) +INCLUDE (CheckLibraryExists) +SET(Threads_FOUND FALSE) + + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + find_package(Winsock) + set(CMAKE_REQUIRED_LIBRARIES ${WINSOCK_LIBRARIES}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +# Do we have sproc? +IF(CMAKE_SYSTEM MATCHES IRIX) + CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H) +ENDIF(CMAKE_SYSTEM MATCHES IRIX) + +IF(CMAKE_HAVE_SPROC_H) + # We have sproc + SET(CMAKE_USE_SPROC_INIT 1) +ELSE(CMAKE_HAVE_SPROC_H) + # Do we have pthreads? + CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H) + IF(CMAKE_HAVE_PTHREAD_H) + # We have pthread.h + # Let's check for the library now. + SET(CMAKE_HAVE_THREADS_LIBRARY) + IF(NOT THREADS_HAVE_PTHREAD_ARG) + set(CMAKE_THREAD_LIB) + set(CMAKE_HAVE_PTHREADS_CREATE) + find_library(CMAKE_THREAD_LIB NAMES pthreads pthread pthreadGC2 thread) + if (CMAKE_THREAD_LIB) + CHECK_LIBRARY_EXISTS(${CMAKE_THREAD_LIB} pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) + if(CMAKE_HAVE_PTHREADS_CREATE) + message(STATUS "Checking whether pthreads is static pthreads-win32") + set(CMAKE_REQUIRED_DEFINITIONS -DPTW32_STATIC_LIB) + set(CMAKE_PTHREADS_W32_STATIC) + CHECK_LIBRARY_EXISTS(${CMAKE_THREAD_LIB} pthread_win32_process_detach_np "" CMAKE_PTHREADS_W32_STATIC) + SET(CMAKE_REQUIRED_DEFINITIONS "") + if(CMAKE_PTHREADS_W32_STATIC) + message(STATUS "Static pthreads-win32 found") + ADD_DEFINITIONS("-DPTW32_STATIC_LIB") + endif() + SET(CMAKE_THREAD_LIBS_INIT ${CMAKE_THREAD_LIB}) + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + SET(Threads_FOUND TRUE) + endif(CMAKE_HAVE_PTHREADS_CREATE) + endif(CMAKE_THREAD_LIB) + + if(NOT CMAKE_HAVE_PTHREADS_CREATE) + # Original behaviour + # Do we have -lpthreads + CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) + IF(CMAKE_HAVE_PTHREADS_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lpthreads") + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + SET(Threads_FOUND TRUE) + ENDIF(CMAKE_HAVE_PTHREADS_CREATE) + # Ok, how about -lpthread + CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) + IF(CMAKE_HAVE_PTHREAD_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lpthread") + SET(Threads_FOUND TRUE) + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + ENDIF(CMAKE_HAVE_PTHREAD_CREATE) + IF(CMAKE_SYSTEM MATCHES "SunOS.*") + # On sun also check for -lthread + CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) + IF(CMAKE_HAVE_THR_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lthread") + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + SET(Threads_FOUND TRUE) + ENDIF(CMAKE_HAVE_THR_CREATE) + ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*") + endif(NOT CMAKE_HAVE_PTHREADS_CREATE) + ENDIF(NOT THREADS_HAVE_PTHREAD_ARG) + + IF(NOT CMAKE_HAVE_THREADS_LIBRARY) + # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread + IF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG") + MESSAGE(STATUS "Check if compiler accepts -pthread") + TRY_RUN(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG + ${CMAKE_BINARY_DIR} + ${CMAKE_ROOT}/Modules/CheckForPthreads.c + CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread + COMPILE_OUTPUT_VARIABLE OUTPUT) + IF(THREADS_HAVE_PTHREAD_ARG) + IF(THREADS_PTHREAD_ARG MATCHES "^2$") + SET(Threads_FOUND TRUE) + MESSAGE(STATUS "Check if compiler accepts -pthread - yes") + ELSE(THREADS_PTHREAD_ARG MATCHES "^2$") + MESSAGE(STATUS "Check if compiler accepts -pthread - no") + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n") + ENDIF(THREADS_PTHREAD_ARG MATCHES "^2$") + ELSE(THREADS_HAVE_PTHREAD_ARG) + MESSAGE(STATUS "Check if compiler accepts -pthread - no") + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n") + ENDIF(THREADS_HAVE_PTHREAD_ARG) + ENDIF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG") + IF(THREADS_HAVE_PTHREAD_ARG) + SET(Threads_FOUND TRUE) + SET(CMAKE_THREAD_LIBS_INIT "-pthread") + ENDIF(THREADS_HAVE_PTHREAD_ARG) + ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY) + ENDIF(CMAKE_HAVE_PTHREAD_H) +ENDIF(CMAKE_HAVE_SPROC_H) + +IF(CMAKE_THREAD_LIBS_INIT) + SET(CMAKE_USE_PTHREADS_INIT 1) + SET(Threads_FOUND TRUE) +ENDIF(CMAKE_THREAD_LIBS_INIT) + +IF(CMAKE_SYSTEM MATCHES "Windows") + SET(CMAKE_USE_WIN32_THREADS_INIT 1) + SET(Threads_FOUND TRUE) +ENDIF(CMAKE_SYSTEM MATCHES "Windows") + +IF(CMAKE_USE_PTHREADS_INIT) + IF(CMAKE_SYSTEM MATCHES "HP-UX-*") + # Use libcma if it exists and can be used. It provides more + # symbols than the plain pthread library. CMA threads + # have actually been deprecated: + # http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395 + # http://docs.hp.com/en/947/d8.html + # but we need to maintain compatibility here. + # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads + # are available. + CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) + IF(CMAKE_HAVE_HP_CMA) + SET(CMAKE_THREAD_LIBS_INIT "-lcma") + SET(CMAKE_HP_PTHREADS_INIT 1) + SET(Threads_FOUND TRUE) + ENDIF(CMAKE_HAVE_HP_CMA) + SET(CMAKE_USE_PTHREADS_INIT 1) + ENDIF(CMAKE_SYSTEM MATCHES "HP-UX-*") + + IF(CMAKE_SYSTEM MATCHES "OSF1-V*") + SET(CMAKE_USE_PTHREADS_INIT 0) + SET(CMAKE_THREAD_LIBS_INIT ) + ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V*") + + IF(CMAKE_SYSTEM MATCHES "CYGWIN_NT*") + SET(CMAKE_USE_PTHREADS_INIT 1) + SET(Threads_FOUND TRUE) + SET(CMAKE_THREAD_LIBS_INIT ) + SET(CMAKE_USE_WIN32_THREADS_INIT 0) + ENDIF(CMAKE_SYSTEM MATCHES "CYGWIN_NT*") +ENDIF(CMAKE_USE_PTHREADS_INIT) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND) diff --git a/cmake/modules/FindWinsock.cmake b/cmake/modules/FindWinsock.cmake new file mode 100644 index 000000000..032ef2309 --- /dev/null +++ b/cmake/modules/FindWinsock.cmake @@ -0,0 +1,24 @@ +# - Find Winsock +# Find the Windows socket includes and library +# +# WINSOCK_INCLUDE_DIR - where to find regex.h +# WINSOCK_LIBRARIES - List of libraries when using Winsock. +# WINSOCK_FOUND - True if Winsock found. + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + find_path(WINSOCK_INCLUDE_DIR winsock2.h + HINTS + C:/MinGW/include/) + find_library(WINSOCK_LIBRARIES NAMES ws2_32 + HINTS + C:/MinGW/lib/) +else(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # Do nothing if not on Windows + set(WINSOCK_INCLUDE_DIR TRUE) + set(WINSOCK_LIBRARIES TRUE) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args (Winsock DEFAULT_MSG WINSOCK_LIBRARIES WINSOCK_INCLUDE_DIR) + +mark_as_advanced(WINSOCK_LIBRARIES WINSOCK_INCLUDE_DIR) diff --git a/cmake/toolchain-cross-mingw-linux.cmake b/cmake/toolchain-cross-mingw-linux.cmake new file mode 100644 index 000000000..0b0714510 --- /dev/null +++ b/cmake/toolchain-cross-mingw-linux.cmake @@ -0,0 +1,46 @@ +# adapted from http://www.cmake.org/Wiki/File:Toolchain-cross-mingw32-linux.cmake + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +IF(NOT ("${GNU_HOST}" STREQUAL "")) + find_program(CC_GNUHOST NAMES ${GNU_HOST}-gcc) +ENDIF() + +if(CC_GNUHOST) + set(COMPILER_PREFIX "${GNU_HOST}") +else() + find_program(CC_W64 NAMES i686-w64-mingw32-gcc) + if(CC_W64) + # for 32 or 64 bits mingw-w64 + # see http://mingw-w64.sourceforge.net/ + set(COMPILER_PREFIX "i686-w64-mingw32") + else() + # for classical mingw32 + # see http://www.mingw.org/ + set(COMPILER_PREFIX "i586-mingw32msvc") + endif() +endif() + +#set(COMPILER_PREFIX "x86_64-w64-mingw32" + +# which compilers to use for C and C++ +find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) +#SET(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres) +find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) +#SET(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc) +find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) +#SET(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++) + + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw) +SET(CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_FIND_ROOT_PATH}) # needed to make FindSDL find includes + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +