Skip to content

Commit d3bb42c

Browse files
committed
update cmake file to properly build either static or shared libs
1 parent ec2f241 commit d3bb42c

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

CMakeLists.txt

+35-20
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ project(tmx-loader)
44

55
# Set options
66
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")
7+
set(BUILD_SHARED_LIBS TRUE CACHE BOOL "TRUE to build as shared libraries, FALSE to build it as static libraries")
88
set(SFML_STATIC_LIBS FALSE CACHE BOOL "Choose whether SFML is linked statically or not.")
99
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(USE_BOX2D FALSE CACHE BOOL "Use the Box2D functions of the map loader - Requires Box2D if true")
1011
set(TMX_BUILD_EXAMPLE FALSE BOOL CACHE BOOL "TRUE to build the tmx-loader example, FALSE to ignore them")
1112
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
1213

@@ -54,27 +55,40 @@ set(pugi_SRCS
5455
src/pugixml/pugixml.cpp)
5556

5657
set(tmx_HDRS
57-
include/tmx/MapLayer.h
58-
include/tmx/MapLoader.h
59-
include/tmx/MapObject.h
60-
include/tmx/QuadTreeNode.h
61-
include/tmx/DebugShape.h
62-
include/tmx/Helpers.h
63-
include/tmx/Log.h)
58+
include/tmx/MapLayer.hpp
59+
include/tmx/MapLoader.hpp
60+
include/tmx/MapObject.hpp
61+
include/tmx/QuadTreeNode.hpp
62+
include/tmx/DebugShape.hpp
63+
include/tmx/Helpers.hpp
64+
include/tmx/Log.hpp
65+
include/tmx/Export.hpp)
6466

6567
set(tmx_SRCS
66-
src/DebugShape.cpp
68+
src/DebugShape.cpp
6769
src/MapLoaderPublic.cpp
6870
src/MapLoaderPrivate.cpp
6971
src/MapLayer.cpp
7072
src/MapObject.cpp
71-
src/QuadTreeNode.cpp)
72-
73+
src/QuadTreeNode.cpp
74+
src/Log.cpp)
75+
76+
if(USE_BOX2D)
77+
list(APPEND ${tmx_HDRS}
78+
include/tmx/tmx2box2d.hpp)
79+
list(APPEND ${tmx_SRCS}
80+
src/tmx2box2d.cpp)
81+
endif()
82+
7383
set(maps_SRCS "${PROJECT_SOURCE_DIR}/maps/")
7484
set(fonts_SRCS "${PROJECT_SOURCE_DIR}/fonts/")
7585

7686
add_library(pugi ${pugi_HDRS} ${pugi_SRCS})
77-
add_library(${PROJECT_NAME} ${tmx_HDRS} ${tmx_SRCS})
87+
if(BUILD_SHARED_LIBS)
88+
add_library(${PROJECT_NAME} SHARED ${tmx_HDRS} ${tmx_SRCS})
89+
else()
90+
add_library(${PROJECT_NAME} STATIC ${tmx_HDRS} ${tmx_SRCS})
91+
endif()
7892

7993

8094
find_package(SFML 2 REQUIRED graphics window system)
@@ -97,17 +111,18 @@ elseif(NOT ZLIB_FOUND)
97111
message("-> Make sure the zlib libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n")
98112
endif()
99113

114+
if(USE_BOX2D)
115+
find_package(BOX2D)
100116

101-
find_package(BOX2D)
102-
103-
if(BOX2D_FOUND)
104-
include_directories(${BOX2D_INCLUDE_DIR})
105-
elseif(NOT BOX2D_FOUND)
106-
set(BOX2D_INCLUDE_DIR "" CACHE PATH "Box2D include directory")
107-
set(BOX2D_LIBRARIES "" CACHE PATH "Box2D lib directory")
117+
if(BOX2D_FOUND)
118+
include_directories(${BOX2D_INCLUDE_DIR})
119+
elseif(NOT BOX2D_FOUND)
120+
set(BOX2D_INCLUDE_DIR "" CACHE PATH "Box2D include directory")
121+
set(BOX2D_LIBRARIES "" CACHE PATH "Box2D lib directory")
108122
message("\n-> Box2D directories not found. Set BOX2D_INCLUDE_DIR to Box2D's include path and BOX2D_LIBRARIES to Box2D's lib directory path.")
109123
message("-> Make sure the Box2D libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n")
110124
endif()
125+
endif()
111126

112127
#target_link_libraries(pugi ${ZLIB_LIBRARIES})
113128
target_link_libraries(tmx-loader pugi ${SFML_LIBRARIES} ${SFML_DEPENDENCIES} ${ZLIB_LIBRARIES})
@@ -146,7 +161,7 @@ install(
146161

147162
# Install tmx-loader
148163
install(
149-
TARGETS tmx-loader
164+
TARGETS tmx-loader EXPORT tmx-loader-targets
150165
RUNTIME DESTINATION bin COMPONENT bin
151166
LIBRARY DESTINATION lib COMPONENT bin
152167
ARCHIVE DESTINATION lib COMPONENT dev

0 commit comments

Comments
 (0)