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

A couple of cmake cleanups. NFC. #10934

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions cmake/Modules/Platform/Emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,12 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_SYSTEM_INCLUDE_PATH "${EMSCRIPTEN_ROOT_PATH}/system/include")

# We would prefer to specify a standard set of Clang+Emscripten-friendly common
# convention for suffix files, especially for CMake executable files, but if
# these are adjusted, ${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake will fail,
# since it depends on being able to compile output files with predefined names.
#set(CMAKE_LINK_LIBRARY_SUFFIX "")
#set(CMAKE_STATIC_LIBRARY_PREFIX "")
#set(CMAKE_SHARED_LIBRARY_PREFIX "")
#set(CMAKE_FIND_LIBRARY_PREFIXES "")
#set(CMAKE_FIND_LIBRARY_SUFFIXES ".bc")
#set(CMAKE_SHARED_LIBRARY_SUFFIX ".bc")

option(EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES "If set, static library targets generate LLVM bitcode files (.bc). If disabled (default), UNIX ar archives (.a) are generated." OFF)
if (EMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES)
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")

# Use the compiler to create a bitcode object rather than the default of using the AR tool
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_C_COMPILER> -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_CXX_COMPILER> -o <TARGET> <LINK_FLAGS> <OBJECTS>")
else()
# Specify the program to use when building static libraries. Force
# Emscripten-related command line options to clang.
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed these two lines since this the basically the default for cmake anyway. The key is to use our version of AR which setting the CMAKE_AR is enough to do.

endif()

set(CMAKE_EXECUTABLE_SUFFIX ".js")
Expand Down
32 changes: 8 additions & 24 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import tools.duplicate_function_eliminator

scons_path = Building.which('scons')
if WINDOWS:
emcmake = path_from_root('emcmake.bat')
else:
emcmake = path_from_root('emcmake')


class temp_directory(object):
Expand Down Expand Up @@ -624,11 +628,6 @@ def check_makefile(dirname):
}
}

if WINDOWS:
emcmake = path_from_root('emcmake.bat')
else:
emcmake = path_from_root('emcmake')

for generator in generators:
conf = configurations[generator]

Expand Down Expand Up @@ -709,11 +708,6 @@ def test_cmake_compile_features(self):
print(str(cmd))
native_features = run_process(cmd, stdout=PIPE).stdout

if WINDOWS:
emcmake = path_from_root('emcmake.bat')
else:
emcmake = path_from_root('emcmake')

with temp_directory(self.get_dir()):
cmd = [emcmake, 'cmake', path_from_root('tests', 'cmake', 'stdproperty')]
print(str(cmd))
Expand All @@ -727,7 +721,7 @@ def test_cmake_compile_features(self):
def test_cmake_with_embind_cpp11_mode(self):
for args in [[], ['-DNO_GNU_EXTENSIONS=1']]:
with temp_directory(self.get_dir()) as tempdirname:
configure = [path_from_root('emcmake.bat' if WINDOWS else 'emcmake'), 'cmake', path_from_root('tests', 'cmake', 'cmake_with_emval')] + args
configure = [emcmake, 'cmake', path_from_root('tests', 'cmake', 'cmake_with_emval')] + args
print(str(configure))
run_process(configure)
build = ['cmake', '--build', '.']
Expand All @@ -743,15 +737,10 @@ def test_cmake_with_embind_cpp11_mode(self):
# Tests that the Emscripten CMake toolchain option
# -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=ON works.
def test_cmake_bitcode_static_libraries(self):
if WINDOWS:
emcmake = path_from_root('emcmake.bat')
else:
emcmake = path_from_root('emcmake')

# Test that building static libraries by default generates UNIX archives (.a, with the emar tool)
self.clear()
run_process([emcmake, 'cmake', path_from_root('tests', 'cmake', 'static_lib')])
run_process([Building.which('cmake'), '--build', '.'])
run_process(['cmake', '--build', '.'])
assert Building.is_ar('libstatic_lib.a')
run_process([PYTHON, EMAR, 'x', 'libstatic_lib.a'])
found = False # hashing makes the object name random
Expand All @@ -769,7 +758,7 @@ def test_cmake_bitcode_static_libraries(self):
# (.bc)
self.clear()
run_process([emcmake, 'cmake', '-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=ON', path_from_root('tests', 'cmake', 'static_lib')])
run_process([Building.which('cmake'), '--build', '.'])
run_process(['cmake', '--build', '.'])
if self.is_wasm_backend():
assert Building.is_wasm('libstatic_lib.bc')
else:
Expand All @@ -781,16 +770,11 @@ def test_cmake_bitcode_static_libraries(self):
# with ".so" suffix which are in fact either ar archives or bitcode files)
self.clear()
run_process([emcmake, 'cmake', '-DSET_FAKE_SUFFIX_IN_PROJECT=1', path_from_root('tests', 'cmake', 'static_lib')])
run_process([Building.which('cmake'), '--build', '.'])
run_process(['cmake', '--build', '.'])
assert Building.is_ar('myprefix_static_lib.somecustomsuffix')

# Tests that the CMake variable EMSCRIPTEN_VERSION is properly provided to user CMake scripts
def test_cmake_emscripten_version(self):
if WINDOWS:
emcmake = path_from_root('emcmake.bat')
else:
emcmake = path_from_root('emcmake')

run_process([emcmake, 'cmake', path_from_root('tests', 'cmake', 'emscripten_version')])

def test_system_include_paths(self):
Expand Down