|
1 |
| -project(tmx-loader) |
2 | 1 | cmake_minimum_required(VERSION 2.8)
|
3 |
| -include_directories(${CMAKE_SOURCE_DIR}/include) |
| 2 | + |
| 3 | +project(tmx-loader) |
| 4 | + |
| 5 | +# Set options |
| 6 | +set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)") |
| 7 | +set(BUILD_SHARED_LIBS TRUE CACHE BOOL "TRUE to build light as shared libraries, FALSE to build it as static libraries") |
| 8 | +set(SFML_STATIC_LIBS FALSE CACHE BOOL "Choose whether SFML is linked statically or not.") |
| 9 | +set(TMX_STATIC_STD_LIBS FALSE CACHE BOOL "Use statically linked standard/runtime libraries? This option must match the one used for SFML.") |
| 10 | +set(TMX_BUILD_EXAMPLE FALSE BOOL CACHE BOOL "TRUE to build the tmx-loader example, FALSE to ignore them") |
4 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
5 |
| -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") |
| 12 | + |
| 13 | +# tmx-loader uses C++11 features |
| 14 | +if(CMAKE_COMPILER_IS_GNUCXX) |
| 15 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 16 | +endif() |
| 17 | + |
| 18 | +# Make sure that the runtime library gets link statically |
| 19 | +if(TMX_STATIC_STD_LIBS) |
| 20 | + if(NOT SFML_STATIC_LIBS) |
| 21 | + message("\n-> If you check TMX_STATIC_STD_LIBS, you also need to check SFML_STATIC_LIBRARIES.") |
| 22 | + message("-> It would lead to multiple runtime environments which result in undefined behavior.\n") |
| 23 | + elseif(WIN32 AND MSVC) |
| 24 | + # Change all MSVC compiler flags to /MT |
| 25 | + foreach(flag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) |
| 26 | + if(${flag} MATCHES "/MD") |
| 27 | + string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") |
| 28 | + endif() |
| 29 | + endforeach() |
| 30 | + elseif(CMAKE_COMPILER_IS_GNUCXX) |
| 31 | + # Note: Doesn't work for TDM compiler, since it's compiling the runtime libs statically by default |
| 32 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") |
| 33 | + endif() |
| 34 | +endif() |
| 35 | + |
| 36 | +# Make sure that FindSFML.cmake searches for the static libraries |
| 37 | +if(SFML_STATIC_LIBS) |
| 38 | + add_definitions(-DSFML_STATIC) |
| 39 | + set(SFML_STATIC_LIBRARIES TRUE) |
| 40 | +endif() |
| 41 | + |
| 42 | +include_directories(${CMAKE_SOURCE_DIR}/include) |
6 | 43 |
|
7 | 44 | set(pugi_HDRS
|
8 | 45 | include/pugixml/pugiconfig.hpp
|
@@ -30,70 +67,116 @@ set(tmx_SRCS
|
30 | 67 | set(maps_SRCS "${PROJECT_SOURCE_DIR}/maps/")
|
31 | 68 | set(fonts_SRCS "${PROJECT_SOURCE_DIR}/fonts/")
|
32 | 69 |
|
33 |
| -add_library(pugi SHARED ${pugi_HDRS} ${pugi_SRCS}) |
34 |
| -add_library(${PROJECT_NAME} SHARED ${tmx_HDRS} ${tmx_SRCS}) |
35 |
| -if (UNIX) |
36 |
| - install(TARGETS pugi ${PROJECT_NAME} LIBRARY DESTINATION lib) |
37 |
| - install(FILES ${tmx_HDRS} DESTINATION include/tmx) |
38 |
| - install(FILES ${pugi_HDRS} DESTINATION include/pugixml) |
39 |
| -endif (UNIX) |
| 70 | +add_library(pugi ${pugi_HDRS} ${pugi_SRCS}) |
| 71 | +add_library(${PROJECT_NAME} ${tmx_HDRS} ${tmx_SRCS}) |
| 72 | + |
40 | 73 |
|
41 |
| -FILE(GLOB maps "${CMAKE_CURRENT_SOURCE_DIR}/maps/*") |
42 |
| -install(FILES ${maps} DESTINATION share/tmx/examples/maps) |
| 74 | +find_package(SFML 2 REQUIRED graphics window system) |
| 75 | + |
| 76 | +if(SFML_FOUND) |
| 77 | + include_directories(${SFML_INCLUDE_DIR}) |
| 78 | +elseif(NOT SFML_FOUND) |
| 79 | + set(SFML_ROOT "" CACHE PATH "SFML top-level directory") |
| 80 | + message("\n-> SFML directory not found. Set SFML_ROOT to SFML's top-level path (containing \"include\" and \"lib\" directories).") |
| 81 | + message("-> Make sure the SFML libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n") |
| 82 | +endif() |
43 | 83 |
|
44 |
| -#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") |
45 |
| -find_package(SFML 2 REQUIRED system window graphics) |
46 | 84 | find_package(ZLIB REQUIRED)
|
| 85 | + |
| 86 | +if(ZLIB_FOUND) |
| 87 | + include_directories(${ZLIB_INCLUDE_DIRS}) |
| 88 | +elseif(NOT ZLIB_FOUND) |
| 89 | + set(ZLIB_ROOT "" CACHE PATH "zlib top-level directory") |
| 90 | + message("\n-> zlib directory not found. Set ZLIB_ROOT to zlib's top-level path (containing \"include\" and \"lib\" directories).") |
| 91 | + message("-> Make sure the zlib libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n") |
| 92 | +endif() |
| 93 | + |
| 94 | + |
47 | 95 | find_package(BOX2D)
|
48 | 96 |
|
49 |
| -if (SFML_FOUND) |
| 97 | +if(BOX2D_FOUND) |
| 98 | + include_directories(${BOX2D_INCLUDE_DIR}) |
| 99 | +elseif(NOT BOX2D_FOUND) |
| 100 | + set(BOX2D_INCLUDE_DIR "" CACHE PATH "Box2D include directory") |
| 101 | + set(BOX2D_LIBRARIES "" CACHE PATH "Box2D lib directory") |
| 102 | + message("\n-> Box2D directories not found. Set BOX2D_INCLUDE_DIR to Box2D's include path and BOX2D_LIBRARIES to Box2D's lib directory path.") |
| 103 | + message("-> Make sure the Box2D libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n") |
| 104 | +endif() |
| 105 | + |
| 106 | +#target_link_libraries(pugi ${ZLIB_LIBRARIES}) |
| 107 | +target_link_libraries(tmx-loader pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
| 108 | + |
| 109 | +# Adjust the output file prefix/suffix to match our conventions |
| 110 | +if(BUILD_SHARED_LIBS) |
| 111 | + if(WIN32) |
| 112 | + set_target_properties(pugi PROPERTIES DEBUG_POSTFIX -d) |
| 113 | + set_target_properties(tmx-loader PROPERTIES DEBUG_POSTFIX -d) |
| 114 | + |
| 115 | + if(CMAKE_COMPILER_IS_GNUCXX) |
| 116 | + # on Windows/gcc get rid of "lib" prefix for shared libraries, |
| 117 | + # and transform the ".dll.a" suffix into ".a" for import libraries |
| 118 | + set_target_properties(pugi PROPERTIES PREFIX "") |
| 119 | + set_target_properties(tmx-loader PROPERTIES PREFIX "") |
| 120 | + set_target_properties(pugi PROPERTIES IMPORT_SUFFIX ".a") |
| 121 | + set_target_properties(tmx-loader PROPERTIES IMPORT_SUFFIX ".a") |
| 122 | + endif() |
| 123 | + endif() |
| 124 | +else() |
| 125 | + set_target_properties(pugi PROPERTIES DEBUG_POSTFIX -s-d) |
| 126 | + set_target_properties(tmx-loader PROPERTIES DEBUG_POSTFIX -s-d) |
| 127 | + set_target_properties(pugi PROPERTIES RELEASE_POSTFIX -s) |
| 128 | + set_target_properties(tmx-loader PROPERTIES RELEASE_POSTFIX -s) |
| 129 | + set_target_properties(pugi PROPERTIES MINSIZEREL_POSTFIX -s) |
| 130 | + set_target_properties(tmx-loader PROPERTIES MINSIZEREL_POSTFIX -s) |
| 131 | +endif() |
| 132 | + |
| 133 | +# Install pugi |
| 134 | +install( |
| 135 | + TARGETS pugi |
| 136 | + RUNTIME DESTINATION bin COMPONENT bin |
| 137 | + LIBRARY DESTINATION lib COMPONENT bin |
| 138 | + ARCHIVE DESTINATION lib COMPONENT dev |
| 139 | +) |
| 140 | + |
| 141 | +# INstall tmx-loader |
| 142 | +install( |
| 143 | + TARGETS tmx-loader |
| 144 | + RUNTIME DESTINATION bin COMPONENT bin |
| 145 | + LIBRARY DESTINATION lib COMPONENT bin |
| 146 | + ARCHIVE DESTINATION lib COMPONENT dev |
| 147 | +) |
| 148 | +install(DIRECTORY include DESTINATION .) |
| 149 | + |
| 150 | +# Build and install the examples |
| 151 | +if(TMX_BUILD_EXAMPLE) |
50 | 152 | add_executable(BenchMark examples/Benchmark.cpp)
|
51 |
| - target_link_libraries(BenchMark ${PROJECT_NAME}) |
52 |
| - target_link_libraries(BenchMark pugi) |
53 |
| - target_link_libraries(BenchMark ${SFML_LIBRARIES}) |
54 |
| - target_link_libraries(BenchMark ${ZLIB_LIBRARIES}) |
| 153 | + target_link_libraries(BenchMark ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
55 | 154 | install(TARGETS BenchMark RUNTIME DESTINATION share/tmx/examples)
|
56 | 155 |
|
57 | 156 | add_executable(DrawWithDebug examples/DrawMapWithDebug.cpp)
|
58 |
| - target_link_libraries(DrawWithDebug ${PROJECT_NAME}) |
59 |
| - target_link_libraries(DrawWithDebug pugi) |
60 |
| - target_link_libraries(DrawWithDebug ${SFML_LIBRARIES}) |
61 |
| - target_link_libraries(DrawWithDebug ${ZLIB_LIBRARIES}) |
| 157 | + target_link_libraries(DrawWithDebug ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
62 | 158 | install(TARGETS DrawWithDebug RUNTIME DESTINATION share/tmx/examples)
|
63 | 159 |
|
64 | 160 | add_executable(Isometric examples/IsometricWithConvertCoords.cpp)
|
65 |
| - target_link_libraries(Isometric ${PROJECT_NAME}) |
66 |
| - target_link_libraries(Isometric pugi) |
67 |
| - target_link_libraries(Isometric ${SFML_LIBRARIES}) |
68 |
| - target_link_libraries(Isometric ${ZLIB_LIBRARIES}) |
| 161 | + target_link_libraries(Isometric ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
69 | 162 | install(TARGETS Isometric RUNTIME DESTINATION share/tmx/examples)
|
70 | 163 |
|
71 | 164 | add_executable(QuadTree examples/MapWithQuadTree.cpp)
|
72 |
| - target_link_libraries(QuadTree ${PROJECT_NAME}) |
73 |
| - target_link_libraries(QuadTree pugi) |
74 |
| - target_link_libraries(QuadTree ${SFML_LIBRARIES}) |
75 |
| - target_link_libraries(QuadTree ${ZLIB_LIBRARIES}) |
| 165 | + target_link_libraries(QuadTree ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
76 | 166 | install(TARGETS QuadTree RUNTIME DESTINATION share/tmx/examples)
|
77 | 167 |
|
78 | 168 | add_executable(ShaderEffects examples/ShaderEffects.cpp)
|
79 |
| - target_link_libraries(ShaderEffects ${PROJECT_NAME}) |
80 |
| - target_link_libraries(ShaderEffects pugi) |
81 |
| - target_link_libraries(ShaderEffects ${SFML_LIBRARIES}) |
82 |
| - target_link_libraries(ShaderEffects ${ZLIB_LIBRARIES}) |
| 169 | + target_link_libraries(ShaderEffects ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES}) |
83 | 170 | install(TARGETS ShaderEffects RUNTIME DESTINATION share/tmx/examples)
|
84 | 171 |
|
85 | 172 | if(BOX2D_FOUND)
|
86 | 173 | add_executable(Box2D examples/Box2D.cpp src/tmx2box2d.cpp)
|
87 |
| - target_link_libraries(Box2D ${PROJECT_NAME}) |
88 |
| - target_link_libraries(Box2D pugi) |
89 |
| - target_link_libraries(Box2D ${SFML_LIBRARIES}) |
90 |
| - target_link_libraries(Box2D ${ZLIB_LIBRARIES}) |
91 |
| - target_link_libraries(Box2D ${BOX2D_LIBRARIES}) |
| 174 | + target_link_libraries(Box2D ${PROJECT_NAME} pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES} ${BOX2D_LIBRARIES}) |
92 | 175 | install(TARGETS Box2D RUNTIME DESTINATION share/tmx/examples)
|
93 |
| - |
94 |
| - endif (BOX2D_FOUND) |
| 176 | + endif() |
95 | 177 |
|
96 |
| - file(COPY ${maps_SRCS} DESTINATION "maps") |
97 |
| - file(COPY ${fonts_SRCS} DESTINATION "fonts") |
98 |
| - |
99 |
| -endif (SFML_FOUND) |
| 178 | + install(DIRECTORY maps/ |
| 179 | + DESTINATION share/tmx/examples/maps) |
| 180 | + install(DIRECTORY fonts/ |
| 181 | + DESTINATION share/tmx/examples/fonts) |
| 182 | +endif() |
0 commit comments