From 4a30800cf16d403a7c25d78388e2822aa396ac86 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 22 Mar 2013 18:19:53 +0100 Subject: Fixes for compiling on MSYS * fixed SDL_main() and putenv() issues * disabled desktop subdir for MSYS * disabled building CBot_console for now --- CMakeLists.txt | 18 +++++++++++++++++- src/CBot/CMakeLists.txt | 5 ++++- src/CMakeLists.txt | 20 ++++++++------------ src/app/app.cpp | 4 ++-- src/app/main.cpp | 7 ++++++- src/app/system_other.h | 2 +- src/common/config.h.cmake | 12 ++++++++++-- src/common/image.cpp | 4 ++-- src/common/key.h | 2 +- src/common/restext.cpp | 2 +- src/desktop/CMakeLists.txt | 2 +- src/graphics/engine/terrain.cpp | 2 +- src/graphics/engine/text.cpp | 4 ++-- src/graphics/opengl/gldevice.cpp | 2 +- src/tools/CMakeLists.txt | 2 ++ test/cbot/CMakeLists.txt | 2 +- test/envs/opengl/light_test.cpp | 12 +++++++++--- test/envs/opengl/model_test.cpp | 12 +++++++++--- test/envs/opengl/texture_test.cpp | 12 +++++++++--- test/envs/opengl/transform_test.cpp | 12 +++++++++--- test/unit/CMakeLists.txt | 33 ++++++++++++++++++++------------- test/unit/common/image_test.cpp | 2 +- 22 files changed, 117 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e25826..60839be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS}" set(COLOBOT_CXX_FLAGS_RELEASE "-O2") set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0") + # Asserts can be enabled/disabled regardless of build type option(ASSERTS "Enable assert()s" ON) @@ -83,6 +84,9 @@ option(TESTS "Enable tests" ON) # CBot can also be a static library option(CBOT_STATIC "Build CBot as static libary" OFF) +# Generate desktop files, manpage, etc. +option(DESKTOP ON) + # Doxygen docs are optional for installation option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) @@ -90,8 +94,16 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) option(OPENAL_SOUND "Build openal sound support" OFF) +# Hacks for MSYS +if (MSYS) + set(COLOBOT_CXX_FLAGS "${COLOBOT_CXX_FLAGS} -U__STRICT_ANSI__") # fixes putenv() + set(USE_SDL_MAIN 1) # fixes SDL_main + set(DESKTOP OFF) # MSYS doesn't have the necessary tools +endif() + + ## -# Required packages +# Searching for packages ## find_package(OpenGL 1.4 REQUIRED) @@ -115,6 +127,10 @@ find_package(GLEW REQUIRED) include("${colobot_SOURCE_DIR}/cmake/FindLibSndFile.cmake") +if (${OPENAL_SOUND}) + find_package(OpenAL REQUIRED) +endif() + ## # Additional settings to use when cross-compiling with MXE (http://mxe.cc/) diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index daf08c6..fecd18e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -16,5 +16,8 @@ if(${CBOT_STATIC}) add_library(CBot STATIC ${SOURCES}) else() add_library(CBot SHARED ${SOURCES}) - install(TARGETS CBot LIBRARY DESTINATION ${COLOBOT_INSTALL_LIB_DIR}) + install(TARGETS CBot LIBRARY + DESTINATION ${COLOBOT_INSTALL_LIB_DIR} + ARCHIVE DESTINATION ${COLOBOT_INSTALL_LIB_DIR} + RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc181f2..3d6908d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,22 +12,18 @@ add_subdirectory(tools) add_subdirectory(po) -add_subdirectory(desktop) +if(${DESKTOP}) + add_subdirectory(desktop) +endif() # Optional libraries set(OPTIONAL_LIBS "") +set(OPTIONAL_INCLUDES "") if (${OPENAL_SOUND}) - if (${PLATFORM_WINDOWS}) - set(OPTIONAL_LIBS - OpenAL32 - ) - else() - set(OPTIONAL_LIBS - openal - ) - endif() + set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) + set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) endif() # Additional libraries per platform @@ -196,8 +192,8 @@ ${OPENGL_LIBRARY} ${PNG_LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} -${OPTIONAL_LIBS} ${LIBSNDFILE_LIBRARY} +${OPTIONAL_LIBS} ${PLATFORM_LIBS} ) @@ -217,8 +213,8 @@ ${SDLTTF_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${Boost_INCLUDE_DIRS} -${OPTIONAL_INCLUDE_DIRS} ${LIBSNDFILE_INCLUDE_DIR} +${OPTIONAL_INCLUDE_DIRS} ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) diff --git a/src/app/app.cpp b/src/app/app.cpp index cb1ac34..e84091b 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -33,8 +33,8 @@ #include -#include -#include +#include +#include #include #include diff --git a/src/app/main.cpp b/src/app/main.cpp index e621065..0622370 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,6 +23,7 @@ #include "app/app.h" #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/misc.h" #include "common/restext.h" @@ -70,7 +71,10 @@ The current layout is the following: //! Entry point to the program -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; // Create the logger @@ -111,3 +115,4 @@ int main(int argc, char *argv[]) return code; } +} // extern "C" diff --git a/src/app/system_other.h b/src/app/system_other.h index 6fb4b86..aee3536 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -22,7 +22,7 @@ #include "app/system.h" -#include +#include #include diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index 1595e09..d5a03b4 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -7,11 +7,19 @@ #cmakedefine GLEW_STATIC +#cmakedefine OPENAL_SOUND + +#cmakedefine USE_SDL_MAIN @USE_SDL_MAIN@ + +#ifdef USE_SDL_MAIN +#define SDL_MAIN_FUNC SDL_main +#else +#define SDL_MAIN_FUNC main +#endif + #define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@" #define COLOBOT_CODENAME "@COLOBOT_VERSION_CODENAME@" #define COLOBOT_FULLNAME "Colobot @COLOBOT_VERSION_CODENAME@" #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" - -#cmakedefine OPENAL_SOUND diff --git a/src/common/image.cpp b/src/common/image.cpp index be5711d..db14797 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/src/common/key.h b/src/common/key.h index 196f66d..84ee618 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -22,7 +22,7 @@ #pragma once -#include "SDL/SDL_keysym.h" +#include /* Key definitions are specially defined here so that it is clear in other parts of the code that these are used. It is to avoid having SDL-related enum values or #defines lying around diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 4768aed..a6c33a3 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -30,7 +30,7 @@ #include "object/robotmain.h" #include -#include +#include const char* stringsText[RT_MAX] = { nullptr }; const char* stringsEvent[EVENT_STD_MAX] = { nullptr }; diff --git a/src/desktop/CMakeLists.txt b/src/desktop/CMakeLists.txt index ce4f48d..9a00dd4 100644 --- a/src/desktop/CMakeLists.txt +++ b/src/desktop/CMakeLists.txt @@ -39,7 +39,7 @@ endif() # Create manpage from pod-formatted file find_program(POD2MAN pod2man) -if(POD2MAN) +if(POD2MAN AND (NOT MSYS)) set(COLOBOT_MANPAGE_SECTION 6) macro(podman) diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 8f7ad26..c2a7855 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -30,7 +30,7 @@ #include -#include +#include // Graphics module namespace diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 9dea129..308c813 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -26,8 +26,8 @@ #include "math/func.h" -#include -#include +#include +#include // Graphics module namespace diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index beeb85e..df64e34 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -27,7 +27,7 @@ // Using GLEW so only glew.h is needed #include -#include +#include #include diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3653357..0be2bd5 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -7,6 +7,8 @@ convert_model.cpp include_directories(. ..) +include_directories(SYSTEM ${SDL_INCLUDE_DIR}) + add_definitions(-DMODELFILE_NO_ENGINE) add_executable(convert_model ${CONVERT_MODEL_SOURCES}) diff --git a/test/cbot/CMakeLists.txt b/test/cbot/CMakeLists.txt index e864ed5..e087ea5 100644 --- a/test/cbot/CMakeLists.txt +++ b/test/cbot/CMakeLists.txt @@ -1,2 +1,2 @@ # CBot console interpreter -add_subdirectory(CBot_console) +#add_subdirectory(CBot_console) diff --git a/test/envs/opengl/light_test.cpp b/test/envs/opengl/light_test.cpp index b1e0151..d4635cc 100644 --- a/test/envs/opengl/light_test.cpp +++ b/test/envs/opengl/light_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -7,8 +8,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -357,7 +358,10 @@ void MouseMove(int x, int y) ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -460,3 +464,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/envs/opengl/model_test.cpp b/test/envs/opengl/model_test.cpp index 882b785..168eb32 100644 --- a/test/envs/opengl/model_test.cpp +++ b/test/envs/opengl/model_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -8,8 +9,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -257,7 +258,10 @@ void KeyboardUp(SDLKey key) } } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -378,3 +382,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/envs/opengl/texture_test.cpp b/test/envs/opengl/texture_test.cpp index b1f352c..5c27b43 100644 --- a/test/envs/opengl/texture_test.cpp +++ b/test/envs/opengl/texture_test.cpp @@ -1,3 +1,4 @@ +#include "common/config.h" #include "common/logger.h" #include "common/image.h" @@ -5,8 +6,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include @@ -124,7 +125,10 @@ void Render(Gfx::CGLDevice *device) device->EndScene(); } -int main() +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -192,3 +196,5 @@ int main() return 0; } + +} // extern "C" diff --git a/test/envs/opengl/transform_test.cpp b/test/envs/opengl/transform_test.cpp index 04c73f7..02f9d83 100644 --- a/test/envs/opengl/transform_test.cpp +++ b/test/envs/opengl/transform_test.cpp @@ -1,5 +1,6 @@ #include "app/system.h" +#include "common/config.h" #include "common/logger.h" #include "common/image.h" #include "common/iman.h" @@ -8,8 +9,8 @@ #include "math/geometry.h" -#include -#include +#include +#include #include #include @@ -235,7 +236,10 @@ void MouseMove(int x, int y) ROTATION.x = ROTATION_BASE.x + (static_cast (y - MOUSE_POS_BASE.y) / 600.0f) * Math::PI; } -int main(int argc, char *argv[]) +extern "C" +{ + +int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; @@ -338,3 +342,5 @@ int main(int argc, char *argv[]) return 0; } + +} // extern "C" diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 34027b8..f3be01d 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -158,15 +158,8 @@ endif() set(OPTIONAL_LIBS "") if (${OPENAL_SOUND}) - if (${PLATFORM_WINDOWS}) - set(OPTIONAL_LIBS - OpenAL32 - ) - else() - set(OPTIONAL_LIBS - openal - ) - endif() + set(OPTIONAL_LIBS ${OPENAL_LIBRARY}) + set(OPTIONAL_INCLUDES ${OPENAL_INCLUDE_DIR}) endif() @@ -189,14 +182,28 @@ math/vector_test.cpp ${PLATFORM_TESTS} ) +# Local include_directories( -${CMAKE_CURRENT_BINARY_DIR} -${SRC_DIR} -${GTEST_INCLUDE_DIR} -${GMOCK_INCLUDE_DIR} . common math +${SRC_DIR} +${CMAKE_CURRENT_BINARY_DIR} +) + +# System +include_directories( +SYSTEM +${GTEST_INCLUDE_DIR} +${GMOCK_INCLUDE_DIR} +${SDL_INCLUDE_DIR} +${SDLIMAGE_INCLUDE_DIR} +${SDLTTF_INCLUDE_DIR} +${PNG_INCLUDE_DIRS} +${GLEW_INCLUDE_PATH} +${Boost_INCLUDE_DIRS} +${OPTIONAL_INCLUDE_DIRS} +${LIBSNDFILE_INCLUDE_DIR} ) set(LIBS diff --git a/test/unit/common/image_test.cpp b/test/unit/common/image_test.cpp index 2a8d5e4..2b20a17 100644 --- a/test/unit/common/image_test.cpp +++ b/test/unit/common/image_test.cpp @@ -1,6 +1,6 @@ #include "common/image.h" -#include +#include #include /* For now, just a simple test: loading a file from image -- cgit v1.2.3-1-g7c22