Skip to content

Commit db9b7b1

Browse files
author
Huang-Ming Huang
committed
refactor cmake files
1 parent 69f1ff9 commit db9b7b1

14 files changed

+186
-280
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ script:
3030

3131
# whitelist
3232
branches:
33-
only:
34-
- master
33+
except:
34+
- gh-pages
35+
- emdi

CMakeLists.txt

Lines changed: 16 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@
22
# refer to the root source directory of the project as ${MFAST_SOURCE_DIR} and
33
# to the root binary directory of the project as ${MFAST_BINARY_DIR}.
44

5-
cmake_minimum_required(VERSION 2.8.0)
6-
7-
5+
cmake_minimum_required(VERSION 2.8.11)
86
project (mFAST CXX)
97

10-
11-
set(EXT_PROJECTS_DIR external_projects)
12-
13-
14-
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
15-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
16-
include(CodeCoverage)
17-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_COVERAGE})
18-
endif()
8+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
199

2010
set(MFAST_MAJOR_VERSION 1)
2111
set(MFAST_MINOR_VERSION 3)
@@ -25,195 +15,45 @@ set(MFAST_SOVERSION ${MFAST_MAJOR_VERSION}.${MFAST_MINOR_VERSION})
2515

2616
set(CPACK_PACKAGE_VERSION ${MFAST_VERSION})
2717
set(CPACK_PACKAGE_NAME "mfast")
28-
include(CPack)
29-
3018

19+
include(CPack)
20+
include(SetInstallPaths)
21+
include(Emscripten)
22+
include(SetCXXStandard)
23+
include(SetCompilerWarnings)
24+
include(SetupCoverage)
3125

3226
# flag to enable building shared/dynamic library
3327
set(BUILD_SHARED_LIBS OFF CACHE BOOL "build shared/dynamic library")
34-
# Offer the user the choice of overriding the installation directories
35-
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
36-
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
37-
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
38-
set(INSTALL_DATA_DIR share CACHE PATH "Installation directory for data files")
39-
# flag to enable/disable building examples and/or tests
40-
set(BUILD_EXAMPLES ON CACHE BOOL "build mFAST examples" )
41-
set(BUILD_TESTS ON CACHE BOOL "build mFAST unit tests" )
42-
43-
if (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
44-
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
45-
set(CMAKE_INSTALL_PREFIX $ENV{EMSCRIPTEN}/system/local CACHE PATH "default install path" FORCE)
46-
endif()
47-
set(BUILD_FAST_TYPE_GEN OFF CACHE BOOL "Build fast_type_gen from source")
48-
else()
49-
set(BUILD_FAST_TYPE_GEN ON CACHE BOOL "Build fast_type_gen from source")
50-
endif()
51-
52-
# determine default path for CMake files
53-
if(WIN32 AND NOT CYGWIN)
54-
set(DEF_INSTALL_CMAKE_DIR CMake)
55-
else()
56-
if(${CMAKE_LIBRARY_ARCHITECTURE}) #support for multiarch debian-based distros, need cmake>=2.8.5
57-
set(DEF_INSTALL_CMAKE_DIR lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/mFAST)
58-
else()
59-
set(DEF_INSTALL_CMAKE_DIR lib/cmake/mFAST)
60-
endif()
61-
endif()
62-
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
63-
"Installation directory for CMake files")
64-
65-
# Make relative paths absolute (needed later on)
66-
foreach (p IN ITEMS LIB BIN INCLUDE DATA CMAKE)
67-
set (var "INSTALL_${p}_DIR")
68-
if (NOT IS_ABSOLUTE "${${var}}")
69-
set("ABSOLUTE_${var}" "${CMAKE_INSTALL_PREFIX}/${${var}}")
70-
else ()
71-
set("ABSOLUTE_${var}" "${${var}}")
72-
endif ()
73-
endforeach (p)
74-
75-
76-
include_directories ("${PROJECT_BINARY_DIR}"
77-
"${PROJECT_SOURCE_DIR}/src")
78-
79-
################################################################################
80-
## Setting up Boost Library
81-
################################
82-
8328

8429
find_package(Boost 1.56.0 REQUIRED)
85-
86-
87-
if (NOT BUILD_FAST_TYPE_GEN)
88-
find_program(FAST_TYPE_GEN NAMES fast_type_gen)
89-
if ("${FAST_TYPE_GEN}" STREQUAL "FAST_TYPE_GEN-NOTFOUND")
90-
message(SEND_ERROR "Unable to find the required program fast_type_gen.")
91-
endif ()
92-
endif (NOT BUILD_FAST_TYPE_GEN)
93-
9430
include_directories(${Boost_INCLUDE_DIR})
95-
96-
97-
################################################################################
98-
## Setting up tinyxml2 Library
99-
################################
100-
10131
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tinyxml2)
102-
103-
################################################################################
104-
105-
106-
# Select flags.
107-
# Initialize CXXFLAGS.
108-
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
109-
set(CMAKE_CXX_FLAGS "-W -Wall ${CMAKE_CXX_FLAGS} -std=c++11")
110-
endif()
111-
if (MSVC)
112-
add_definitions(/D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS)
113-
endif()
32+
include_directories ("${PROJECT_SOURCE_DIR}/src")
11433

