Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler options are forced on users of ortools::ortools cmake target #4473

Open
JulZimmermann opened this issue Dec 12, 2024 · 2 comments
Open
Assignees
Labels
Bug Build: CMake CMake based build issue OS: Windows Windows OS
Milestone

Comments

@JulZimmermann
Copy link

What version of OR-Tools and what language are you using?
Version: 9.11
Language: C++

In cpp.cmake:

target_compile_options(${PROJECT_NAME} PUBLIC ${OR_TOOLS_COMPILE_OPTIONS})
target_link_options(${PROJECT_NAME} INTERFACE ${OR_TOOLS_LINK_OPTIONS})

OR_TOOLS_COMPILE_OPTIONS are exported PUBLIC. Therefore, users of the or-tools lib are forced to used the same compiler options in there application. The options should be PRIVATE so or-tools itself is build with the required options but not the downstream application.

Also:
OR_TOOLS_LINK_OPTIONS (which is only set to /WHOLEARCHIVE:ortools when MSVC is used) is exported as INTERFACE. Therefore it has no impact on the build of ortools itself but only on the users of the lib which may not want that.

I noticed this when I tried to use or-tools (compiled with MSVC) in my project which is compiled with clang. This didn't work because clang (not clang-cl) doesn't support these options.

When changing cpp.cmake to:

target_compile_options(${PROJECT_NAME} PRIVATE ${OR_TOOLS_COMPILE_OPTIONS})
#target_link_options(${PROJECT_NAME} INTERFACE ${OR_TOOLS_LINK_OPTIONS})

is works without a problem

@lperron lperron added Bug Build: CMake CMake based build issue labels Dec 12, 2024
@Mizux Mizux added this to the v9.12 milestone Dec 12, 2024
@Mizux
Copy link
Collaborator

Mizux commented Jan 16, 2025

Few issues here...

  1. We currently only support and test MSVC build on windows, but feel free to fix the build and send us a PR for this specific issue...
  2. This option is mandatory with msvc since there is some singleton which will be drop without this, I don't know how clang work here especially on windows and how you integrate it with a MSBuild user project...
  3. for compile_options is not that simple some are configure time option e.g. enabling support of SCIP solver so the -DUSE_SCIP MUST be passed to the user otherwise headers won't be parsed as expected so while maybe not ALL compile options are public some of them are mandatory so if you have time don't hesitate to split the list in two: what is only private and what should be public (aka INTERFACE+PRIVATE) and send us a PR !

@Mizux
Copy link
Collaborator

Mizux commented Jan 27, 2025

FYI I'm working on using BUILD_SHARED_LIB=ON on windows (MSVC) so I may perform some "target_compile_definition" split sooner than expected...

@JulZimmermann may I know the list of definition/compilation you'll want to see PRIVATE aka NOT INTERFACE...
note: PUBLIC stand for INTERFACE & PRIVATE

@Mizux Mizux added the OS: Windows Windows OS label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Build: CMake CMake based build issue OS: Windows Windows OS
Projects
None yet
Development

No branches or pull requests

3 participants