Skip to content

Use cmake standard BUILD_SHARED_LIBS setting#8764

Open
sbc100 wants to merge 1 commit into
mainfrom
BUILD_SHARED_LIBS
Open

Use cmake standard BUILD_SHARED_LIBS setting#8764
sbc100 wants to merge 1 commit into
mainfrom
BUILD_SHARED_LIBS

Conversation

@sbc100
Copy link
Copy Markdown
Member

@sbc100 sbc100 commented May 22, 2026

See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

I'm not sure why we made up our own setting here rather than using the standard one.

@sbc100 sbc100 requested a review from a team as a code owner May 22, 2026 18:18
@sbc100 sbc100 requested review from a team, kripken and stevenfontanella and removed request for a team May 22, 2026 18:18
@sbc100 sbc100 force-pushed the BUILD_SHARED_LIBS branch from 5889248 to 88e50f1 Compare May 22, 2026 18:19
Comment thread CMakeLists.txt
if(BUILD_STATIC_LIB)
message(STATUS "Building libbinaryen as statically linked library.")
add_library(binaryen STATIC)
add_definitions(-DBUILD_STATIC_LIBRARY)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will this code still work without this def?

#elif defined(_MSC_VER) && !defined(BUILD_STATIC_LIBRARY)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't currently support building shared library under MSVC (we force BUILD_SHARED_LIBS to false) so I guess this code is dead.. but somebody was trying to get it working at some point I guess?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, that could be. Should we remove it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It looks like it could be useful as the first step in making a windows DLL work. It seems reasonable to leave in in place for when somebody needs it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, maybe add a comment there that we do not currently define that value? (which is the case as of this PR). That is, add a TODO there to define and use it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I meant in src/binaryen-c.h.

Otherwise it is looking at a C define that is not defined anywhere, which seems confusing? It looks like a bug rather than a TODO.

Copy link
Copy Markdown
Member Author

@sbc100 sbc100 May 22, 2026

Choose a reason for hiding this comment

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

I did updated binaryen-c.h in this PR to refer to the new define. Did you see that part?

I didn't change that fact that we currently disable the shared library build on windows, I just flipped the logic around.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK I added a TODO.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just to be clear the __declspec was never activated before this change also

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, sorry - if that was there before then I just missed it somehow. lgtm!

Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm % comment

See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

I'm not sure why we made up our own setting here rather than using the
standard one.
@sbc100 sbc100 force-pushed the BUILD_SHARED_LIBS branch from 88e50f1 to d4b32b8 Compare May 22, 2026 23:48
Comment thread CMakeLists.txt
if(BUILD_STATIC_LIB)
message(STATUS "Building libbinaryen as statically linked library.")
add_library(binaryen STATIC)
add_definitions(-DBUILD_STATIC_LIBRARY)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, sorry - if that was there before then I just missed it somehow. lgtm!

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.

2 participants