Skip to content

changes to cmake list to install rol as package#28

Open
rjbaraldi wants to merge 14 commits into
developfrom
cmakechange
Open

changes to cmake list to install rol as package#28
rjbaraldi wants to merge 14 commits into
developfrom
cmakechange

Conversation

@rjbaraldi
Copy link
Copy Markdown
Collaborator

Modified the cmake file to allow for rol to be built as a package.

  • Follow-up addition: should we provide sample build script to help with installation? Website change? I can raise this as an issue for the future.

@rjbaraldi rjbaraldi requested a review from dridzal May 20, 2026 18:58
Copy link
Copy Markdown
Collaborator

@dridzal dridzal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Can you add to this PR the change to README.md that goes all the way to make install? Making this change would update the build instructions for our github website. Later, we can copy the instructions to rol.sandia.gov. Also, I am wondering if it would be possible to provide a (very) compact cmake project example that uses ROL, including the cmake file and a ROL::StdVector based example. It could go into Getting Started.

@rjbaraldi
Copy link
Copy Markdown
Collaborator Author

Can do - would you want to change make to cmake or ninja? I haven't tested with make install but I would assume it works.

Re: cmake project example - I was thinking we put the MFEM example hook-up as well somewhere once that's up and running. But for the simple one, perhaps I can raise an issue and put it in a subsequent PR?

@dridzal
Copy link
Copy Markdown
Collaborator

dridzal commented May 20, 2026

would you want to change make to cmake or ninja

You can just use make and make install. In your script, you can test it by deleting the line with ninja and just running plain make.

Regarding the example, I was hoping that it would be compact enough to include in README.md, but it's ok to raise an issue.

Copy link
Copy Markdown
Collaborator

@dridzal dridzal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@rjbaraldi
Copy link
Copy Markdown
Collaborator Author

I'm not sure it would be compact enough to include in the "getting started". Would you want a whole example? To me it feels like a whole website section/page.

@dridzal
Copy link
Copy Markdown
Collaborator

dridzal commented May 20, 2026

feels like a whole website section/page.

Yes, it may be better to have this on rol.sandia.gov.

Copy link
Copy Markdown
Contributor

@GrahamBenHarper GrahamBenHarper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm this works on Ubuntu with CMake 3.28.3 and gcc 13.3.0 by linking it against a minimal external example.

$ cmake .
-- CMAKE_PREFIX_PATH=
-- ROL_LIB=/home/gbharpe/Programming/cpp/rol/rol-install/lib/librol.so
-- ROL_INCLUDE_DIR=/home/gbharpe/Programming/cpp/rol/rol-install/include
-- Configuring done (0.0s)
-- Generating done (0.1s)
-- Build files have been written to: /home/gbharpe/Programming/cpp/rol/rol-examples
$ make
[ 50%] Linking CXX executable main
[100%] Built target main
$ ./main 
Hello from ROL
$ cat main.cpp
#include <iostream>
#include "ROL_Ptr.hpp"

int main() {
  ROL::Ptr<int> p;
  std::cout << "Hello from ROL" << std::endl;
}

Comment thread CMakeLists.txt Outdated
@rjbaraldi
Copy link
Copy Markdown
Collaborator Author

We should also include the cmake example.

Copy link
Copy Markdown
Contributor

@GrahamBenHarper GrahamBenHarper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROL_config.h is only created in the build directory but not the install directory, so we need to make sure that also gets copied into the install directory

Copy link
Copy Markdown
Contributor

@GrahamBenHarper GrahamBenHarper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should fix one problem, but I still see those Teuchos linker errors, which might be a little more tricky

Comment thread CMakeLists.txt Outdated
Comment thread README.md

message(STATUS "ROL directory is: ${ROL_DIR}/include")
include_directories("${ROL_DIR}/include") #one down for all files
include_directories("${ROL_DIR}/lib/librol.so")
Copy link
Copy Markdown
Contributor

@GrahamBenHarper GrahamBenHarper May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the bottom line include_directories("${ROL_DIR}/lib/librol.so") and just include the include directory

Comment thread README.md
enable_language(C)
enable_language(CXX)

message(STATUS "ROL directory is: ${ROL_DIR}/include")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the actual link against the ROL library. Here's the minimum amount of boilerplate to link against the library that I use for my code. Note the add_executable and target_link_libraries in your case will be slightly differently named

Suggested change
message(STATUS "ROL directory is: ${ROL_DIR}/include")
message(STATUS "ROL directory is: ${ROL_DIR}/include")
include_directories("${ROL_DIR}/include") #one down for all files
find_library(ROL_LIB NAMES rol librol PATHS ${ROL_DIR}/lib NO_DEFAULT_PATH)
if(ROL_LIB)
message(STATUS "We found ROL!")
else()
message(FATAL_ERROR "ROL library not found!")
endif()
add_library(rol::rol UNKNOWN IMPORTED)
set_target_properties(rol::rol PROPERTIES IMPORTED_LOCATION "${ROL_LIB}")
add_executable(main main.cpp)
target_link_libraries(main PRIVATE rol::rol)

Co-authored-by: Graham Harper <GrahamBenHarper@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants