Skip to content

Commit

Permalink
Merge pull request geo-data#11 from Jule-/master
Browse files Browse the repository at this point in the history
Visual Studio compilation with CMake
  • Loading branch information
homme committed Nov 24, 2014
2 parents ba59bba + 61ed2e7 commit cbddc79
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 26 deletions.
27 changes: 19 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
if(NOT MSVC)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
endif()

# We need g++ >= version 4.7 (see
Expand Down Expand Up @@ -52,8 +54,17 @@ install(FILES ${PROJECT_BINARY_DIR}/config.hpp DESTINATION include/ctb)

# Perform as many checks as possible on debug builds:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra --pedantic")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra --pedantic")
if(NOT MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra --pedantic")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra --pedantic")
endif()

# We need GDAL
find_package(GDAL)
if(NOT GDAL_FOUND)
message(FATAL_ERROR "The GDAL library cannot be found on the system")
endif()
include_directories(${GDAL_INCLUDE_DIRS})

# Build and install libctb
include_directories("${PROJECT_SOURCE_DIR}/src")
Expand Down
11 changes: 2 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# We need GDAL
find_package(GDAL)
if(NOT GDAL_FOUND)
message(FATAL_ERROR "The GDAL library cannot be found on the system")
endif()
include_directories(${GDAL_INCLUDE_DIRS})

# Ensure we have a unified GDAL: `GDALOpenEx` is only present after
# unification.
include(CheckLibraryExists)
check_library_exists(gdal GDALOpenEx "gdal.h" HAVE_UNIFIED_GDAL)
if(NOT HAVE_UNIFIED_GDAL)
if(NOT MSVC AND NOT HAVE_UNIFIED_GDAL)
message(FATAL_ERROR "The GDAL version must be one that implements RFC 46 (GDAL/OGR unification) i.e. >= 2.0.0")
endif(NOT HAVE_UNIFIED_GDAL)
endif()

# We need zlib
find_package(ZLIB)
Expand Down
3 changes: 2 additions & 1 deletion src/GDALTile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "gdal_priv.h"

#include "config.hpp" // for CTB_DLL
#include "Tile.hpp"

namespace ctb {
Expand All @@ -41,7 +42,7 @@ namespace ctb {
* linear approximation) which wraps an image transformer. The VRT owns any top
* level transformer, but we are responsible for the wrapped image transformer.
*/
class ctb::GDALTile :
class CTB_DLL ctb::GDALTile :
public Tile
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/GDALTiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ctb::TilerOptions {
* the reference count is decremented and, if it reaches `0`, the dataset is
* closed.
*/
class ctb::GDALTiler {
class CTB_DLL ctb::GDALTiler {
public:

/// Instantiate a tiler with all required arguments
Expand Down
2 changes: 1 addition & 1 deletion src/GlobalGeodetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace ctb {
* This class models the [Tile Mapping Service Global Geodetic
* Profile](http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).
*/
class ctb::GlobalGeodetic:
class CTB_DLL ctb::GlobalGeodetic :
public Grid {
public:

Expand Down
3 changes: 2 additions & 1 deletion src/GlobalMercator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @brief This defines the `GlobalMercator` class
*/

#include "config.hpp" // for CTB_DLL
#include "Grid.hpp"

namespace ctb {
Expand All @@ -34,7 +35,7 @@ namespace ctb {
* This class models the [Tile Mapping Service Global Mercator
* Profile](http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-mercator).
*/
class ctb::GlobalMercator:
class CTB_DLL ctb::GlobalMercator :
public Grid {
public:

Expand Down
4 changes: 2 additions & 2 deletions src/TerrainTile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace ctb {
* This aims to implement the Cesium [heightmap-1.0 terrain
* format](http://cesiumjs.org/data-and-assets/terrain/formats/heightmap-1.0.html).
*/
class ctb::Terrain {
class CTB_DLL ctb::Terrain {
public:

/// Create an empty terrain object
Expand Down Expand Up @@ -180,7 +180,7 @@ class ctb::Terrain {
* Associating terrain data with a tile coordinate allows the tile to be
* converted to a geo-referenced raster (see `TerrainTile::heightsToRaster`).
*/
class ctb::TerrainTile :
class CTB_DLL ctb::TerrainTile :
public Terrain, public Tile
{
friend class TerrainTiler;
Expand Down
2 changes: 1 addition & 1 deletion src/TerrainTiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ctb {
* `GDALTiler::createTerrainTile` method enabling `TerrainTile`s to be created
* for a specific `TileCoordinate`.
*/
class ctb::TerrainTiler :
class CTB_DLL ctb::TerrainTiler :
public GDALTiler
{
public:
Expand Down
14 changes: 14 additions & 0 deletions src/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
* `config.hpp`.
*/

/* Enable symbol export in Visual Studio 2013 as per issue #6. This is an
adaptation of `CPL_DLL` in GDAL's `cpl_port.h`. */
#ifndef CTB_DLL
#if defined(_MSC_VER)
# if !defined(CPL_DISABLE_DLL)
# define CTB_DLL __declspec(dllexport)
# else
# define CTB_DLL __declspec(dllimport)
# endif
#else
# define CTB_DLL
#endif
#endif

#include <string>
#include <sstream>

Expand Down
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# The tools are not shared libraries
add_definitions(-DCPL_DISABLE_DLL)

set(TOOL_TARGETS commander ctb)

# Add the `ctb-tile` executable
Expand Down
4 changes: 2 additions & 2 deletions tools/ctb-tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ setIteratorSize(T &iter) {

/// A thread safe wrapper around `GDALTermProgress`
static int
termProgress(double dfComplete, const char *pszMessage, void *pProgressArg) {
CPL_STDCALL termProgress(double dfComplete, const char *pszMessage, void *pProgressArg) {
static mutex mutex; // GDALTermProgress isn't thread safe, so lock it
int status;

Expand All @@ -274,7 +274,7 @@ termProgress(double dfComplete, const char *pszMessage, void *pProgressArg) {

/// In a thread safe manner describe the file just created
static int
verboseProgress(double dfComplete, const char *pszMessage, void *pProgressArg) {
CPL_STDCALL verboseProgress(double dfComplete, const char *pszMessage, void *pProgressArg) {
stringstream stream;
stream << "[" << (int) (dfComplete*100) << "%] " << pszMessage << endl;
cout << stream.str();
Expand Down

0 comments on commit cbddc79

Please sign in to comment.