Skip to content

Commit 44fb196

Browse files
committed
Simplify relative directory settings
1 parent 18a6528 commit 44fb196

File tree

13 files changed

+181
-47
lines changed

13 files changed

+181
-47
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ if ("${CMAKE_SYSTEM}" MATCHES ".*OpenBSD.*")
7171
set(OPENBSD ON)
7272
endif ("${CMAKE_SYSTEM}" MATCHES ".*OpenBSD.*")
7373

74+
# Path setup - relative build paths and output directories
75+
include(Path_Setup)
76+
7477
# testing and compilation options, build output dirs, install dirs, uninstall, package creation, etc
7578
include(${SC_CMAKE_DIR}/SC_Build_opts.cmake)
7679

cmake/Path_Setup.cmake

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Copyright (c) 2010-2020 United States Government as represented by
2+
# the U.S. Army Research Laboratory.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above
12+
# copyright notice, this list of conditions and the following
13+
# disclaimer in the documentation and/or other materials provided
14+
# with the distribution.
15+
#
16+
# 3. The name of the author may not be used to endorse or promote
17+
# products derived from this software without specific prior written
18+
# permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
33+
#---------------------------------------------------------------------
34+
# Define relative install locations. Don't set these if they have already
35+
# been set by some other means (like a higher level CMakeLists.txt file
36+
# including this one).
37+
38+
# The location in which to install BRL-CAD executables.
39+
if(NOT BIN_DIR)
40+
set(BIN_DIR bin)
41+
endif(NOT BIN_DIR)
42+
43+
# Define a relative path that will "reset" a path back to
44+
# the point before BIN_DIR was appended. This is primarily
45+
# useful when working with generator expressions
46+
unset(RBIN_DIR CACHE)
47+
set(LBIN_DIR "${BIN_DIR}")
48+
while (NOT "${LBIN_DIR}" STREQUAL "")
49+
get_filename_component(LBDIR "${LBIN_DIR}" DIRECTORY)
50+
set(LBIN_DIR "${LBDIR}")
51+
if ("${RBIN_DIR}" STREQUAL "")
52+
set(RBIN_DIR "..")
53+
else ("${RBIN_DIR}" STREQUAL "")
54+
set(RBIN_DIR "../${RBIN_DIR}")
55+
endif ("${RBIN_DIR}" STREQUAL "")
56+
endwhile (NOT "${LBIN_DIR}" STREQUAL "")
57+
58+
# The location in which to install BRL-CAD libraries.
59+
if(NOT LIB_DIR)
60+
set(LIB_DIR lib)
61+
endif(NOT LIB_DIR)
62+
if(NOT LIBEXEC_DIR)
63+
set(LIBEXEC_DIR libexec)
64+
endif(NOT LIBEXEC_DIR)
65+
66+
# The location in which to install BRL-CAD header files.
67+
if(NOT INCLUDE_DIR)
68+
set(INCLUDE_DIR include)
69+
endif(NOT INCLUDE_DIR)
70+
71+
# The location in which to install BRL-CAD data files
72+
if(NOT DATA_DIR)
73+
set(DATA_DIR share)
74+
endif(NOT DATA_DIR)
75+
76+
# The location in which to install BRL-CAD documentation files
77+
if(NOT DOC_DIR)
78+
set(DOC_DIR ${DATA_DIR}/doc)
79+
endif(NOT DOC_DIR)
80+
81+
# The location in which to install BRL-CAD Manual pages
82+
if(NOT MAN_DIR)
83+
set(MAN_DIR ${DATA_DIR}/man)
84+
endif(NOT MAN_DIR)
85+
86+
# Make sure no absolute paths have been supplied to these variables
87+
set(INSTALL_DIRS BIN INCLUDE LIB LIBEXEC DATA MAN DOC)
88+
foreach(instdir ${INSTALL_DIRS})
89+
get_filename_component(instdir_full ${${instdir}_DIR} ABSOLUTE)
90+
if("${${instdir}_DIR}" STREQUAL "${instdir_full}")
91+
message(FATAL_ERROR "Error - absolute path supplied for ${instdir}_DIR. This path must be relative - e.g. \"bin\" instead of \"/usr/bin\"")
92+
set(HAVE_INSTALL_DIR_FULL_PATH 1)
93+
endif("${${instdir}_DIR}" STREQUAL "${instdir_full}")
94+
endforeach(instdir ${INSTALL_DIRS})
95+
96+
#---------------------------------------------------------------------
97+
# Output directories - this is where built library and executable
98+
# files will be placed after building but prior to install. The
99+
# necessary variables change between single and multi configuration
100+
# build systems, so it is necessary to handle both cases on a
101+
# conditional basis.
102+
103+
if(NOT CMAKE_CONFIGURATION_TYPES)
104+
# If we're not doing multi-configuration, just set the three main
105+
# variables to the correct values.
106+
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
107+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${${PROJECT_NAME}_BINARY_DIR}/${LIB_DIR} CACHE INTERNAL "Single output directory for building all libraries.")
108+
endif(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
109+
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
110+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${${PROJECT_NAME}_BINARY_DIR}/${LIB_DIR} CACHE INTERNAL "Single output directory for building all archives.")
111+
endif(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
112+
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
113+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${${PROJECT_NAME}_BINARY_DIR}/${BIN_DIR} CACHE INTERNAL "Single output directory for building all executables.")
114+
endif(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
115+
else(NOT CMAKE_CONFIGURATION_TYPES)
116+
# Multi-configuration is more difficult. Not only do we need to
117+
# properly set the output directories, but we also need to
118+
# identify the "toplevel" directory for each configuration so
119+
# we can place files, documentation, etc. in the correct
120+
# relative positions. Because files may be placed by CMake
121+
# without a build target to put them in their proper relative build
122+
# directory position using these paths, we must fully qualify them
123+
# without using CMAKE_CFG_INTDIR.
124+
#
125+
# We define directories that may not be quite "standard"
126+
# for a particular build tool - for example, native VS2010 projects use
127+
# another directory to denote CPU type being compiled for - but CMake only
128+
# supports multi-configuration setups having multiple configurations,
129+
# not multiple compilers.
130+
#
131+
# One additional wrinkle we must watch for here is the case where
132+
# a multi-configuration setup uses "." for its internal directory -
133+
# if that's the case, we need to just set the various config output
134+
# directories to the same value.
135+
set(CFG_ROOT ${${PROJECT_NAME}_BINARY_DIR})
136+
foreach(CFG_TYPE ${CMAKE_CONFIGURATION_TYPES})
137+
if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
138+
set(CFG_ROOT ${${PROJECT_NAME}_BINARY_DIR}/${CFG_TYPE})
139+
endif(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
140+
string(TOUPPER "${CFG_TYPE}" CFG_TYPE_UPPER)
141+
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
142+
set("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER}" ${CFG_ROOT}/${LIB_DIR} CACHE INTERNAL "Single output directory for building ${CFG_TYPE} libraries.")
143+
endif(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
144+
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
145+
set("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER}" ${CFG_ROOT}/${LIB_DIR} CACHE INTERNAL "Single output directory for building ${CFG_TYPE} archives.")
146+
endif(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
147+
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
148+
set("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER}" ${CFG_ROOT}/${BIN_DIR} CACHE INTERNAL "Single output directory for building ${CFG_TYPE} executables.")
149+
endif(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CFG_TYPE_UPPER})
150+
if(NOT DEFINED CMAKE_BINARY_DIR_${CFG_TYPE_UPPER})
151+
set("CMAKE_BINARY_DIR_${CFG_TYPE_UPPER}" ${CFG_ROOT} CACHE INTERNAL "Toplevel binary dir for ${CFG_TYPE} building.")
152+
endif(NOT DEFINED CMAKE_BINARY_DIR_${CFG_TYPE_UPPER})
153+
if(NOT DEFINED ${PROJECT_NAME}_BINARY_DIR_${CFG_TYPE_UPPER})
154+
set("${PROJECT_NAME}_BINARY_DIR_${CFG_TYPE_UPPER}" ${CFG_ROOT} CACHE INTERNAL "Toplevel binary dir for ${CFG_TYPE} building.")
155+
endif(NOT DEFINED ${PROJECT_NAME}_BINARY_DIR_${CFG_TYPE_UPPER})
156+
endforeach()
157+
endif(NOT CMAKE_CONFIGURATION_TYPES)
158+
159+
# Local Variables:
160+
# tab-width: 8
161+
# mode: cmake
162+
# indent-tabs-mode: t
163+
# End:
164+
# ex: shiftwidth=2 tabstop=8

cmake/SC_Build_opts.cmake

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
# BIN and LIB directories
2-
if(NOT DEFINED BIN_DIR)
3-
set(BIN_DIR bin)
4-
endif(NOT DEFINED BIN_DIR)
5-
6-
if(NOT DEFINED LIB_DIR)
7-
set(LIB_DIR lib)
8-
endif(NOT DEFINED LIB_DIR)
9-
10-
# testing and compilation options, build output dirs, install dirs, etc
11-
# included by root CMakeLists
12-
13-
if(NOT DEFINED INCLUDE_INSTALL_DIR)
14-
set(INCLUDE_INSTALL_DIR include)
15-
endif(NOT DEFINED INCLUDE_INSTALL_DIR)
16-
17-
if(NOT DEFINED LIB_INSTALL_DIR)
18-
set(LIB_INSTALL_DIR lib)
19-
endif(NOT DEFINED LIB_INSTALL_DIR)
20-
21-
if(NOT DEFINED BIN_INSTALL_DIR)
22-
set(BIN_INSTALL_DIR bin)
23-
endif(NOT DEFINED BIN_INSTALL_DIR)
24-
251
if(NOT DEFINED SC_BUILD_TYPE)
262
set(SC_BUILD_TYPE "Debug" CACHE STRING "Build type") # By default set debug build
273
endif(NOT DEFINED SC_BUILD_TYPE)
@@ -51,12 +27,6 @@ OPTION_WITH_DEFAULT(SC_CPP_GENERATOR "Compile exp2cxx" ON)
5127
OPTION_WITH_DEFAULT(SC_MEMMGR_ENABLE_CHECKS "Enable sc_memmgr's memory leak detection" OFF)
5228
OPTION_WITH_DEFAULT(SC_TRACE_FPRINTF "Enable extra comments in generated code so the code's source in exp2cxx may be located" OFF)
5329

54-
# Should we use C++11?
55-
OPTION_WITH_DEFAULT(SC_ENABLE_CXX11 "Build with C++ 11 features" ON)
56-
57-
# Get version from git
58-
OPTION_WITH_DEFAULT(SC_GIT_VERSION "Build using version from git" ON)
59-
6030
option(SC_BUILD_EXPRESS_ONLY "Only build express parser." OFF)
6131
mark_as_advanced(SC_BUILD_EXPRESS_ONLY)
6232

cmake/SC_CXX_schema_macros.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ endmacro(P21_TESTS sfile)
2828
macro(SCHEMA_EXES)
2929
RELATIVE_PATH_TO_TOPLEVEL(${CMAKE_CURRENT_SOURCE_DIR} RELATIVE_PATH_COMPONENT)
3030
SC_ADDEXEC(p21read_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/test/p21read/p21read.cc" LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
31-
#add_dependencies(p21read_${PROJECT_NAME} version_string)
3231
if(NOT WIN32)
3332
SC_ADDEXEC(lazy_${PROJECT_NAME} SOURCES "${RELATIVE_PATH_COMPONENT}/src/cllazyfile/lazy_test.cc" LINK_LIBRARIES ${PROJECT_NAME} steplazyfile stepdai stepcore stepeditor steputils base TESTABLE)
34-
#add_dependencies(lazy_${PROJECT_NAME} version_string)
3533
endif(NOT WIN32)
3634

3735
#add user-defined executables
3836
foreach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
3937
get_filename_component(name ${src} NAME_WE)
4038
get_filename_component(path ${src} ABSOLUTE)
4139
SC_ADDEXEC(${name}_${PROJECT_NAME} SOURCES ${src} LINK_LIBRARIES ${PROJECT_NAME} stepdai stepcore stepeditor steputils base TESTABLE)
42-
add_dependencies(${name}_${PROJECT_NAME} version_string)
4340
#set_target_properties(${name}_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${${PROJECT_NAME}_COMPILE_FLAGS} -I${path}")
4441
endforeach(src ${SC_SDAI_ADDITIONAL_EXES_SRCS})
4542
ENDMACRO(SCHEMA_EXES)

cmake/SC_Config_Headers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ endif(SC_ENABLE_CXX11)
9999
# Now that all the tests are done, configure the sc_cf.h file:
100100
get_property(CONFIG_H_FILE_CONTENTS GLOBAL PROPERTY SC_CONFIG_H_CONTENTS)
101101
file(WRITE ${CONFIG_H_FILE} "${CONFIG_H_FILE_CONTENTS}")
102-
configure_file(${CONFIG_H_FILE} ${SC_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_cf.h)
102+
configure_file(${CONFIG_H_FILE} ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h)
103103

104104
# Local Variables:
105105
# tab-width: 8

cmake/schema_scanner/schemaScanner.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ message( STATUS "Schema scanner built. Running it...")
7171

7272
# not sure if it makes sense to install this or not...
7373
if(WIN32)
74-
install(PROGRAMS ${SCANNER_OUT_DIR}/schema_scanner.exe DESTINATION ${BIN_INSTALL_DIR})
74+
install(PROGRAMS ${SCANNER_OUT_DIR}/schema_scanner.exe DESTINATION ${BIN_DIR})
7575
else(WIN32)
76-
install(PROGRAMS ${SCANNER_OUT_DIR}/schema_scanner DESTINATION ${BIN_INSTALL_DIR})
76+
install(PROGRAMS ${SCANNER_OUT_DIR}/schema_scanner DESTINATION ${BIN_DIR})
7777
endif(WIN32)
7878

7979
# macro SCHEMA_CMLIST

include/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ set(express_HDRS
2222
express/variable.h
2323
)
2424
install(FILES ${express_HDRS}
25-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode/express)
25+
DESTINATION ${INCLUDE_DIR}/stepcode/express)
2626

2727
set(exppp_HDRS
2828
exppp/exppp.h
2929
)
3030
install(FILES ${exppp_HDRS}
31-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode/exppp)
31+
DESTINATION ${INCLUDE_DIR}/stepcode/exppp)
3232

3333
install(FILES ordered_attrs.h
3434
sc_export.h
3535
sc_stdbool.h
36-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode)
36+
DESTINATION ${INCLUDE_DIR}/stepcode)
3737

38-
install(FILES ${SC_BINARY_DIR}/${INCLUDE_INSTALL_DIR}/sc_cf.h
39-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode)
38+
install(FILES ${SC_BINARY_DIR}/${INCLUDE_DIR}/sc_cf.h
39+
DESTINATION ${INCLUDE_DIR}/stepcode)
4040

4141
# Local Variables:
4242
# tab-width: 8

src/base/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
6161
endif(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/judy/src")
6262

6363
install(FILES ${SC_BASE_HDRS}
64-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode/base)
64+
DESTINATION ${INCLUDE_DIR}/stepcode/base)
6565

6666
# Local Variables:
6767
# tab-width: 8

src/cldai/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if($CACHE{SC_BUILD_STATIC_LIBS})
4848
endif()
4949

5050
install(FILES ${SC_CLDAI_HDRS}
51-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode/cldai)
51+
DESTINATION ${INCLUDE_DIR}/stepcode/cldai)
5252

5353
# Local Variables:
5454
# tab-width: 8

src/cleditor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if($CACHE{SC_BUILD_STATIC_LIBS})
3939
endif()
4040

4141
install(FILES ${SC_CLEDITOR_HDRS}
42-
DESTINATION ${INCLUDE_INSTALL_DIR}/stepcode/cleditor)
42+
DESTINATION ${INCLUDE_DIR}/stepcode/cleditor)
4343

4444
# Local Variables:
4545
# tab-width: 8

0 commit comments

Comments
 (0)