Skip to content

Commit 9df5dc1

Browse files
committed
Configure as ignition package using ign-cmake2
Fixes gazebosim#181. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
1 parent 2905643 commit 9df5dc1

36 files changed

+185
-1368
lines changed

CMakeLists.txt

+39-324
Original file line numberDiff line numberDiff line change
@@ -4,350 +4,65 @@ if(COMMAND CMAKE_POLICY)
44
CMAKE_POLICY(SET CMP0003 NEW)
55
CMAKE_POLICY(SET CMP0004 NEW)
66
endif(COMMAND CMAKE_POLICY)
7-
enable_testing()
87

9-
# with -fPIC
10-
if(UNIX AND NOT WIN32)
11-
set (CMAKE_INSTALL_PREFIX "/usr" CACHE STRING "Install Prefix")
12-
find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
13-
if(CMAKE_UNAME)
14-
exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR)
15-
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL
16-
"processor type (i386 and x86_64)")
17-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
18-
ADD_DEFINITIONS(-fPIC)
19-
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
20-
endif(CMAKE_UNAME)
21-
endif()
22-
23-
project (sdformat10)
8+
project (sdformat10 VERSION 10.6.0)
249

2510
# The protocol version has nothing to do with the package version set below.
2611
# It represents the current version of sdformat implement by the software
2712
set (SDF_PROTOCOL_VERSION 1.7)
2813

