Skip to content

Commit d0803d0

Browse files
author
Huang-Ming Huang
committed
Better cross-compile support
1 parent 8e583b8 commit d0803d0

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

cmake/Emscripten.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@
22

33

44
if (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
5-
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
6-
set(CMAKE_INSTALL_PREFIX $ENV{EMSCRIPTEN}/system/local CACHE PATH "default install path" FORCE)
7-
endif()
8-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s OUTLINING_LIMIT=20000 -s DISABLE_EXCEPTION_CATCHING=0")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s OUTLINING_LIMIT=20000 -s DISABLE_EXCEPTION_CATCHING=0 ")
96
endif()
10-

cmake/FastTypeGenTarget.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ function (FASTTYPEGEN_TARGET Name)
1818
list(APPEND INPUTS "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
1919
endforeach (input)
2020

21-
if (CMAKE_CROSSCOMPILING)
22-
set(FAST_TYPE_GEN_TARGET)
23-
endif (CMAKE_CROSSCOMPILING)
24-
2521
add_custom_command(
2622
OUTPUT ${FASTTYPEGEN_${Name}_OUTPUTS}
27-
COMMAND fast_type_gen -- ${INPUTS}
28-
DEPENDS ${ARGN} ${FAST_TYPE_GEN_TARGET}
23+
COMMAND $<TARGET_FILE:fast_type_gen> -- ${INPUTS}
24+
DEPENDS ${ARGN} fast_type_gen
2925
COMMENT "[FASTTYPEGEN][${Name}] Building Fast Application Types"
3026
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
3127
VERBATIM)
@@ -36,3 +32,6 @@ function (FASTTYPEGEN_TARGET Name)
3632
set("FASTTYPEGEN_${Name}_DEFINED" TRUE PARENT_SCOPE)
3733
set("FASTTYPEGEN_${Name}_INPUTS" "${ARGN}" PARENT_SCOPE)
3834
endfunction (FASTTYPEGEN_TARGET)
35+
36+
get_target_property(mfast_cxx mfast_static CXX_STANDARD)
37+
message("mfast CXX_STANDARD = ${mfast_cxx}")

cmake/SetCXXStandard.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set(CMAKE_CXX_STANDARD 11 CACHE INTERNAL "specifies the C++ standard whose features are requested to build this target")
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5-
if (${CMAKE_VERSION} VERSION_LESS "3.1.0" AND NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
6-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD})
5+
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
6+
### Even though CMAKE_CXX_STANDARD_REQUIRED is supported since CMake 3.1, it doesn't work for Emscripten em++ together with
7+
### Cmake 3.6.
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD}")
79
endif()

src/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
# add_subdirectory (fastxml)
22
add_subdirectory (mfast)
33

4-
if (NOT CMAKE_CROSSCOMPILING)
5-
add_subdirectory (fast_type_gen)
6-
set(FAST_TYPE_GEN_INSTALL_LOCATION "${FAST_TYPE_GEN_INSTALL_LOCATION}" PARENT_SCOPE)
7-
else()
8-
find_program(FAST_TYPE_GEN NAMES fast_type_gen)
9-
if ("${FAST_TYPE_GEN}" STREQUAL "FAST_TYPE_GEN-NOTFOUND")
10-
message(SEND_ERROR "Unable to find the required program fast_type_gen.")
11-
set(FAST_TYPE_GEN_INSTALL_LOCATION ${FAST_TYPE_GEN} PARENT_SCOPE)
12-
endif ()
13-
endif()
4+
add_subdirectory (fast_type_gen)
5+
set(FAST_TYPE_GEN_INSTALL_LOCATION "${FAST_TYPE_GEN_INSTALL_LOCATION}" PARENT_SCOPE)
146

157
install(FILES "mfast.h" DESTINATION "${INSTALL_INCLUDE_DIR}")

src/fast_type_gen/CMakeLists.txt

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
21

3-
add_executable (fast_type_gen
4-
fast_type_gen.cpp
5-
codegen_base.cpp
6-
hpp_gen.cpp
7-
inl_gen.cpp
8-
cpp_gen.cpp)
2+
if (NOT CMAKE_CROSSCOMPILING)
3+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
4+
add_executable (fast_type_gen
5+
fast_type_gen.cpp
6+
codegen_base.cpp
7+
hpp_gen.cpp
8+
inl_gen.cpp
9+
cpp_gen.cpp)
910

11+
target_link_libraries (fast_type_gen
12+
mfast_xml_parser_static
13+
mfast_static
14+
mfast_coder_static)
1015

11-
target_link_libraries (fast_type_gen
12-
mfast_xml_parser_static
13-
mfast_static
14-
mfast_coder_static)
16+
set_target_properties(fast_type_gen PROPERTIES VERSION "${MFAST_VERSION}")
1517

16-
set_target_properties(fast_type_gen PROPERTIES VERSION "${MFAST_VERSION}")
18+
install(TARGETS fast_type_gen
19+
EXPORT mFASTTargets
20+
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin)
21+
add_custom_target(install.fast_type_gen
22+
COMMAND ${CMAKE_COMMAND} -DBUILD_TYPE=${CMAKE_BUILD_TYPE} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
23+
DEPENDS fast_type_gen)
24+
set(FAST_TYPE_GEN_INSTALL_LOCATION "${INSTALL_BIN_DIR}/fast_type_gen${CMAKE_EXECUTABLE_SUFFIX}" PARENT_SCOPE)
25+
else()
26+
include(ExternalProject)
27+
externalproject_add(native_mfast
28+
SOURCE_DIR "${PROJECT_SOURCE_DIR}"
29+
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}" "-DCMAKE_BUILD_TYPE=RELEASE"
30+
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target install.fast_type_gen
31+
BUILD_BYPRODUCTS ${PROJECT_BINARY_DIR}/bin/fast_type_gen
32+
INSTALL_COMMAND "")
33+
34+
add_executable(fast_type_gen IMPORTED GLOBAL)
35+
set_property(TARGET fast_type_gen PROPERTY IMPORTED_LOCATION ${PROJECT_BINARY_DIR}/bin/fast_type_gen)
36+
add_dependencies(fast_type_gen native_mfast)
37+
38+
endif()
1739

18-
install(TARGETS fast_type_gen
19-
EXPORT mFASTTargets
20-
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin)
21-
22-
set(FAST_TYPE_GEN_INSTALL_LOCATION "${INSTALL_BIN_DIR}/fast_type_gen${CMAKE_EXECUTABLE_SUFFIX}" PARENT_SCOPE)
40+

0 commit comments

Comments
 (0)