Skip to content

Commit

Permalink
master: configure.hpp: split C compilers into separate symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbell committed Jun 24, 2022
1 parent 6ab73cf commit cfa2289
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 17 deletions.
9 changes: 6 additions & 3 deletions example/jit/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,26 @@ bool compile(void)
// compile
std::string compile = "";
int flag;
# ifdef _MSC_VER
# if CPPAD_C_COMPILER_MSVC
flag = std::system("cl 1> nul 2> nul");
if( flag == 0 )
compile = "cl /EHs /EHc /c /LD /TC /O2";
# else
# endif
# if CPPAD_C_COMPILER_GNU
flag = std::system("gcc --version > temp");
if( flag == 0 )
compile = "gcc -c -fPIC -O2";
# endif
# if CPPAD_C_COMPILER_CLANG
# ifndef __MINGW32__
// clang: error: unsupported option '-fPIC' for target
// 'x86_64-pc-windows-msys'
flag = std::system("clang --version > /dev/null");
if( flag == 0 )
compile = "clang -c -fPIC -O2";
# endif
//
# endif
//
if( compile == "" )
return ok;
// std::cout << "compile = " << compile << "\n";
Expand Down
2 changes: 1 addition & 1 deletion example/jit/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern bool to_csrc(void);
int main(void)
{ bool ok = true;
//
# if CPPAD_GNU_OR_MSVC_C_COMPILER
# if CPPAD_C_COMPILER_GNU || CPPAD_C_COMPILER_MSVC
std::string group = "example/jit";
size_t width = 20;
CppAD::test_boolofvoid Run(group, width);
Expand Down
4 changes: 3 additions & 1 deletion example/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ int main(void)
Run( vectorBool, "vectorBool" );
// END_SORT_THIS_LINE_MINUS_1
//
# if CPPAD_USE_CPLUSPLUS_2017 && CPPAD_GNU_OR_MSVC_C_COMPILER
# if CPPAD_C_COMPILER_GNU || CPPAD_C_COMPILER_MSVC
# if CPPAD_USE_CPLUSPLUS_2017
Run( dll_lib, "dll_lib" );
# endif
# endif
//
// check for memory leak
Expand Down
22 changes: 17 additions & 5 deletions include/cppad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,25 @@ SET(CMAKE_REQUIRED_FLAGS "")
SET(CMAKE_REQUIRED_INCLUDES "")
SET(CMAKE_REQUIRED_LIBRARIES "")
# -----------------------------------------------------------------------------
# gnu_or_msvc_c_compiler
# cppad_c_compiler_gnu
IF( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
SET(gnu_or_msvc_c_compiler 1)
ELSEIF( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
SET(gnu_or_msvc_c_compiler 1)
SET(cppad_c_compiler_gnu 1)
ELSE()
SET(gnu_or_msvc_c_compiler 0)
SET(cppad_c_compiler_gnu 0)
ENDIF()
#
# cppad_c_compiler_msvc
IF( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
SET(cppad_c_compiler_msvc 1)
ELSE()
SET(cppad_c_compiler_msvc 0)
ENDIF()
#
# cppad_c_compiler_clang
IF( "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" )
SET(cppad_c_compiler_clang 1)
ELSE()
SET(cppad_c_compiler_clang 0)
ENDIF()
# -----------------------------------------------------------------------------
# compiler_has_conversion_warn
Expand Down
18 changes: 15 additions & 3 deletions include/cppad/configure.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,22 @@ This preprocessor symbol is
$code noexcept$$ when C++11 is available and $code NDEBUG$$ is defined.
Otherwise it is empty.

$head CPPAD_GNU_OR_MSVC_C_COMPILER$$
If true, the C complier is $code gcc$$ or $code cl$$.
$head CPPAD_C_COMPILER_GNU$$
If true, the C complier is $code gcc$$
$srccode%hpp% */
# define CPPAD_GNU_OR_MSVC_C_COMPILER @gnu_or_msvc_c_compiler@
# define CPPAD_C_COMPILER_GNU @cppad_c_compiler_gnu@
/* %$$

$head CPPAD_C_COMPILER_MSVC$$
If true, the C complier is $code cl$$
$srccode%hpp% */
# define CPPAD_C_COMPILER_MSVC @cppad_c_compiler_msvc@
/* %$$

$head CPPAD_C_COMPILER_CLANG$$
If true, the C complier is $code cl$$
$srccode%hpp% */
# define CPPAD_C_COMPILER_CLANG @cppad_c_compiler_clang@
/* %$$

$end
Expand Down
4 changes: 3 additions & 1 deletion include/cppad/core/undef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ that are used by the CppAD examples and tests.
# undef CPPAD_HASH_TABLE_SIZE used by test_more/optimize.cpp
# undef EIGEN_MATRIXBASE_PLUGIN example use of Eigen with CppAD
# undef CPPAD_HAS_COLPACK used by speed/cppad/sparse_*.cpp
# undef CPPAD_GNU_OR_MSVC_C_COMPILER used to select dll examples.
# undef CPPAD_C_COMPILER_GNU used to select dll examples.
# undef CPPAD_C_COMPILER_MSVC used to select dll examples.
# undef CPPAD_C_COMPILER_CLANG used to select dll examples.
// for conditional testing when implicit conversion is not present
Expand Down
1 change: 1 addition & 0 deletions omh/example_list.omh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ $rref jac_lu_det.cpp$$
$rref jac_minor_det.cpp$$
$rref jacobian.cpp$$
$rref jit_atomic.cpp$$
$rref jit_compile.cpp$$
$rref jit_dynamic.cpp$$
$rref jit_get_started.cpp$$
$rref jit_to_csrc.cpp$$
Expand Down
4 changes: 2 additions & 2 deletions speed/cppad_jit/det_minor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern std::map<std::string, bool> global_option;
# define DLL_EXT ".so"
# endif

# if ! CPPAD_GNU_OR_MSVC_C_COMPILER
# if ! (CPPAD_C_COMPILER_GNU || CPPAD_C_COMPILER_MSVC)
bool link_det_minor(
const std::string& job ,
size_t size ,
Expand Down Expand Up @@ -275,7 +275,7 @@ bool link_det_minor(
}
return true;
}
# endif // CPPAD_GNU_OR_MSVC_C_COMPILER
# endif // CPPAD_C_COMPILER_GNU || CPPAD_C_COMPILER_MSVC
/* %$$
$end
*/
2 changes: 1 addition & 1 deletion test_more/general/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(void)
Run( tan, "tan" );
Run( to_string, "to_string" );
// END_SORT_THIS_LINE_MINUS_1
# if CPPAD_GNU_OR_MSVC_C_COMPILER
# if CPPAD_C_COMPILER_GNU || CPPAD_C_COMPILER_MSVC
Run( to_csrc, "to_csrc" );
# endif
#if CPPAD_HAS_ADOLC
Expand Down

0 comments on commit cfa2289

Please sign in to comment.