Skip to content

Commit

Permalink
Fix build and tests (#87)
Browse files Browse the repository at this point in the history
* Link tests against CPPAD to avoid missing symbol issue
* Avoid template redefinition error
* Use CMake found compiler instead of '/usr/bin/gcc' in unit test
* CPPAD_HOME show the root directory instead of the include directory
  • Loading branch information
jorisv authored Jun 9, 2024
1 parent fde3752 commit a77bdb2
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
-DUSE_VALGRIND=OFF \
-DENABLE_THREAD_POOL_TESTS=OFF \
-DLLVM_VERSION=${LLVM_VERSION} \
-DCPPAD_HOME="${curdir}/${CPPAD_INSTALL}/include" \
-DCPPAD_HOME="${curdir}/${CPPAD_INSTALL}" \
-DEIGEN3_INCLUDE_DIR="${curdir}/${EIGEN_INSTALL}" \
..
cd test
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindCppAD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENDIF ()
IF (DEFINED CPPAD_HOME)

FIND_PATH(CPPAD_INCLUDE_DIR NAMES cppad/cppad.hpp
PATHS "${CPPAD_HOME}"
PATHS "${CPPAD_HOME}/include"
NO_DEFAULT_PATH)

FIND_LIBRARY(CPPAD_LIBRARY
Expand Down
1 change: 0 additions & 1 deletion include/cppad/cg/dae_index_reduction/dummy_deriv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ class DummyDerivatives : public DaeIndexReduction<Base> {
using namespace std;
using std::vector;
using std::map;
using std::map;

auto& graph = idxIdentify_->getGraph();
//auto& vnodes = graph.variables();
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ FUNCTION(add_cppadcg_test source_file)
IF( UNIX )
TARGET_LINK_LIBRARIES(${test_target_name} ${DL_LIBRARIES})
ENDIF()
TARGET_LINK_LIBRARIES(${test_target_name} ${CPPAD_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(${test_target_name} PRIVATE ${CPPAD_INCLUDE_DIRS})
TARGET_COMPILE_DEFINITIONS(${test_target_name}
PRIVATE CPPAD_CG_C_COMPILER=\"${CMAKE_C_COMPILER}\")

ADD_TEST(NAME ${test_target_name}
COMMAND ${test_target_name})
Expand Down
6 changes: 3 additions & 3 deletions test/cppad/cg/CppADCGDynamicAtomicNestedTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class CppADCGDynamicAtomicNestedTest : public CppADCGTest {
* (compile source code)
*/
DynamicModelLibraryProcessor<double> p(compDynHelp, "innerModel");
GccCompiler<double> compiler1;
GccCompiler<double> compiler1(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler1);

_dynamicLib = p.createDynamicLibrary(compiler1);
Expand Down Expand Up @@ -514,7 +514,7 @@ class CppADCGDynamicAtomicNestedTest : public CppADCGTest {
* Create the dynamic library
* (compile source code)
*/
GccCompiler<double> compiler2;
GccCompiler<double> compiler2(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler2);

DynamicModelLibraryProcessor<double> p2(compDynHelp2, "outerModel");
Expand Down Expand Up @@ -637,7 +637,7 @@ class CppADCGDynamicAtomicNestedTest : public CppADCGTest {
* Create the dynamic library
* (compile source code)
*/
GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);

DynamicModelLibraryProcessor<double> p(compDynHelp);
Expand Down
8 changes: 4 additions & 4 deletions test/cppad/cg/CppADCGDynamicAtomicTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ class CppADCGDynamicAtomicTest : public CppADCGModelTest {
* Create the dynamic library
* (generate and compile source code)
*/
GccCompiler<double> compiler1;
GccCompiler<double> compiler1(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler1);
compiler1.setSourcesFolder("sources_atomiclibatomiclib_" + _modelName);
compiler1.setSaveToDiskFirst(true);
Expand Down Expand Up @@ -815,7 +815,7 @@ class CppADCGDynamicAtomicTest : public CppADCGModelTest {
compDynHelp2.setVerbose(this->verbose_);

DynamicModelLibraryProcessor<double> p2(compDynHelp2, "outerModel");
GccCompiler<double> compiler2;
GccCompiler<double> compiler2(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler2);
compiler2.setSourcesFolder("sources_atomiclibatomiclib_" + _modelName);
compiler2.setSaveToDiskFirst(true);
Expand Down Expand Up @@ -912,7 +912,7 @@ class CppADCGDynamicAtomicTest : public CppADCGModelTest {

DynamicModelLibraryProcessor<double> p(compDynHelp);

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);
compiler.setSourcesFolder(folder);
compiler.setSaveToDiskFirst(true);
Expand Down Expand Up @@ -1069,7 +1069,7 @@ class CppADCGDynamicAtomicTest : public CppADCGModelTest {

DynamicModelLibraryProcessor<double> p(libSrcGen);

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);
compiler.setSourcesFolder(folder);
compiler.setSaveToDiskFirst(true);
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/CppADCGDynamicTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class CppADCGDynamicTest : public CppADCGModelTest {
const auto& cp = p;
ASSERT_TRUE(cp.getOptions().empty());

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
//compiler.setSaveToDiskFirst(true); // useful to detect problem
prepareTestCompilerFlags(compiler);
if(libSourceGen.getMultiThreading() == MultiThreadingType::OPENMP) {
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/CppADCGOperationTestImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void* CppADCGOperationTest::getFunction(void * libHandle, const std::string& fun
void CppADCGOperationTest::compile(const std::string& source,
const std::string& library) {

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);

try {
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/model/dynamiclib/dynamic_atomic_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CppADCGDynamicAtomic2Test : public CppADCGTest {
SaveFilesModelLibraryProcessor<double>::saveLibrarySourcesTo(compDynHelp, MODEL_NAME);

DynamicModelLibraryProcessor<double> p(compDynHelp);
GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);

_dynamicLib = p.createDynamicLibrary(compiler);
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/model/dynamiclib/dynamic_forward_reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CppADCGDynamicForRevTest2 : public CppADCGTest {
compHelp.setCreateSparseJacobian(true);
compHelp.setCreateSparseHessian(true);

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);

ModelLibraryCSourceGen<double> compDynHelp(compHelp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CppADCGDynamicForRevTest : public CppADCGTest {
compHelp.setCreateSparseJacobian(true);
compHelp.setCreateSparseHessian(true);

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);

ModelLibraryCSourceGen<double> compDynHelp(compHelp);
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/models/collocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class CollocationModel : public PatternTestModel<T> {
//SaveFilesModelLibraryProcessor<double>::saveLibrarySourcesTo(compDynHelpL, "sources_" + lName);

DynamicModelLibraryProcessor<double> p(compDynHelpL, lName);
GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);
compiler.setSourcesFolder("sources_" + lName);
compiler.setSaveToDiskFirst(true);
Expand Down
2 changes: 1 addition & 1 deletion test/cppad/cg/patterns/CppADCGPatternTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class CppADCGPatternTest : public CppADCGTest {
if (!customHessSparsity_.empty())
compHelpL.setCustomSparseHessianElements(customHessSparsity_);

GccCompiler<double> compiler;
GccCompiler<double> compiler(CPPAD_CG_C_COMPILER);
prepareTestCompilerFlags(compiler);
compiler.setSourcesFolder("sources_" + libBaseName);
compiler.setSaveToDiskFirst(true);
Expand Down

0 comments on commit a77bdb2

Please sign in to comment.