Skip to content

Commit d2063f3

Browse files
committed
master: Add -m32 flag to cmake command.
1. Remove certian test from 32 bit compile case. 2. compile_source_test.cmake: set compiler flags (Bug fix). player.hpp: avoid double definition of setup_random (Bug fix).
1 parent 21af7f7 commit d2063f3

File tree

21 files changed

+188
-53
lines changed

21 files changed

+188
-53
lines changed

CMakeLists.txt

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ IF( POLICY CMP0054 )
1616
ENDIF( POLICY CMP0054 )
1717
#
1818
# cppad_version is used by version.sh to get the version number.
19-
SET(cppad_version "20250114")
19+
SET(cppad_version "20250117")
2020
SET(cppad_url "https://coin-or.github.io/CppAD" )
2121
SET(cppad_description "Differentiation of C++ Algorithms" )
2222
IF( NOT DEFINED CMAKE_BUILD_TYPE)
@@ -176,6 +176,11 @@ command_line_arg(cppad_cxx_flags "" STRING
176176
"compile flags used with cppad (besides debug, release, and profile flags)"
177177
)
178178
#
179+
# cppad_link_flags
180+
command_line_arg(cppad_link_flags "" STRING
181+
"additional linker flags)"
182+
)
183+
#
179184
# cppad_profile_flag
180185
command_line_arg(cppad_profile_flag NOTFOUND STRING
181186
"compile flag used to compile and link a profile version of a program"
@@ -473,22 +478,42 @@ FOREACH(dir_types includedirs libdirs datadir docdir)
473478
ENDIF( cppad_postfix )
474479
ENDFOREACH(dir_types includedirs libdirs datadir docdir)
475480
# -----------------------------------------------------------------------------
481+
# cppad_link_flags_has_m32
482+
STRING( FIND "${cppad_link_flags}" "-m32" index)
483+
IF( "${index}" STREQUAL "-1" )
484+
SET(cppad_link_flags_has_m32 0)
485+
ELSE ( )
486+
SET(cppad_link_flags_has_m32 1)
487+
ENDIF( )
488+
# -----------------------------------------------------------------------------
476489
# OpenMP_CXX_FOUND, OpenMP_CXX_FLAGS
477-
IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
490+
IF( cppad_link_flags_has_m32 )
491+
SET(OpenMP_CXX_FOUND FALSE)
492+
MESSAGE(STATUS
493+
"Skipping OpenMP becasue -m32 is in cppad_link_flags"
494+
)
495+
ELSEIF( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
478496
SET(OpenMP_CXX_FOUND FALSE)
479497
MESSAGE(STATUS
480498
"Skipping OpenMP on Darwin (Mac) systems. 2DO: fix this"
481499
)
482-
ELSE( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
500+
ELSE( )
483501
FIND_PACKAGE(OpenMP)
484-
ENDIF( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )
502+
ENDIF( )
485503
# -----------------------------------------------------------------------------
486-
# boost_prefix
504+
# Boost_Found, cppad_has_boost
487505
# Only need components for object libraries, not include libraries.
488-
SET(CMAKE_REQUIRED_FLAGS "") # 2DO: why is this necessary with clang ?
489-
FIND_PACKAGE(Boost COMPONENTS thread)
490-
SET(CMAKE_REQUIRED_FLAGS "${cppad_cxx_flags}")
491-
SET(cppad_has_boost 0)
506+
IF( cppad_link_flags_has_m32 )
507+
MESSAGE(STATUS
508+
"Skipping Boost becasue -m32 is in cppad_link_flags"
509+
)
510+
SET( Boost_FOUND 0)
511+
SET(cppad_has_boost 0)
512+
ELSE ( )
513+
SET(CMAKE_REQUIRED_FLAGS "") # 2DO: why is this necessary with clang ?
514+
FIND_PACKAGE(Boost COMPONENTS thread)
515+
SET(CMAKE_REQUIRED_FLAGS "${cppad_cxx_flags}")
516+
ENDIF( )
492517
IF ( Boost_FOUND )
493518
SET(cppad_has_boost 1)
494519
#
@@ -582,7 +607,9 @@ ELSE( )
582607
ENDIF( )
583608
ENDIF( )
584609
print_variable(is_cppad_lib_dynamic)
585-
610+
#
611+
# CMAKE_EXE_LINKER_FLAGS
612+
SET(CMAKE_EXE_LINKER_FLAGS "${cppad_link_flags}" )
586613
#
587614
# Initialize list of tests as empty
588615
SET(check_depends "")

appendix/whats_new/2025.xrst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-24 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55

66
{xrst_begin 2025 app}
77
{xrst_spell
8+
dll
9+
jit
810
}
911

1012
Release Notes for 2025
@@ -13,6 +15,23 @@ Release Notes for 2025
1315
mm-dd
1416
*****
1517

18+
01-17
19+
=====
20+
#. The :ref:`cmake@cppad_link_flags` option was added to the cmake command.
21+
22+
#. The detection of when ``unsigned int`` and ``size_t`` were the same,
23+
by the cmake command, was incorrect in cases where
24+
the compiler flags affected this result.
25+
26+
#. Fix some errors of the form *function_name*\ ``(unsigned int)``
27+
cannot be overloaded with *function_name*\ ``(size_t)`` .
28+
29+
#. The :ref:`dll_lib.cpp@Restrictions` ,
30+
on when the dll_lib.cpp example is tested were documented.
31+
32+
#. The :ref:`example_jit@Restrictions` was added to the
33+
jit example documentation.
34+
1635
01-10
1736
=====
1837
Split the external links at the top of the user guide into:

bin/run_cmake.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env bash
22
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
33
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
4-
# SPDX-FileContributor: 2003-24 Bradley M. Bell
4+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
55
# ----------------------------------------------------------------------------
66
set -e -u
77
echo $0 $*
@@ -20,6 +20,7 @@ echo_eval() {
2020
# -----------------------------------------------------------------------------
2121
verbose_make='no'
2222
standard='c++17'
23+
m32='no'
2324
profile_speed='no'
2425
callgrind='no'
2526
clang='no'
@@ -44,6 +45,7 @@ usage: bin/run_cmake.sh: \\
4445
[--help] \\
4546
[--verbose_make] \\
4647
[--c++11] \\
48+
[--m32] \\
4749
[--profile_speed] \\
4850
[--callgrind] \\
4951
[--clang ] \\
@@ -78,6 +80,10 @@ EOF
7880
standard='c++11'
7981
;;
8082

83+
--m32)
84+
m32='yes'
85+
;;
86+
8187
--profile_speed)
8288
profile_speed='yes'
8389
;;
@@ -337,9 +343,21 @@ do
337343
cmake_args+=" -D ${package}_prefix=$prefix"
338344
done
339345
#
346+
# cppad_link_flags
347+
if [ "$m32" == 'yes' ]
348+
then
349+
cmake_args+=" -D cppad_link_flags=-m32"
350+
fi
351+
#
340352
# cppad_cxx_flags
341-
cppad_cxx_flags="-Wall -pedantic-errors -std=$standard -Wshadow"
342-
cppad_cxx_flags+=" -Wfloat-conversion -Wconversion"
353+
if [ "$m32" == 'yes' ]
354+
then
355+
cppad_cxx_flags="-std=$standard -m32"
356+
else
357+
cppad_cxx_flags="-std=$standard"
358+
fi
359+
cppad_cxx_flags+=' -Wall -pedantic-errors -Wshadow'
360+
cppad_cxx_flags+=' -Wfloat-conversion -Wconversion'
343361
if [ "$debug_which" == 'debug_all' ]
344362
then
345363
# CMAKE_CXX_FLAGS_DEBUG include -g so do not need it here

cmake/compile_source_test.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-22 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55
# compile_source_test(defined_ok source variable)
66
#
@@ -33,6 +33,15 @@ MACRO(compile_source_test defined_ok source variable)
3333
ENDIF( DEFINED ${variable} )
3434
ENDIF( NOT ${defined_ok} )
3535
#
36+
SET(CMAKE_REQUIRED_DEFINITIONS "" )
37+
SET(CMAKE_REQUIRED_INCLUDES "" )
38+
SET(CMAKE_REQUIRED_LIBRARIES "" )
39+
IF( cppad_cxx_flags )
40+
SET(CMAKE_REQUIRED_FLAGS "${cppad_cxx_flags} ${CMAKE_CXX_FLAGS}" )
41+
ELSE( cppad_cxx_flags )
42+
SET(CMAKE_REQUIRED_FLAGS "" )
43+
ENDIF( cppad_cxx_flags )
44+
#
3645
# check that source code compiles
3746
CHECK_CXX_SOURCE_COMPILES("${source}" ${variable} )
3847
#

cppad_lib/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-22 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55
# Build and install the cppad_lib shared library
66
#
@@ -50,7 +50,10 @@ IF( "${is_cppad_lib_dynamic}" STREQUAL "0" )
5050
ELSEIF( "${is_cppad_lib_dynamic}" STREQUAL "1" )
5151
MESSAGE( STATUS "Not Windows system so building shared cppad_lib")
5252
ADD_LIBRARY( cppad_lib SHARED ${source_list} )
53-
SET_TARGET_PROPERTIES( cppad_lib PROPERTIES SOVERSION ${soversion} )
53+
SET_TARGET_PROPERTIES( cppad_lib PROPERTIES
54+
SOVERSION ${soversion}
55+
LINK_OPTIONS "${cppad_link_flags}"
56+
)
5457
#
5558
FIND_LIBRARY(dl_LIBRARY dl)
5659
IF( dl_LIBRARY )

example/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-22 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55
# Build the example directory tests
66
# Inherit environment from ../CMakeList.txt
@@ -18,7 +18,6 @@ ADD_SUBDIRECTORY(compare_change)
1818
ADD_SUBDIRECTORY(general)
1919
ADD_SUBDIRECTORY(get_started)
2020
ADD_SUBDIRECTORY(graph)
21-
ADD_SUBDIRECTORY(jit)
2221
ADD_SUBDIRECTORY(json)
2322
ADD_SUBDIRECTORY(multi_thread)
2423
ADD_SUBDIRECTORY(optimize)
@@ -37,6 +36,12 @@ ENDIF( cppad_has_cppadcg )
3736
IF( cppad_has_ipopt)
3837
ADD_SUBDIRECTORY(ipopt_solve)
3938
ENDIF( cppad_has_ipopt)
39+
#
40+
# jit examples
41+
IF( NOT cppad_link_flags_has_m32 )
42+
ADD_SUBDIRECTORY(jit)
43+
ENDIF( )
44+
4045

4146

4247
# Add the check_example target

example/jit/jit.xrst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-23 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55
{xrst_begin example_jit}
66

77
JIT Creation, Compilation, and Linking of C Source Code
88
#######################################################
99

10+
Restrictions
11+
************
12+
These examples are not tested when the
13+
:ref:`cmake@cppad_link_flags` contain ``-m32`` .
14+
1015
Contents
1116
********
1217
{xrst_toc_table

example/multi_thread/openmp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
# SPDX-FileContributor: 2003-24 Bradley M. Bell
3+
# SPDX-FileContributor: 2003-25 Bradley M. Bell
44
# ----------------------------------------------------------------------------
55
# Build the example/multi_thread/openmp directory tests
66
# Inherit build type from ../CMakeList.txt
@@ -38,7 +38,7 @@ TARGET_LINK_LIBRARIES(
3838
)
3939

4040
# Extra flags used by linker for openmp support
41-
SET(CMAKE_EXE_LINKER_FLAGS ${OpenMP_CXX_FLAGS} )
41+
SET(CMAKE_EXE_LINKER_FLAGS "${OpenMP_CXX_FLAGS} ${cppad_link_flags}" )
4242

4343
# check_example_multi_thread_openmp
4444
add_check_executable(check_example_multi_thread openmp get_started)

example/utility/dll_lib.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
// SPDX-FileContributor: 2003-22 Bradley M. Bell
3+
// SPDX-FileContributor: 2003-25 Bradley M. Bell
44
// ----------------------------------------------------------------------------
55

66
/*
77
{xrst_begin dll_lib.cpp}
8+
{xrst_spell
9+
msvc
10+
}
811
912
dll_lib: Example and Test
1013
#########################
@@ -19,6 +22,19 @@ from the default options:
1922
// END_OPTIONS
2023
}
2124
25+
Restrictions
26+
************
27+
This example is only built and run under the following conditions:
28+
29+
#. The :ref:`cmake-name` command determines that the C compiler is
30+
gcc, clang, or msvc.
31+
32+
#. The :ref:`cmake-name` command determines it is OK to use
33+
C++17 features.
34+
35+
#. The :ref:`cmake@cppad_link_flags` do not contain ``-m32`` .
36+
37+
2238
Source
2339
******
2440
{xrst_literal
@@ -105,6 +121,8 @@ bool dll_lib(void)
105121
std::map< std::string, std::string > options;
106122
# ifdef _MSC_VER
107123
options["compile"] = "cl /EHs /EHc /c /TC /O2";
124+
# elif CPPAD_LINK_FLAGS_HAS_M32
125+
options["compile"] = "gcc -c -fPIC -O2 -m32";
108126
# else
109127
options["compile"] = "gcc -c -fPIC -O2";
110128
# endif

example/utility/utility.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
22
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
3-
// SPDX-FileContributor: 2003-22 Bradley M. Bell
3+
// SPDX-FileContributor: 2003-25 Bradley M. Bell
44
// ----------------------------------------------------------------------------
55
/*
66
{xrst_begin utility.cpp}
@@ -108,7 +108,7 @@ int main(void)
108108
// END_SORT_THIS_LINE_MINUS_1
109109
//
110110
# if CPPAD_C_COMPILER_GNU_FLAGS || CPPAD_C_COMPILER_MSVC_FLAGS
111-
# if CPPAD_USE_CPLUSPLUS_2017
111+
# if CPPAD_USE_CPLUSPLUS_2017 && ! CPPAD_LINK_FLAGS_HAS_M32
112112
Run( dll_lib, "dll_lib" );
113113
# endif
114114
# endif

include/cppad/configure.hpp.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# define CPPAD_CONFIGURE_HPP
33
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
44
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
5-
// SPDX-FileContributor: 2003-24 Bradley M. Bell
5+
// SPDX-FileContributor: 2003-25 Bradley M. Bell
66
// ----------------------------------------------------------------------------
77

88
/*!
@@ -27,6 +27,13 @@
2727
Preprocessor Symbols Set By CMake Command
2828
#########################################
2929

30+
CPPAD_LINK_FLAGS_HAS_M32
31+
************************
32+
is -m32 in the :ref:`cmake@cppad_link_flags` .
33+
{xrst_code hpp} */
34+
# define CPPAD_LINK_FLAGS_HAS_M32 @cppad_link_flags_has_m32@
35+
/* {xrst_code}
36+
3037
CPPAD_COMPILER_HAS_CONVERSION_WARN
3138
**********************************
3239
is the compiler a variant of g++ and has conversion warnings

0 commit comments

Comments
 (0)