Skip to content

Commit 38d2a49

Browse files
committed
Improvements in the cmake builder
1 parent 89035cd commit 38d2a49

11 files changed

Lines changed: 141 additions & 58 deletions

File tree

CMakeLists.txt

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,41 @@
3838
# This file contains the top level CMakeLists.txt logic for the
3939
# SCL software package.
4040

41+
PROJECT(SCL)
42+
SET(SCL_VERSION_MAJOR 0)
43+
SET(SCL_VERSION_MINOR 5-dev)
44+
SET(SCL_VERSION ${SCL_VERSION_MAJOR}.${SCL_VERSION_MINOR})
45+
4146
# Minimum required version of CMake
4247
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
4348
IF(COMMAND CMAKE_POLICY)
4449
CMAKE_POLICY(SET CMP0003 NEW)
4550
ENDIF(COMMAND CMAKE_POLICY)
4651

47-
# set CMake project name
48-
PROJECT(SCL)
49-
50-
if( CMAKE_BUILD_TYPE STREQUAL "" )
51-
message( "-- Debug build - to override, rerun cmake with '-DCMAKE_BUILD_TYPE=Release'." )
52-
set( CMAKE_BUILD_TYPE Debug )
53-
endif()
52+
IF (NOT MSVC)
53+
IF( NOT DEFINED SCL_BUILD_TYPE )
54+
SET( SCL_BUILD_TYPE "Debug" CACHE STRING "Build type" ) # By default set debug build
55+
ENDIF( NOT DEFINED SCL_BUILD_TYPE )
56+
SET( CMAKE_BUILD_TYPE ${SCL_BUILD_TYPE} CACHE INTERNAL "Build type,
57+
immutable" FORCE )
58+
ENDIF(NOT MSVC)
59+
60+
# Define helper macro OPTION_WITH_DEFAULT
61+
MACRO( OPTION_WITH_DEFAULT OPTION_NAME OPTION_STRING OPTION_DEFAULT )
62+
IF( NOT DEFINED ${OPTION_NAME} )
63+
SET( ${OPTION_NAME} ${OPTION_DEFAULT} )
64+
ENDIF( NOT DEFINED ${OPTION_NAME} )
65+
OPTION( ${OPTION_NAME} "${OPTION_STRING}" ${${OPTION_NAME}} )
66+
ENDMACRO( OPTION_WITH_DEFAULT OPTION_NAME OPTION_STRING OPTION_DEFAULT )
5467

5568
# build shared libs by default
56-
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
69+
OPTION_WITH_DEFAULT(SCL_BUILD_SHARED_LIBS "Build shared libs" ON )
5770

5871
# build static libs by default
59-
OPTION(BUILD_STATIC_LIBS "Build static libraries" OFF)
72+
OPTION_WITH_DEFAULT(SCL_BUILD_STATIC_LIBS "Build static libs" OFF)
6073

61-
OPTION(PYTHON_GENERATOR "Compile fedex_plus_python" ON)
62-
OPTION(CPP_GENERATOR "Compile fedex_plus" ON)
63-
64-
# Set version
65-
SET(SCL_VERSION_MAJOR "3")
66-
SET(SCL_VERSION_MINOR "2")
67-
SET(SCL_VERSION_PATCH "0")
68-
SET(SCL_VERSION "${SCL_VERSION_MAJOR}.${SCL_VERSION_MINOR}.${SCL_VERSION_PATCH}")
74+
OPTION_WITH_DEFAULT(SCL_PYTHON_GENERATOR "Compile fedex_plus_python" ON)
75+
OPTION_WITH_DEFAULT(SCL_CPP_GENERATOR "Compile fedex_plus" ON)
6976

7077
# CMake derives much of its functionality from modules, typically
7178
# stored in one directory - let CMake know where to find them.
@@ -100,16 +107,28 @@ ENDIF(NOT WIN32)
100107

101108
#---------------------------------------------------------------------
102109
# Testing option
103-
OPTION( ENABLE_TESTING "Enable unittesting framework" OFF )
104-
IF(ENABLE_TESTING)
105-
set( CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage" ) #for code coverage
106-
set( CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage" )
107-
if( NOT DEFINED BUILD_SCHEMAS )
108-
set( BUILD_SCHEMAS "ALL" ) #test all schemas, unless otherwise specified
110+
OPTION_WITH_DEFAULT( SCL_ENABLE_TESTING "Enable unittesting framework" ON )
111+
IF(SCL_ENABLE_TESTING)
112+
if( NOT DEFINED SCL_BUILD_SCHEMAS )
113+
set( SCL_BUILD_SCHEMAS "ALL" ) #test all schemas, unless otherwise specified
109114
endif()
110115
INCLUDE(CTest)
111116
ENABLE_TESTING()
112-
ENDIF(ENABLE_TESTING)
117+
ENDIF(SCL_ENABLE_TESTING)
118+
119+
#---------------------------------------------------------------------
120+
# Coverage option
121+
OPTION_WITH_DEFAULT( SCL_ENABLE_COVERAGE "Enable code coverage test" OFF )
122+
IF(SCL_ENABLE_COVERAGE)
123+
SET(SCL_ENABLE_TESTING ON CACHE BOOL "Testing enabled by coverage option" FORCE)
124+
# build static libs, better coverage report
125+
SET(SCL_BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE )
126+
SET(SCL_BUILD_STATIC_LIBS ON CACHE BOOL "Build static libs" FORCE )
127+
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fprofile-arcs -ftest-coverage" CACHE STRING "Extra compile flags required by code coverage" FORCE)
128+
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fprofile-arcs -ftest-coverage" CACHE STRING "Extra compile flags required by code coverage" FORCE)
129+
SET(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-fprofile-arcs -ftest-coverage" CACHE STRING "Extra linker flags required by code coverage" FORCE)
130+
SET(SCL_BUILD_TYPE "Debug" CACHE STRING "Build type required by testing framework" FORCE)
131+
ENDIF(SCL_ENABLE_COVERAGE)
113132

114133
#---------------------------------------------------------------------
115134
# The following logic is what allows binaries to run successfully in
@@ -174,23 +193,21 @@ ENDFOREACH()
174193
# The location in which to install SCL. Need a good Debug location
175194
# for Windows. Only do this if CMAKE_INSTALL_PREFIX hasn't been set
176195
# already, to try and allow parent builds (if any) some control.
177-
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
178-
IF(NOT WIN32)
179-
IF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
180-
SET(CMAKE_INSTALL_PREFIX "/usr")
181-
ELSEIF ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
182-
SET(CMAKE_INSTALL_PREFIX "${SCL_SOURCE_DIR}/../scl-install")
183-
MESSAGE("--- Setting debug install dir to ${CMAKE_INSTALL_PREFIX}")
184-
ELSE("${CMAKE_BUILD_TYPE}" MATCHES "Release")
185-
SET(CMAKE_INSTALL_PREFIX "/usr/local")
186-
ENDIF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
187-
ENDIF(NOT WIN32)
188-
SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "SCL install prefix" FORCE)
189-
SET(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 0)
190-
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
191-
192-
OPTION(SCL-BUILD_EXPRESS_ONLY "Only build express parser." OFF)
193-
MARK_AS_ADVANCED(SCL-BUILD_EXPRESS_ONLY)
196+
IF(NOT WIN32)
197+
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
198+
SET(SCL_INSTALL_PREFIX "${SCL_SOURCE_DIR}/../scl-install")
199+
ELSE()
200+
SET(SCL_INSTALL_PREFIX "/usr/local")
201+
ENDIF()
202+
ENDIF(NOT WIN32)
203+
SET( SCL_INSTALL_PREFIX ${SCL_INSTALL_PREFIX} CACHE
204+
PATH "Install prefix prepended to target to create install location" )
205+
SET( CMAKE_INSTALL_PREFIX ${SCL_INSTALL_PREFIX} CACHE INTERNAL "Prefix
206+
prepended to install directories if target destination is not absolute,
207+
immutable" FORCE )
208+
209+
OPTION(SCL_BUILD_EXPRESS_ONLY "Only build express parser." OFF)
210+
MARK_AS_ADVANCED(SCL_BUILD_EXPRESS_ONLY)
194211

195212
# Take the scl config file template and copy it to the build directory so CMake
196213
# scripts can append to it if need be
@@ -277,3 +294,31 @@ ADD_SUBDIRECTORY(doc)
277294
# this is for testing - 'make core' builds everything that isn't generated
278295
add_custom_target( core )
279296
add_dependencies( core stepdai check-express stepeditor fedex_plus )
297+
298+
###############################################################################
299+
# SCL Packaging #
300+
# $make package #
301+
###############################################################################
302+
303+
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "STEP Class Library")
304+
SET(CPACK_SET_DESTDIR "ON")
305+
306+
SET(CPACK_PACKAGE_VERSION_MAJOR ${SCL_VERSION_MAJOR})
307+
SET(CPACK_PACKAGE_VERSION_MINOR ${SCL_VERSION_MINOR})
308+
SET(CPACK_PACKAGE_NAME SCL )
309+
310+
SET(CPACK_PACKAGE_CONTACT "SCL Developers <scl-dev@googlegroups.com>")
311+
INCLUDE(CPack)
312+
313+
########################################################################################
314+
# Uninstall code #
315+
# From http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F #
316+
# ######################################################################################
317+
configure_file(
318+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
319+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
320+
IMMEDIATE @ONLY)
321+
322+
add_custom_target(uninstall
323+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
324+

cmake/SCL_Utils.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ MACRO(SCL_ADDLIB libname srcs libs)
3333
STRING(REGEX REPLACE " " ";" libslist1 "${libs}")
3434
STRING(REGEX REPLACE "-framework;" "-framework " libslist "${libslist1}")
3535
DLL_DEFINE(${libname})
36-
IF(BUILD_SHARED_LIBS)
36+
IF(SCL_BUILD_SHARED_LIBS)
3737
add_library(${libname} SHARED ${srcslist})
3838
if(NOT ${libs} MATCHES "NONE")
3939
target_link_libraries(${libname} ${libslist})
4040
endif(NOT ${libs} MATCHES "NONE")
4141
SET_TARGET_PROPERTIES(${libname} PROPERTIES VERSION ${SCL_VERSION_MAJOR}.${SCL_VERSION_MINOR} SOVERSION ${SCL_VERSION_MAJOR} )
4242
INSTALL(TARGETS ${libname} DESTINATION lib)
43-
ENDIF(BUILD_SHARED_LIBS)
44-
IF(BUILD_STATIC_LIBS AND NOT MSVC)
43+
ENDIF(SCL_BUILD_SHARED_LIBS)
44+
IF(SCL_BUILD_STATIC_LIBS AND NOT MSVC)
4545
add_library(${libname}-static STATIC ${srcslist})
4646
if(NOT ${libs} MATCHES "NONE")
4747
target_link_libraries(${libname}-static ${libslist})
@@ -56,7 +56,7 @@ MACRO(SCL_ADDLIB libname srcs libs)
5656
SET_TARGET_PROPERTIES(${libname}-static PROPERTIES PREFIX "lib")
5757
ENDIF(WIN32)
5858
INSTALL(TARGETS ${libname}-static DESTINATION lib)
59-
ENDIF(BUILD_STATIC_LIBS AND NOT MSVC)
59+
ENDIF(SCL_BUILD_STATIC_LIBS AND NOT MSVC)
6060
# Enable extra compiler flags if local libraries and/or global options dictate
6161
SET(LOCAL_COMPILE_FLAGS "")
6262
FOREACH(extraarg ${ARGN})

cmake/cmake_uninstall.cmake.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
2+
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
3+
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
4+
5+
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
6+
string(REGEX REPLACE "\n" ";" files "${files}")
7+
list(REVERSE files)
8+
foreach (file ${files})
9+
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
10+
if (EXISTS "$ENV{DESTDIR}${file}")
11+
execute_process(
12+
COMMAND ${CMAKE_COMMAND} -E remove "$ENV{DESTDIR}${file}"
13+
OUTPUT_VARIABLE rm_out
14+
RESULT_VARIABLE rm_retval
15+
)
16+
if(NOT ${rm_retval} EQUAL 0)
17+
message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
18+
endif (NOT ${rm_retval} EQUAL 0)
19+
else (EXISTS "$ENV{DESTDIR}${file}")
20+
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
21+
endif (EXISTS "$ENV{DESTDIR}${file}")
22+
endforeach(file)

data/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FUNCTION( TESTABLE_TARGET target )
88
ENDFUNCTION( TESTABLE_TARGET )
99

1010
# To build one or more schemas, configure with
11-
# 'cmake -DBUILD_SCHEMAS="path/to/schema.exp;path/to/schema2.exp"
11+
# 'cmake -DSCL_BUILD_SCHEMAS="path/to/schema.exp;path/to/schema2.exp"
1212

1313
# This function runs fedex on one express file. The generated source goes in a dir
1414
# in the build dir, and it is compiled into a library. A p21read executable is
@@ -120,11 +120,11 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
120120

121121
ENDFUNCTION(BUILD_A_SCHEMA)
122122

123-
if( DEFINED BUILD_SCHEMAS )
124-
if( BUILD_SCHEMAS STREQUAL "ALL" )
125-
file( GLOB_RECURSE BUILD_SCHEMAS ${SCL_SOURCE_DIR}/data/*.exp )
123+
if( DEFINED SCL_BUILD_SCHEMAS )
124+
if( SCL_BUILD_SCHEMAS STREQUAL "ALL" )
125+
file( GLOB_RECURSE SCL_BUILD_SCHEMAS ${SCL_SOURCE_DIR}/data/*.exp )
126126
endif()
127-
foreach( ap ${BUILD_SCHEMAS} )
127+
foreach( ap ${SCL_BUILD_SCHEMAS} )
128128
BUILD_A_SCHEMA( ${ap} )
129129
endforeach()
130130
endif()

doc/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ SET(scl_MANS
44
man/man1/fedex_plus.1
55
man/man1/mkProbe.1
66
)
7-
INSTALL(FILES ${scl_MANS} DESTINATION ${MAN_DIR}/man1)
7+
IF(NOT WIN32)
8+
INSTALL(FILES ${scl_MANS} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
9+
ENDIF(NOT WIN32)

src/cldai/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ include_directories(
4242
SCL_ADDLIB(stepdai "${LIBSTEPDAI_SRCS}" "steputils")
4343

4444
if(APPLE)
45-
set_target_properties(stepdai PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
45+
if(SCL_BUILD_SHARED_LIBS)
46+
set_target_properties(stepdai PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
47+
endif(SCL_BUILD_SHARED_LIBS)
4648
endif(APPLE)

src/cleditor/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ endif()
5050
SCL_ADDLIB(stepeditor "${LIBSTEPEDITOR_SRCS}" stepcore stepdai steputils)
5151

5252
if(APPLE)
53-
set_target_properties(stepeditor PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
53+
if(SCL_BUILD_SHARED_LIBS)
54+
set_target_properties(stepeditor PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
55+
endif(SCL_BUILD_SHARED_LIBS)
5456
endif(APPLE)

src/clstepcore/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ include_directories(
8585

8686
SCL_ADDLIB(stepcore "${LIBSTEPCORE_SRCS} ${LIBDEPEND_SRCS}" "express steputils stepdai")
8787
if(APPLE)
88-
set_target_properties(stepcore PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
88+
if(SCL_BUILD_SHARED_LIBS)
89+
set_target_properties(stepcore PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
90+
endif(SCL_BUILD_SHARED_LIBS)
8991
endif(APPLE)

src/clutils/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ IF(MSVC OR BORLAND)
4242
ENDIF()
4343

4444
if(APPLE)
45-
set_target_properties(steputils PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
45+
if(SCL_BUILD_SHARED_LIBS)
46+
set_target_properties(steputils PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
47+
endif(SCL_BUILD_SHARED_LIBS)
4648
endif(APPLE)

src/exppp/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ add_definitions( -D__STDC__ )
2424
endif()
2525

2626
SCL_ADDLIB(libexppp "${LIBEXPPP_SOURCES}" "express base")
27-
set_target_properties(libexppp PROPERTIES PREFIX "")
27+
if(SCL_BUILD_SHARED_LIBS)
28+
set_target_properties(libexppp PROPERTIES PREFIX "")
29+
endif(SCL_BUILD_SHARED_LIBS)
2830

2931
#SCL_ADDEXEC(exppp "${EXPPP_SOURCES}" "libexppp express")
3032

3133
if(APPLE)
32-
set_target_properties(libexppp PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
34+
if(SCL_BUILD_SHARED_LIBS)
35+
set_target_properties(libexppp PROPERTIES LINK_FLAGS "-flat_namespace -undefined suppress")
36+
endif(SCL_BUILD_SHARED_LIBS)
3337
endif(APPLE)

0 commit comments

Comments
 (0)