Skip to content

Commit

Permalink
Merge pull request #3962 from rouault/cmake_UNITY_BUILD
Browse files Browse the repository at this point in the history
Make build compatible of -DCMAKE_UNITY_BUILD=ON for faster builds
  • Loading branch information
rouault authored Nov 29, 2023

Verified

This commit was signed with the committer’s verified signature.
hannojg Hanno J. Gödecke
2 parents ce39a39 + 3edd0f2 commit 8b22f81
Showing 150 changed files with 1,840 additions and 1,453 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -63,7 +63,8 @@ jobs:
set PROJ_DIR=%GITHUB_WORKSPACE%\proj_dir
# Not directly linked to BUILD_SHARED_LIBS, but a way to test different C++ standard versions
if "${{ env.BUILD_SHARED_LIBS }}"=="ON" (set EXTRA_CXX_FLAGS="/std:c++20")
cmake -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" -DBUILD_SHARED_LIBS="${{ env.BUILD_SHARED_LIBS }}" -DCMAKE_C_FLAGS="/WX" -DCMAKE_CXX_FLAGS="/WX %EXTRA_CXX_FLAGS%" -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX="%PROJ_DIR%" -DPROJ_DB_CACHE_DIR=%PROJ_DB_CACHE_DIR% ..
if "${{ env.BUILD_TYPE }}"=="Release" (set CMAKE_UNITY_BUILD_OPT="-DCMAKE_UNITY_BUILD=ON")
cmake -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" -DBUILD_SHARED_LIBS="${{ env.BUILD_SHARED_LIBS }}" -DCMAKE_C_FLAGS="/WX" -DCMAKE_CXX_FLAGS="/WX %EXTRA_CXX_FLAGS%" -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX="%PROJ_DIR%" -DPROJ_DB_CACHE_DIR=%PROJ_DB_CACHE_DIR% %CMAKE_UNITY_BUILD_OPT% ..
ninja -v
ninja install
dir %PROJ_DIR%\bin
@@ -136,7 +137,7 @@ jobs:
PROJ_DIR=${GITHUB_WORKSPACE}/proj_dir
mkdir ${PROJ_BUILD}
cd ${PROJ_BUILD}
cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DBUILD_SHARED_LIBS=${{ env.BUILD_SHARED_LIBS }} -DCMAKE_INSTALL_PREFIX="${PROJ_DIR}" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DUSE_CCACHE=ON -DPROJ_DB_CACHE_DIR=$HOME/.ccache ..
cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DBUILD_SHARED_LIBS=${{ env.BUILD_SHARED_LIBS }} -DCMAKE_INSTALL_PREFIX="${PROJ_DIR}" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DUSE_CCACHE=ON -DCMAKE_UNITY_BUILD=ON -DPROJ_DB_CACHE_DIR=$HOME/.ccache ..
make -j 2
make install
ls ${PROJ_DIR}/bin
11 changes: 11 additions & 0 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
@@ -315,6 +315,17 @@ All cached entries can be viewed using ``cmake -LAH`` from a build directory.
:envvar:`OSGEO4W_ROOT` (if set), otherwise is ``c:/OSGeo4W``.
Default for Unix-like is ``/usr/local/``.

.. option:: CMAKE_UNITY_BUILD=OFF

.. versionadded:: 9.4

Default is OFF. This can be set to ON to build PROJ using the
https://cmake.org/cmake/help/latest/variable/CMAKE_UNITY_BUILD.html feature.
This helps speeding PROJ build times. This feature is still considered
experimental for now, and could hide subtle bugs (we are not aware of
any at writing time though). We don't recommend it for mission critical
builds.

.. option:: ENABLE_IPO=OFF

Build library using the compiler's `interprocedural optimization
28 changes: 14 additions & 14 deletions include/proj/internal/lru_cache.hpp
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ template <typename K, typename V> struct KeyValuePair {
K key;
V value;

KeyValuePair(const K &k, const V &v) : key(k), value(v) {}
KeyValuePair(const K &keyIn, const V &v) : key(keyIn), value(v) {}
};