11534
add_definitions(-DSIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P})
11635

117-
if (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
118-
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")
119-
endif()
12036
# variables to be used later
12137
set(MFAST_SHARED_LIBRARIES CACHE INTERNAL "")
12238
set(MFAST_STATIC_LIBRARIES CACHE INTERNAL "")
12339
set(MFAST_DYNAMIC_COMPONENTS CACHE INTERNAL "")
12440
set(MFAST_STATIC_COMPONENTS CACHE INTERNAL "")
12541

126-
############################################################################
127-
# Setting up RPATH
128-
#
129-
130-
# add the automatically determined parts of the RPATH
131-
# which point to directories outside the build tree to the install RPATH
132-
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
133-
134-
135-
############################################################################
136-
42+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
13743

13844
add_subdirectory (src)
45+
include(FastTypeGenTarget)
13946

140-
link_directories ("${PROJECT_BINARY_DIR}/src")
141-
142-
#============================================================
143-
# Install fast_type_gen batch file to set up the PATH environment
144-
# variable for using BOOST libraries
145-
146-
# if(MSVC_IDE)
147-
# configure_file(invoke.bat.in
148-
# "${PROJECT_BINARY_DIR}/bin/invoke.bat"
149-
# @ONLY)
150-
# endif(MSVC_IDE)
151-
152-
#============================================================
153-
# FASTTYPEGEN_TARGET (public function)
154-
#============================================================
155-
#
156-
157-
function (FASTTYPEGEN_TARGET Name)
158-
set(FASTTYPEGEN_TARGET_usage "FASTTYPEGEN_TARGET(<Name> Input1 Input2 ...]" PARENT_SCOPE)
159-
160-
set("FASTTYPEGEN_${Name}_OUTPUTS")
161-
set(INPUTS)
162-
163-
foreach (input IN LISTS ARGN)
164-
get_filename_component(noext_name "${input}" NAME_WE)
165-
list(APPEND "FASTTYPEGEN_${Name}_OUTPUTS"
166-
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.cpp"
167-
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.h"
168-
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.inl")
169-
list(APPEND INPUTS "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
170-
endforeach (input)
171-
172-
if (BUILD_FAST_TYPE_GEN)
173-
set(FAST_TYPE_GEN fast_type_gen)
174-
set(FAST_TYPE_GEN_TARGET fast_type_gen)
175-
else (BUILD_FAST_TYPE_GEN)
176-
set(FAST_TYPE_GEN_TARGET)
177-
endif (BUILD_FAST_TYPE_GEN)
178-
179-
add_custom_command(
180-
OUTPUT ${FASTTYPEGEN_${Name}_OUTPUTS}
181-
COMMAND "${FAST_TYPE_GEN}" -- ${INPUTS}
182-
DEPENDS ${ARGN} ${FAST_TYPE_GEN_TARGET}
183-
COMMENT "[FASTTYPEGEN][${Name}] Building Fast Application Types"
184-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
185-
VERBATIM)
186-
187-
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
188-
189-
set("FASTTYPEGEN_${Name}_OUTPUTS" "${FASTTYPEGEN_${Name}_OUTPUTS}" PARENT_SCOPE)
190-
set("FASTTYPEGEN_${Name}_DEFINED" TRUE PARENT_SCOPE)
191-
set("FASTTYPEGEN_${Name}_INPUTS" "${ARGN}" PARENT_SCOPE)
192-
endfunction (FASTTYPEGEN_TARGET)
193-
194-
195-
196-
# Includes Catch in the project:
197-
#add_subdirectory(${EXT_PROJECTS_DIR}/catch)
198-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/catch/include ${COMMON_INCLUDES})
199-
200-
if (BUILD_TESTS)
201-
enable_testing()
202-
add_subdirectory (tests)
203-
endif (BUILD_TESTS)
47+
enable_testing()
48+
add_subdirectory (tests)
20449

20550
if (BUILD_SHARED_LIBS)
20651
set(MFAST_LIBRARIES "${MFAST_SHARED_LIBRARIES}")
207-
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
208-
add_definitions(-DMFAST_DYN_LINK)
209-
endif ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
21052
else (BUILD_SHARED_LIBS)
21153
set(MFAST_LIBRARIES "${MFAST_STATIC_LIBRARIES}")
21254
endif (BUILD_SHARED_LIBS)
21355

214-
if (BUILD_EXAMPLES)
215-
add_subdirectory (examples)
216-
endif (BUILD_EXAMPLES)
56+
add_subdirectory (examples)
21757

21858

21959
# Setting up dist target
@@ -224,61 +64,13 @@ add_custom_target(dist
22464
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
22565
| bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
22666
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
67+
22768

228-
# Provide mfast-config.cmake and mfast-config.version to be used by other applications
229-
# ===============================
230-
231-
export(PACKAGE ${CMAKE_PROJECT_NAME})
232-
233-
if (BUILD_FAST_TYPE_GEN)
234-
export(TARGETS fast_type_gen ${MFAST_SHARED_LIBRARIES} ${MFAST_STATIC_LIBRARIES}
235-
FILE "${PROJECT_BINARY_DIR}/mFASTTargets.cmake")
236-
else (BUILD_FAST_TYPE_GEN)
237-
export(TARGETS ${MFAST_SHARED_LIBRARIES} ${MFAST_STATIC_LIBRARIES}
238-
FILE "${PROJECT_BINARY_DIR}/mFASTTargets.cmake")
239-
set(FAST_TYPE_GEN_INSTALL_LOCATION ${FAST_TYPE_GEN})
240-
endif (BUILD_FAST_TYPE_GEN)
241-
242-
# Create the mFASTConfig.cmake for the build tree
243-
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src")
244-
configure_file(mFASTConfig.cmake.in
245-
"${PROJECT_BINARY_DIR}/mFASTConfig.cmake"
246-
@ONLY)
247-
248-
# Create the mFASTConfig.cmake for the install tree
249-
file(RELATIVE_PATH REL_INCLUDE_DIR "${ABSOLUTE_INSTALL_CMAKE_DIR}" "${ABSOLUTE_INSTALL_INCLUDE_DIR}")
250-
set(CONF_INCLUDE_DIRS "\${MFAST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
251-
configure_file(mFASTConfig.cmake.in
252-
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mFASTConfig.cmake"
253-
@ONLY)
254-
255-
# Create the mFASTConfigVersion.cmake for both
256-
configure_file(mFASTConfigVersion.cmake.in
257-
"${PROJECT_BINARY_DIR}/mFASTConfigVersion.cmake"
258-
@ONLY)
259-
260-
# Install the mFASTConfig.cmake and mFASTConfigVersion.cmake
261-
install(FILES
262-
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mFASTConfig.cmake"
263-
"${PROJECT_BINARY_DIR}/mFASTConfigVersion.cmake"
264-
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
265-
266-
# Install the export set for use with the install-tree
267-
install(EXPORT mFASTTargets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
69+
include(GenProjectConfig)
26870

26971
file(GLOB schema_files "${CMAKE_CURRENT_SOURCE_DIR}/schema/*.*")
270-
27172
install(FILES
27273
${schema_files}
27374
DESTINATION ${INSTALL_DATA_DIR}/mfast)
27475

27576

276-
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
277-
SETUP_TARGET_FOR_COVERAGE(
278-
coverage # Name for custom target.
279-
mfast_test # Name of the test driver executable that runs the tests.
280-
# NOTE! This should always have a ZERO as exit code
281-
# otherwise the coverage generation will not complete.
282-
coverage # Name of output directory.
283-
)
284-
endif()

appveyor.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ clone_folder: C:\projects\mfast
3131
# branches to build
3232
branches:
3333
#whitelist
34-
only:
35-
- master
34+
# only:
35+
# - master
3636
# blacklist
37-
# except:
38-
# - gh-pages
37+
except:
38+
- gh-pages
39+
- emdi
3940

4041
# scripts that run after cloning repository
4142
install:

cmake/Emscripten.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
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")
9+
endif()
10+

cmake/FastTypeGenTarget.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#============================================================
2+
# FASTTYPEGEN_TARGET (public function)
3+
#============================================================
4+
#
5+
6+
function (FASTTYPEGEN_TARGET Name)
7+
set(FASTTYPEGEN_TARGET_usage "FASTTYPEGEN_TARGET(<Name> Input1 Input2 ...]" PARENT_SCOPE)
8+
9+
set("FASTTYPEGEN_${Name}_OUTPUTS")
10+
set(INPUTS)
11+
12+
foreach (input IN LISTS ARGN)
13+
get_filename_component(noext_name "${input}" NAME_WE)
14+
list(APPEND "FASTTYPEGEN_${Name}_OUTPUTS"
15+
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.cpp"
16+
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.h"
17+
"${CMAKE_CURRENT_BINARY_DIR}/${noext_name}.inl")
18+
list(APPEND INPUTS "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
19+
endforeach (input)
20+
21+
if (CMAKE_CROSSCOMPILING)
22+
set(FAST_TYPE_GEN_TARGET)
23+
endif (CMAKE_CROSSCOMPILING)
24+
25+
add_custom_command(
26+
OUTPUT ${FASTTYPEGEN_${Name}_OUTPUTS}
27+
COMMAND fast_type_gen -- ${INPUTS}
28+
DEPENDS ${ARGN} ${FAST_TYPE_GEN_TARGET}
29+
COMMENT "[FASTTYPEGEN][${Name}] Building Fast Application Types"
30+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
31+
VERBATIM)
32+
33+
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
34+
35+
set("FASTTYPEGEN_${Name}_OUTPUTS" "${FASTTYPEGEN_${Name}_OUTPUTS}" PARENT_SCOPE)
36+
set("FASTTYPEGEN_${Name}_DEFINED" TRUE PARENT_SCOPE)
37+
set("FASTTYPEGEN_${Name}_INPUTS" "${ARGN}" PARENT_SCOPE)
38+
endfunction (FASTTYPEGEN_TARGET)

0 commit comments

Comments
 (0)