29-
set (SDF_MAJOR_VERSION 10)
30-
set (SDF_MINOR_VERSION 6)
31-
set (SDF_PATCH_VERSION 0)
32-
33-
set (SDF_VERSION ${SDF_MAJOR_VERSION}.${SDF_MINOR_VERSION})
34-
set (SDF_VERSION_FULL ${SDF_MAJOR_VERSION}.${SDF_MINOR_VERSION}.${SDF_PATCH_VERSION})
35-
36-
string (TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
37-
string(REGEX REPLACE "[0-9]+" "" PROJECT_NAME_NO_VERSION ${PROJECT_NAME})
38-
string(TOLOWER ${PROJECT_NAME_NO_VERSION} PROJECT_NAME_NO_VERSION_LOWER)
39-
set(PROJECT_EXPORT_NAME ${PROJECT_NAME_LOWER})
40-
set(PROJECT_LIBRARY_TARGET_NAME ${PROJECT_NAME_LOWER})
41-
4214
set (project_cmake_dir ${PROJECT_SOURCE_DIR}/cmake
4315
CACHE PATH "Location of CMake scripts")
4416

45-
message (STATUS "${PROJECT_NAME} version ${SDF_VERSION_FULL}")
46-
set (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
47-
48-
#============================================================================
49-
# We turn off extensions because (1) we do not ever want to use non-standard
50-
# compiler extensions, and (2) this variable is on by default, causing cmake
51-
# to choose the flag -std=gnu++14 instead of -std=c++14 when the C++14
52-
# features are requested. Explicitly turning this flag off will force cmake to
53-
# choose -std=c++14.
54-
# See https://github.com/ignitionrobotics/ign-cmake/issues/13 for more info.
55-
set(CMAKE_CXX_EXTENSIONS off)
56-
57-
# Include GNUInstallDirs to get canonical paths
58-
include(GNUInstallDirs)
59-
60-
# Default test type for test all over source
61-
set(TEST_TYPE "UNIT")
17+
message (STATUS "${PROJECT_NAME} version ${PROJECT_VERSION_FULL}")
6218

63-
# developer's option to cache PKG_CONFIG_PATH and
64-
# LD_LIBRARY_PATH for local installs
65-
if(PKG_CONFIG_PATH)
66-
set (ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH})
67-
endif()
68-
if(LD_LIBRARY_PATH)
69-
set (ENV{LD_LIBRARY_PATH} ${LD_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH})
70-
endif()
71-
72-
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/sdformat-${SDF_VERSION}/sdf")
73-
set (LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Installation directory for libraries (relative to CMAKE_INSTALL_PREFIX)")
74-
set (BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE STRING "Installation directory for binaries (relative to CMAKE_INSTALL_PREFIX)")
75-
set (USE_FULL_RPATH OFF CACHE BOOL "Set to true to enable full rpath")
76-
77-
set(PKG_NAME SDFormat)
78-
set(sdf_target sdformat${SDF_MAJOR_VERSION})
19+
set(sdf_target sdformat${PROJECT_VERSION_MAJOR})
7920
set(sdf_config_install_dir "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME_LOWER}/")
8021
set(sdf_import_target_name ${PROJECT_EXPORT_NAME}::${sdf_target})
8122
set(sdf_target_output_filename "${sdf_target}-targets.cmake")
8223

8324

8425
OPTION(SDFORMAT_DISABLE_CONSOLE_LOGFILE "Disable the sdformat console logfile" OFF)
8526

86-
if (USE_FULL_RPATH)
87-
# use, i.e. don't skip the full RPATH for the build tree
88-
set(CMAKE_SKIP_BUILD_RPATH FALSE)
89-
90-
# when building, don't use the install RPATH already
91-
# (but later on when installing)
92-
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
93-
94-
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
95-
96-
# add the automatically determined parts of the RPATH
97-
# which point to directories outside the build tree to the install RPATH
98-
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
99-
100-
# the RPATH to be used when installing, but only if its not a system directory
101-
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" isSystemDir)
102-
if("${isSystemDir}" STREQUAL "-1")
103-
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
104-
endif("${isSystemDir}" STREQUAL "-1")
105-
endif()
106-
10727
set (BUILD_SDF ON CACHE INTERNAL "Build SDF" FORCE)
108-
set (build_errors "" CACHE INTERNAL "build errors" FORCE)
109-
set (build_warnings "" CACHE INTERNAL "build warnings" FORCE)
11028

11129
set (sdf_cmake_dir ${PROJECT_SOURCE_DIR}/cmake CACHE PATH
11230
"Location of CMake scripts")
11331

114-
message (STATUS "\n\n====== Finding 3rd Party Packages ======")
115-
include (${sdf_cmake_dir}/SDFUtils.cmake)
116-
include (${sdf_cmake_dir}/SearchForStuff.cmake)
117-
message (STATUS "----------------------------------------\n")
118-
119-
#####################################
120-
# Set the default build type
121-
if (NOT CMAKE_BUILD_TYPE)
122-
set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
123-
"Choose the type of build, options are: Debug Release RelWithDebInfo Profile Check" FORCE)
124-
endif (NOT CMAKE_BUILD_TYPE)
125-
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
126-
127-
set (BUILD_TYPE_PROFILE FALSE)
128-
set (BUILD_TYPE_RELEASE FALSE)
129-
set (BUILD_TYPE_RELWITHDEBINFO FALSE)
130-
set (BUILD_TYPE_DEBUG FALSE)
131-
132-
if ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "PROFILE")
133-
set (BUILD_TYPE_PROFILE TRUE)
134-
elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE")
135-
set (BUILD_TYPE_RELEASE TRUE)
136-
elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELWITHDEBINFO")
137-
set (BUILD_TYPE_RELWITHDEBINFO TRUE)
138-
elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "DEBUG")
139-
set (BUILD_TYPE_DEBUG TRUE)
140-
elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "COVERAGE")
141-
include (${project_cmake_dir}/CodeCoverage.cmake)
142-
set (BUILD_TYPE_DEBUG TRUE)
143-
SETUP_TARGET_FOR_COVERAGE(coverage ctest coverage)
144-
else()
145-
# NONE is a valid CMAKE_BUILD_TYPE
146-
if (NOT "${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "NONE")
147-
build_error("CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} unknown. Valid options are: Debug Release RelWithDebInfo Profile Coverage None")
148-
endif()
149-
endif()
150-
151-
#####################################
152-
# Handle CFlags
153-
unset (CMAKE_C_FLAGS_ALL CACHE)
154-
155-
# USE_HOST_CFLAGS (default TRUE)
156-
# Will check building host machine for proper cflags
157-
if(NOT DEFINED USE_HOST_CFLAGS OR USE_HOST_CFLAGS)
158-
message(STATUS "Enable host CFlags")
159-
include (${project_cmake_dir}/HostCFlags.cmake)
160-
endif()
161-
162-
# USE_UPSTREAM_CFLAGS (default TRUE)
163-
# Will use predefined ignition developers cflags
164-
if(NOT DEFINED USE_UPSTREAM_CFLAGS OR USE_UPSTREAM_CFLAGS)
165-
message(STATUS "Enable upstream CFlags")
166-
include(${project_cmake_dir}/DefaultCFlags.cmake)
167-
endif()
168-
169-
# Check if warning options are avaliable for the compiler and return WARNING_CXX_FLAGS variable
170-
if (MSVC)
171-
set(WARN_LEVEL "/W4")
172-
173-
# Unable to be filtered flags (failing due to limitations in filter_valid_compiler_warnings)
174-
# Handling exceptions rightly and ignore unknown pragmas
175-
set(UNFILTERED_FLAGS "/EHsc /wd4068")
176-
else()
177-
# Equivalent to Wall (according to man gcc) but removed the unknown pragmas since we use
178-
# MSVC only pragmas all over the code
179-
list(APPEND WARN_LEVEL -Waddress -Warray-bounds -Wcomment -Wformat -Wnonnull)
180-
list(APPEND WARN_LEVEL -Wparentheses -Wreorder -Wreturn-type)
181-
list(APPEND WARN_LEVEL -Wsequence-point -Wsign-compare -Wstrict-aliasing)
182-
list(APPEND WARN_LEVEL -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized)
183-
list(APPEND WARN_LEVEL -Wunused-function -Wunused-label -Wunused-value)
184-
list(APPEND WARN_LEVEL -Wunused-variable -Wvolatile-register-var)
185-
186-
# Unable to be filtered flags (failing due to limitations in filter_valid_compiler_warnings)
187-
set(UNFILTERED_FLAGS "-Wc++17-compat")
188-
endif()
189-
190-
filter_valid_compiler_warnings(${WARN_LEVEL} -Wextra -Wno-long-long
191-
-Wno-unused-value -Wno-unused-value -Wno-unused-value -Wno-unused-value
192-
-Wfloat-equal -Wshadow -Winit-self -Wswitch-default
193-
-Wmissing-include-dirs -pedantic -Wno-pragmas)
194-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${WARNING_CXX_FLAGS} ${UNFILTERED_FLAGS}")
195-
19632
#################################################
197-
# OS Specific initialization
198-
if (UNIX)
199-
sdf_setup_unix()
200-
endif ()
201-
202-
if (WIN32)
203-
sdf_setup_windows()
204-
endif ()
205-
206-
if (APPLE)
207-
sdf_setup_apple()
208-
endif ()
209-
210-
#################################################
211-
# Print warnings and errors
212-
if ( build_warnings )
213-
message(WARNING "-- BUILD WARNINGS")
214-
foreach (msg ${build_warnings})
215-
message(WARNING "-- ${msg}")
216-
endforeach ()
217-
message(WARNING "-- END BUILD WARNINGS\n")
218-
endif (build_warnings)
219-
220-
########### Add uninstall target ###############
221-
configure_file(
222-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
223-
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
224-
IMMEDIATE @ONLY)
225-
add_custom_target(uninstall
226-
"${CMAKE_COMMAND}" -P
227-
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
228-
229-
if (build_errors)
230-
message(SEND_ERROR "-- BUILD ERRORS: These must be resolved before compiling.")
231-
foreach (msg ${build_errors})
232-
message(SEND_ERROR "-- ${msg}")
233-
endforeach ()
234-
message(SEND_ERROR "-- END BUILD ERRORS\n")
235-
message (FATAL_ERROR "Errors encountered in build. Please see the BUILD ERRORS above.")
236-
237-
else (build_errors)
238-
239-
########################################
240-
# Write the config.h file
241-
configure_file (${sdf_cmake_dir}/sdf_config.h.in
242-
${PROJECT_BINARY_DIR}/sdf/sdf_config.h)
243-
sdf_install_includes("" ${PROJECT_BINARY_DIR}/sdf/sdf_config.h)
244-
245-
message (STATUS "C Flags:${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")
246-
message (STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
247-
message (STATUS "Install path: ${CMAKE_INSTALL_PREFIX}")
248-
249-
if (BUILD_SDF)
250-
include_directories(include
251-
${PROJECT_BINARY_DIR}
252-
${PROJECT_BINARY_DIR}/include
253-
)
254-
255-
link_directories(${PROJECT_BINARY_DIR}/src)
256-
257-
if (NOT DEFINED BUILD_TESTING OR BUILD_TESTING)
258-
set(BUILD_SDF_TEST TRUE)
259-
else()
260-
set(BUILD_SDF_TEST FALSE)
261-
endif()
262-
263-
if (BUILD_SDF_TEST)
264-
add_subdirectory(test)
265-
endif()
266-
add_subdirectory(src)
267-
add_subdirectory(include/sdf)
268-
add_subdirectory(sdf)
269-
add_subdirectory(conf)
270-
add_subdirectory(doc)
271-
endif(BUILD_SDF)
272-
273-
########################################
274-
# Setup Codecheck
275-
include (IgnCodeCheck)
276-
set(CPPCHECK_DIRS
277-
${PROJECT_SOURCE_DIR}/src
278-
${PROJECT_SOURCE_DIR}/include
279-
${PROJECT_SOURCE_DIR}/test/integration
280-
${PROJECT_SOURCE_DIR}/test/performance)
281-
282-
set(CPPCHECK_INCLUDE_DIRS
283-
${PROJECT_BINARY_DIR}
284-
${PROJECT_SOURCE_DIR}/include
285-
${PROJECT_SOURCE_DIR}/test/integration
286-
${PROJECT_SOURCE_DIR}/test/performance)
287-
288-
# Ignore vendored directories.
289-
file(WRITE ${PROJECT_BINARY_DIR}/cppcheck.suppress
290-
"*:${PROJECT_SOURCE_DIR}/src/urdf/*\n"
291-
)
292-
ign_setup_target_for_codecheck()
293-
294-
########################################
295-
# Make the package config file
296-
configure_file(${CMAKE_SOURCE_DIR}/cmake/sdformat_pc.in
297-
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME_LOWER}.pc @ONLY)
298-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME_LOWER}.pc DESTINATION
299-
${LIB_INSTALL_DIR}/pkgconfig COMPONENT pkgconfig)
300-
301-
########################################
302-
# Configure documentation uploader
303-
configure_file("${CMAKE_SOURCE_DIR}/cmake/upload_doc.sh.in"
304-
${CMAKE_BINARY_DIR}/upload_doc.sh @ONLY)
305-
306-
########################################
307-
# Make the cmake config files
308-
set(sdf_config_input "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdf_config.cmake.in")
309-
set(sdf_config_output "cmake/${sdf_target}-config.cmake")
310-
set(sdf_version_output "cmake/${sdf_target}-config-version.cmake")
311-
set(sdf_config_install_dir "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME_LOWER}/")
312-
313-
include(CMakePackageConfigHelpers)
314-
#--------------------------------------
315-
# Configure and install the config file
316-
configure_package_config_file(
317-
${sdf_config_input}
318-
${sdf_config_output}
319-
INSTALL_DESTINATION ${sdf_config_install_dir}
320-
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
321-
322-
#--------------------------------------
323-
# Configure and install the version file
324-
write_basic_package_version_file(
325-
${CMAKE_CURRENT_BINARY_DIR}/${sdf_version_output}
326-
VERSION "${SDF_VERSION_FULL}"
327-
COMPATIBILITY SameMajorVersion)
328-
329-
install(FILES
330-
${CMAKE_CURRENT_BINARY_DIR}/${sdf_config_output}
331-
${CMAKE_CURRENT_BINARY_DIR}/${sdf_version_output}
332-
DESTINATION ${sdf_config_install_dir}
333-
COMPONENT cmake)
334-
335-
########################################
336-
# Package Creation:
337-
include (${sdf_cmake_dir}/sdf_cpack.cmake)
338-
set (CPACK_PACKAGE_VERSION "${SDF_VERSION_FULL}")
339-
set (CPACK_PACKAGE_VERSION_MAJOR "${SDF_MAJOR_VERSION}")
340-
set (CPACK_PACKAGE_VERSION_MINOR "${SDF_MINOR_VERSION}")
341-
set (CPACK_PACKAGE_VERSION_PATCH "${SDF_PATCH_VERSION}")
342-
343-
if (CPACK_GENERATOR)
344-
message(STATUS "Found CPack generators: ${CPACK_GENERATOR}")
345-
346-
configure_file("${sdf_cmake_dir}/cpack_options.cmake.in"
347-
${SDF_CPACK_CFG_FILE} @ONLY)
348-
set(CPACK_PROJECT_CONFIG_FILE ${SDF_CPACK_CFG_FILE})
349-
include (CPack)
350-
endif()
351-
352-
message(STATUS "Configuration successful. Type make to compile sdf")
353-
endif(build_errors)
33+
# Find ign-cmake
34+
find_package(ignition-cmake2 2.9 REQUIRED)
35+
set(IGN_CMAKE_VER ${ignition-cmake2_VERSION_MAJOR})
36+
37+
if (BUILD_SDF)
38+
ign_configure_project(
39+
NO_IGNITION_PREFIX
40+
REPLACE_IGNITION_INCLUDE_PATH sdf)
41+
42+
message (STATUS "\n\n====== Finding 3rd Party Packages ======")
43+
include (${sdf_cmake_dir}/SDFUtils.cmake)
44+
include (${sdf_cmake_dir}/SearchForStuff.cmake)
45+
message (STATUS "----------------------------------------\n")
46+
47+
ign_configure_build(QUIT_IF_BUILD_ERRORS)
48+
ign_create_packages()
49+
50+
add_subdirectory(sdf)
51+
add_subdirectory(conf)
52+
add_subdirectory(doc)
53+
endif(BUILD_SDF)
54+
55+
########################################
56+
# Setup Codecheck
57+
58+
# Ignore vendored directories.
59+
file(WRITE ${PROJECT_BINARY_DIR}/cppcheck.suppress
60+
"*:${PROJECT_SOURCE_DIR}/src/urdf/*\n"
61+
)
62+
63+
########################################
64+
# Configure documentation uploader
65+
configure_file("${CMAKE_SOURCE_DIR}/cmake/upload_doc.sh.in"
66+
${CMAKE_BINARY_DIR}/upload_doc.sh @ONLY)
67+
68+
message(STATUS "Configuration successful. Type make to compile sdf")

0 commit comments

Comments
 (0)