/**
@@ -122,17 +122,17 @@ class Cache {
cache_.clear();
keys_.clear();
}
void insert(const Key &k, const Value &v) {
void insert(const Key &key, const Value &v) {
Guard g(lock_);
const auto iter = cache_.find(k);
const auto iter = cache_.find(key);
if (iter != cache_.end()) {
iter->second->value = v;
keys_.splice(keys_.begin(), keys_, iter->second);
return;
}

keys_.emplace_front(k, v);
cache_[k] = keys_.begin();
keys_.emplace_front(key, v);
cache_[key] = keys_.begin();
prune();
}
bool tryGet(const Key &kIn, Value &vOut) {
@@ -149,9 +149,9 @@ class Cache {
* The const reference returned here is only
* guaranteed to be valid till the next insert/delete
*/
const Value &get(const Key &k) {
const Value &get(const Key &key) {
Guard g(lock_);
const auto iter = cache_.find(k);
const auto iter = cache_.find(key);
if (iter == cache_.end()) {
throw KeyNotFound();
}
@@ -163,9 +163,9 @@ class Cache {
* The const reference returned here is only
* guaranteed to be valid till the next insert/delete
*/
const Value *getPtr(const Key &k) {
const Value *getPtr(const Key &key) {
Guard g(lock_);
const auto iter = cache_.find(k);
const auto iter = cache_.find(key);
if (iter == cache_.end()) {
return nullptr;
}
@@ -176,20 +176,20 @@ class Cache {
/**
* returns a copy of the stored object (if found)
*/
Value getCopy(const Key &k) { return get(k); }
bool remove(const Key &k) {
Value getCopy(const Key &key) { return get(key); }
bool remove(const Key &key) {
Guard g(lock_);
auto iter = cache_.find(k);
auto iter = cache_.find(key);
if (iter == cache_.end()) {
return false;
}
keys_.erase(iter->second);
cache_.erase(iter);
return true;
}
bool contains(const Key &k) {
bool contains(const Key &key) {
Guard g(lock_);
return cache_.find(k) != cache_.end();
return cache_.find(key) != cache_.end();
}

size_t getMaxSize() const { return maxSize_; }
2 changes: 2 additions & 0 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(CMAKE_UNITY_BUILD OFF)

# Configure executable builds
option(BUILD_APPS
"Build PROJ applications (default value for BUILD_CCT, BUILD_CS2CS, etc.)"
45 changes: 22 additions & 23 deletions src/conversions/axisswap.cpp
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ It is only necessary to specify the axes that are affected by the swap
*
***********************************************************************/

#define PJ_LIB_
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -65,16 +64,16 @@ It is only necessary to specify the axes that are affected by the swap
PROJ_HEAD(axisswap, "Axis ordering");

namespace { // anonymous namespace
struct pj_opaque {
struct pj_axisswap_data {
unsigned int axis[4];
int sign[4];
};
} // anonymous namespace

static int sign(int x) { return (x > 0) - (x < 0); }

static PJ_XY forward_2d(PJ_LP lp, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static PJ_XY pj_axisswap_forward_2d(PJ_LP lp, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
PJ_XY xy;

double in[2] = {lp.lam, lp.phi};
@@ -83,8 +82,8 @@ static PJ_XY forward_2d(PJ_LP lp, PJ *P) {
return xy;
}

static PJ_LP reverse_2d(PJ_XY xy, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static PJ_LP pj_axisswap_reverse_2d(PJ_XY xy, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
unsigned int i;
PJ_COORD out, in;

@@ -98,8 +97,8 @@ static PJ_LP reverse_2d(PJ_XY xy, PJ *P) {
return out.lp;
}

static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static PJ_XYZ pj_axisswap_forward_3d(PJ_LPZ lpz, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
unsigned int i;
PJ_COORD out, in;

@@ -114,8 +113,8 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
return out.xyz;
}

static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static PJ_LPZ pj_axisswap_reverse_3d(PJ_XYZ xyz, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
unsigned int i;
PJ_COORD in, out;

@@ -134,8 +133,8 @@ static void swap_xy_4d(PJ_COORD &coo, PJ *) {
std::swap(coo.xyzt.x, coo.xyzt.y);
}

static void forward_4d(PJ_COORD &coo, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static void pj_axisswap_forward_4d(PJ_COORD &coo, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
unsigned int i;
PJ_COORD out;

@@ -144,8 +143,8 @@ static void forward_4d(PJ_COORD &coo, PJ *P) {
coo = out;
}

static void reverse_4d(PJ_COORD &coo, PJ *P) {
struct pj_opaque *Q = (struct pj_opaque *)P->opaque;
static void pj_axisswap_reverse_4d(PJ_COORD &coo, PJ *P) {
struct pj_axisswap_data *Q = (struct pj_axisswap_data *)P->opaque;
unsigned int i;
PJ_COORD out;

@@ -156,10 +155,10 @@ static void reverse_4d(PJ_COORD &coo, PJ *P) {
}

/***********************************************************************/
PJ *CONVERSION(axisswap, 0) {
PJ *PJ_CONVERSION(axisswap, 0) {
/***********************************************************************/
struct pj_opaque *Q =
static_cast<struct pj_opaque *>(calloc(1, sizeof(struct pj_opaque)));
struct pj_axisswap_data *Q = static_cast<struct pj_axisswap_data *>(
calloc(1, sizeof(struct pj_axisswap_data)));
char *s;
unsigned int i, j, n = 0;

@@ -266,21 +265,21 @@ PJ *CONVERSION(axisswap, 0) {

/* only map fwd/inv functions that are possible with the given axis setup */
if (n == 4) {
P->fwd4d = forward_4d;
P->inv4d = reverse_4d;
P->fwd4d = pj_axisswap_forward_4d;
P->inv4d = pj_axisswap_reverse_4d;
}
if (n == 3 && Q->axis[0] < 3 && Q->axis[1] < 3 && Q->axis[2] < 3) {
P->fwd3d = forward_3d;
P->inv3d = reverse_3d;
P->fwd3d = pj_axisswap_forward_3d;
P->inv3d = pj_axisswap_reverse_3d;
}
if (n == 2) {
if (Q->axis[0] == 1 && Q->sign[0] == 1 && Q->axis[1] == 0 &&
Q->sign[1] == 1) {
P->fwd4d = swap_xy_4d;
P->inv4d = swap_xy_4d;
} else if (Q->axis[0] < 2 && Q->axis[1] < 2) {
P->fwd = forward_2d;
P->inv = reverse_2d;
P->fwd = pj_axisswap_forward_2d;
P->inv = pj_axisswap_reverse_2d;
}
}

4 changes: 1 addition & 3 deletions src/conversions/cart.cpp
Original file line number Diff line number Diff line change
@@ -40,8 +40,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define PJ_LIB_

#include "proj_internal.h"
#include <math.h>

@@ -224,7 +222,7 @@ static PJ_LP cart_reverse(PJ_XY xy, PJ *P) {
}

/*********************************************************************/
PJ *CONVERSION(cart, 1) {
PJ *PJ_CONVERSION(cart, 1) {
/*********************************************************************/
P->fwd3d = cartesian;
P->inv3d = geodetic;
4 changes: 1 addition & 3 deletions src/conversions/geoc.cpp
Original file line number Diff line number Diff line change
@@ -26,8 +26,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define PJ_LIB_

#include <math.h>

#include "proj.h"
@@ -45,7 +43,7 @@ static void inverse(PJ_COORD &coo, PJ *P) {
coo = pj_geocentric_latitude(P, PJ_INV, coo);
}

static PJ *CONVERSION(geoc, 1) {
static PJ *PJ_CONVERSION(geoc, 1) {
P->inv4d = inverse;
P->fwd4d = forward;

4 changes: 1 addition & 3 deletions src/conversions/geocent.cpp
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define PJ_LIB_

#include "proj.h"
#include "proj_internal.h"

@@ -50,7 +48,7 @@ static PJ_LP inverse(PJ_XY xy, PJ *P) {
return lp;
}

PJ *CONVERSION(geocent, 0) {
PJ *PJ_CONVERSION(geocent, 0) {
P->is_geocent = 1;
P->x0 = 0.0;
P->y0 = 0.0;
4 changes: 2 additions & 2 deletions src/conversions/noop.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#define PJ_LIB_


#include "proj_internal.h"

PROJ_HEAD(noop, "No operation");

static void noop(PJ_COORD &, PJ *) {}

PJ *CONVERSION(noop, 0) {
PJ *PJ_CONVERSION(noop, 0) {
P->fwd4d = noop;
P->inv4d = noop;
P->left = PJ_IO_UNITS_WHATEVER;
2 changes: 1 addition & 1 deletion src/conversions/set.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define PJ_LIB_


#include "proj_internal.h"
#include <errno.h>
4 changes: 1 addition & 3 deletions src/conversions/topocentric.cpp
Original file line number Diff line number Diff line change
@@ -25,8 +25,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define PJ_LIB_

#include "proj_internal.h"
#include <errno.h>
#include <math.h>
@@ -75,7 +73,7 @@ static void topocentric_inv(PJ_COORD &coo, PJ *P) {
}

/*********************************************************************/
PJ *CONVERSION(topocentric, 1) {
PJ *PJ_CONVERSION(topocentric, 1) {
/*********************************************************************/
struct pj_opaque *Q =
static_cast<struct pj_opaque *>(calloc(1, sizeof(struct pj_opaque)));
4 changes: 1 addition & 3 deletions src/conversions/unitconvert.cpp
Original file line number Diff line number Diff line change
@@ -63,8 +63,6 @@ Last update: 2017-05-16
*
***********************************************************************/

#define PJ_LIB_

#include <errno.h>
#include <math.h>
#include <string.h>
@@ -437,7 +435,7 @@ static double get_unit_conversion_factor(const char *name, int *p_is_linear,
}

/***********************************************************************/
PJ *CONVERSION(unitconvert, 0) {
PJ *PJ_CONVERSION(unitconvert, 0) {
/***********************************************************************/
struct pj_opaque_unitconvert *Q =
static_cast<struct pj_opaque_unitconvert *>(
1 change: 0 additions & 1 deletion src/deriv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* dervative of (*P->fwd) projection */
#define PJ_LIB_

#include <math.h>

2 changes: 1 addition & 1 deletion src/factors.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* projection scale factors */
#define PJ_LIB_

#include "proj.h"
#include "proj_internal.h"
#include <math.h>
1 change: 0 additions & 1 deletion src/gauss.cpp
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#define PJ_LIB_

#include <math.h>
#include <stdlib.h>
2 changes: 0 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#define PJ_LIB_

#include <ctype.h>
#include <math.h>
#include <stddef.h>
Loading

0 comments on commit 8b22f81

Please sign in to comment.