Skip to content

Commit

Permalink
Use target_include_directories().
Browse files Browse the repository at this point in the history
Clients no longer need to use "include_directories()".
  • Loading branch information
chrisdembia committed Apr 21, 2017
1 parent 5b47ecb commit a3c133f
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 86 deletions.
8 changes: 3 additions & 5 deletions Bindings/Java/OpenSimJNI/CMakeLists.txt
Expand Up @@ -64,11 +64,6 @@ OpenSimGenerateJavaWrapper(examplecomponents
${SWIG_JAVA_EXAMPLECOMPONENTS_CXX_FILE}
${SWIG_JAVA_EXAMPLECOMPONENTS_H_FILE})

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2})

set(EXPORT_MACRO OSIM${UKIT}_EXPORTS)

add_library(osim${KIT}
Expand All @@ -86,6 +81,9 @@ add_library(osim${KIT}
OpenSimContext.cpp
OpenSimContext.h)

target_include_directories(osim${KIT} PRIVATE
${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})

target_link_libraries(osim${KIT} osimTools osimSimmFileWriter osimExampleComponents)

set_target_properties(osim${KIT} PROPERTIES
Expand Down
7 changes: 2 additions & 5 deletions Bindings/Python/CMakeLists.txt
Expand Up @@ -123,13 +123,10 @@ macro(OpenSimAddPythonModule)
endif()
set_source_files_properties("${_output_cxx_file}"
PROPERTIES COMPILE_FLAGS "${_COMPILE_FLAGS}")

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors
${PYTHON_INCLUDE_PATH}
)

add_library(${_libname} SHARED ${_output_cxx_file} ${_output_header_file})

target_include_directories(${_libname} PRIVATE ${PYTHON_INCLUDE_PATH})

target_link_libraries(${_libname}
osimTools osimExampleComponents ${PYTHON_LIBRARIES})
Expand Down
3 changes: 1 addition & 2 deletions DEVELOPING.md
Expand Up @@ -95,9 +95,8 @@ The layout of the distribution on macOS (and Linux) is as follows:
- `bin/` opensim-cmd
- `etc/OpenSim_buildinfo.txt` Describes the compiler used to build OpenSim.
- `include/`
- `OpenSim/` OpenSim headers.
- `OpenSim/` OpenSim (and Lepton) headers.
- `simbody/` Simbody headers.
- `Vendors/` Lepton headers.
- `lib/` (on some Linux variants, `lib/<arch>/`) OpenSim, SimTK, and BTK shared libraries.
- `cmake/` OpenSimConfig.cmake, SimbodyConfig.cmake, etc.
- `python2.7/site-packages/` OpenSim Python bindings.
Expand Down
2 changes: 0 additions & 2 deletions OpenSim/Examples/DataTable/CMakeLists.txt
Expand Up @@ -2,8 +2,6 @@ set(EXAMPLES_TO_COMPILE example1.cpp
example2.cpp
)

include_directories(${OpenSim_SOURCE_DIR} ${OpenSim_SOURCE_DIR}/Vendors)

foreach(EXAMPLE_PROG ${EXAMPLES_TO_COMPILE})
get_filename_component(EXAMPLE_ROOT ${EXAMPLE_PROG} NAME_WE)
add_executable(${EXAMPLE_ROOT}DataTable ${EXAMPLE_PROG})
Expand Down
6 changes: 0 additions & 6 deletions OpenSim/Examples/SymbolicExpressionReporter/CMakeLists.txt
Expand Up @@ -5,12 +5,6 @@ if(BUILD_API_EXAMPLES)

set(EXAMPLE_EXPRESSION_REPORTER_PLUGIN exampleExpressionReporterPlugin)

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/OpenSim
${OpenSim_SOURCE_DIR}/Vendors
${OpenSim_SOURCE_DIR}/Vendors/lepton/include
)

add_library(${EXAMPLE_EXPRESSION_REPORTER_PLUGIN} SHARED
osimExpPluginDLL.cpp
osimExpPluginDLL.h
Expand Down
5 changes: 1 addition & 4 deletions OpenSim/Sandbox/CMakeLists.txt
Expand Up @@ -5,9 +5,6 @@ file(GLOB TO_COMPILE "future*.cpp")

# These executables are *not* tests.

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors)

set(SANDBOX_FILES
"futureOrientationInverseKinematics.osim"
"futureOrientationInverseKinematics.trc"
Expand All @@ -31,7 +28,7 @@ endforeach()


if(UNIX)
add_executable(ImuStreaming ImuStreaming.cpp)
add_executable(ImuStreaming EXCLUDE_FROM_ALL ImuStreaming.cpp)
target_link_libraries(ImuStreaming osimCommon osimSimulation osimTools)
endif()

Expand Down
3 changes: 0 additions & 3 deletions OpenSim/Sandbox/TaskSpace/CMakeLists.txt
Expand Up @@ -4,9 +4,6 @@ file(GLOB TO_COMPILE "future*.cpp")

# These executables are *not* tests.

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors)

set(SANDBOX_FILES
"futureTaskSpace.osim"
)
Expand Down
4 changes: 0 additions & 4 deletions OpenSim/Sandbox/UsefulComponents/CMakeLists.txt
Expand Up @@ -4,10 +4,6 @@ file(GLOB TO_COMPILE "future*.cpp")

# These executables are *not* tests.

include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors)


get_filename_component(_target_name ${TO_COMPILE} NAME_WE)
add_executable(${_target_name} EXCLUDE_FROM_ALL ${TO_COMPILE} ${COMPONENT_FILES})
target_link_libraries(${_target_name} osimTools)
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Simulation/Model/ExpressionBasedBushingForce.cpp
Expand Up @@ -24,7 +24,7 @@
//=============================================================================
// INCLUDES
//=============================================================================
#include <Vendors/lepton/include/Lepton.h>
#include <Lepton.h>

#include "ExpressionBasedBushingForce.h"

Expand Down
6 changes: 3 additions & 3 deletions OpenSim/Simulation/Model/ExpressionBasedCoordinateForce.cpp
Expand Up @@ -26,8 +26,8 @@
//=============================================================================
#include "ExpressionBasedCoordinateForce.h"
#include <OpenSim/Simulation/Model/Model.h>
#include <Vendors/lepton/include/lepton/Parser.h>
#include <Vendors/lepton/include/lepton/ParsedExpression.h>
#include <lepton/Parser.h>
#include <lepton/ParsedExpression.h>

using namespace OpenSim;
using namespace std;
Expand Down Expand Up @@ -168,4 +168,4 @@ Array<double> ExpressionBasedCoordinateForce::getRecordValues(const SimTK::State
OpenSim::Array<double> values(0.0, 0, 1);
values.append(calcExpressionForce(state));
return values;
}
}
2 changes: 1 addition & 1 deletion OpenSim/Simulation/Model/ExpressionBasedCoordinateForce.h
Expand Up @@ -24,7 +24,7 @@
* -------------------------------------------------------------------------- */
// INCLUDE
#include "Force.h"
#include <Vendors/lepton/include/lepton/ExpressionProgram.h>
#include <lepton/ExpressionProgram.h>

namespace OpenSim {

Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Simulation/Model/ExpressionBasedPointToPointForce.cpp
Expand Up @@ -26,8 +26,8 @@
//=============================================================================
#include "ExpressionBasedPointToPointForce.h"
#include <OpenSim/Simulation/Model/Model.h>
#include <Vendors/lepton/include/lepton/Parser.h>
#include <Vendors/lepton/include/lepton/ParsedExpression.h>
#include <lepton/Parser.h>
#include <lepton/ParsedExpression.h>

using namespace OpenSim;
using namespace std;
Expand Down
Expand Up @@ -24,7 +24,7 @@
* -------------------------------------------------------------------------- */

#include "Force.h"
#include <Vendors/lepton/include/lepton/ExpressionProgram.h>
#include <lepton/ExpressionProgram.h>

namespace SimTK {
class MobilizedBody;
Expand Down
3 changes: 0 additions & 3 deletions OpenSim/Tests/CMakeLists.txt
@@ -1,6 +1,3 @@
include_directories(${OpenSim_SOURCE_DIR}
${OpenSim_SOURCE_DIR}/Vendors)

if(BUILD_TESTING)
add_subdirectory(Components)
add_subdirectory(AddComponents)
Expand Down
2 changes: 2 additions & 0 deletions OpenSim/Utilities/simmFileWriterDLL/CMakeLists.txt
Expand Up @@ -10,4 +10,6 @@ OpenSimAddLibrary(
INCLUDES ${INCLUDES}
SOURCES ${SOURCES}
TESTDIRS ""
# Don't install the headers (see function definition).
INCLUDEDIRS TRUE
)
3 changes: 1 addition & 2 deletions Vendors/lepton/CMakeLists.txt
Expand Up @@ -4,8 +4,6 @@ if(WIN32)
add_definitions("-DLEPTON_BUILDING_SHARED_LIBRARY")
endif(WIN32)

include_directories(${OpenSim_SOURCE_DIR}/Vendors/lepton/include)

OpenSimAddLibrary(VENDORLIB LOWERINCLUDEDIRNAME
KIT Lepton
AUTHORS "Peter_Eastman"
Expand All @@ -14,6 +12,7 @@ OpenSimAddLibrary(VENDORLIB LOWERINCLUDEDIRNAME
SOURCES ${SOURCE_FILES}
TESTDIRS test
INCLUDEDIRS include include/lepton
INCLUDEINSTALLREL include/lepton
)

# TODO change header installation location to CMAKE_INSTALL_INCLUDEDIR/OpenSim/lepton
7 changes: 2 additions & 5 deletions cmake/OpenSimConfig.cmake.in
Expand Up @@ -39,11 +39,8 @@ set_and_check(@CMAKE_PROJECT_NAME@_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

# INCLUDE_DIRS
# ------------
list(APPEND @CMAKE_PROJECT_NAME@_INCLUDE_DIRS
"@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@"
# TODO change to CMAKE_INSTALL_INCLUDEDIR/OpenSim/lepton
"@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/Vendors/lepton/include"
)
set_and_check(@CMAKE_PROJECT_NAME@_INCLUDE_DIRS
"@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")


# LIBRARIES
Expand Down
39 changes: 26 additions & 13 deletions cmake/OpenSimMacros.cmake
Expand Up @@ -18,6 +18,8 @@ include(CMakeParseArguments)
# paths). See OpenSim/Simulation/CMakeLists.txt for an example. If omitted,
# all the headers specified under INCLUDES are installed into the same
# directory in the installation tree.
# INCLUDEINSTALLREL (optional): If INCLUDEDIRS is specified, remove
# "INCLUDEINSTALLREL" from the location of the installed headers.
#
# Here's an example from OpenSim/Common/CMakeLists.txt:
#
Expand All @@ -35,7 +37,7 @@ function(OpenSimAddLibrary)
# ----------------
# http://www.cmake.org/cmake/help/v2.8.9/cmake.html#module:CMakeParseArguments
set(options VENDORLIB LOWERINCLUDEDIRNAME EXCLUDEFROMPYTHON)
set(oneValueArgs KIT AUTHORS)
set(oneValueArgs KIT AUTHORS INCLUDEINSTALLREL)
set(multiValueArgs LINKLIBS INCLUDES SOURCES TESTDIRS INCLUDEDIRS)
cmake_parse_arguments(
OSIMADDLIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Expand All @@ -61,13 +63,23 @@ function(OpenSimAddLibrary)
# Add the library.
# ----------------
# These next few lines are the most important:
# Specify the directories in OpenSim that contain header files.
include_directories(${OpenSim_SOURCE_DIR})

# Create the library using the provided source and include files.
add_library(${OSIMADDLIB_LIBRARY_NAME} SHARED
${OSIMADDLIB_SOURCES} ${OSIMADDLIB_INCLUDES})

target_include_directories(${OSIMADDLIB_LIBRARY_NAME}
# Used when building this target:
PRIVATE "${OpenSim_SOURCE_DIR}"
"${OpenSim_SOURCE_DIR}/Vendors/lepton/include"
# Used by other targets in this project:
INTERFACE $<BUILD_INTERFACE:${OpenSim_SOURCE_DIR}>
$<BUILD_INTERFACE:${OpenSim_SOURCE_DIR}/Vendors/lepton/include>
# Used by client projects using an installed OpenSim:
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/OpenSim>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/OpenSim/lepton>
)

# This target links to the libraries provided as arguments to this func.
target_link_libraries(${OSIMADDLIB_LIBRARY_NAME} ${OSIMADDLIB_LINKLIBS})

Expand Down Expand Up @@ -111,12 +123,7 @@ function(OpenSimAddLibrary)

# Install headers.
# ----------------
set(_INCLUDE_PREFIX "${CMAKE_INSTALL_INCLUDEDIR}")
if(OSIMADDLIB_VENDORLIB)
set(_INCLUDE_PREFIX ${_INCLUDE_PREFIX}/Vendors)
else()
set(_INCLUDE_PREFIX ${_INCLUDE_PREFIX}/OpenSim)
endif()
set(_INCLUDE_PREFIX "${CMAKE_INSTALL_INCLUDEDIR}/OpenSim")
if(OSIMADDLIB_LOWERINCLUDEDIRNAME)
string(TOLOWER "${OSIMADDLIB_KIT}" OSIMADDLIB_LKIT)
set(_INCLUDE_LIBNAME ${OSIMADDLIB_LKIT})
Expand All @@ -126,15 +133,24 @@ function(OpenSimAddLibrary)
if(OSIMADDLIB_INCLUDEDIRS)
foreach(dir ${OSIMADDLIB_INCLUDEDIRS})
file(GLOB HEADERS ${dir}/*.h) # returns full pathnames
if(OSIMADDLIB_INCLUDEINSTALLREL)
# Remove "INCLUDEINSTALLREL" from the installed location.
file(RELATIVE_PATH subdir
"${CMAKE_CURRENT_SOURCE_DIR}${OSIMADDLIB_INCLUDEINSTALLREL}"
"${CMAKE_CURRENT_SOURCE_DIR}${dir}")
else()
set(subdir ${dir})
endif()
install(FILES ${HEADERS}
DESTINATION ${_INCLUDE_PREFIX}/${_INCLUDE_LIBNAME}/${dir})
DESTINATION ${_INCLUDE_PREFIX}/${_INCLUDE_LIBNAME}/${subdir})
endforeach(dir)
else()
install(FILES ${OSIMADDLIB_INCLUDES}
DESTINATION ${_INCLUDE_PREFIX}/${_INCLUDE_LIBNAME})
endif()

# RPATH (so that libraries find library dependencies)
# ---------------------------------------------------
if(${OPENSIM_USE_INSTALL_RPATH})
if(APPLE)
set(install_rpath "\@loader_path/")
Expand Down Expand Up @@ -219,8 +235,6 @@ function(OpenSimAddTests)

add_executable(${TEST_NAME} ${test_program}
${OSIMADDTESTS_SOURCES})
target_include_directories(${TEST_NAME}
PRIVATE ${OpenSim_SOURCE_DIR} ${OpenSim_SOURCE_DIR}/Vendors)
target_link_libraries(${TEST_NAME} ${OSIMADDTESTS_LINKLIBS})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
set_target_properties(${TEST_NAME} PROPERTIES
Expand Down Expand Up @@ -265,7 +279,6 @@ function(OpenSimAddApplication)
OSIMADDAPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Build.
include_directories(${OpenSim_SOURCE_DIR} ${OpenSim_SOURCE_DIR}/Vendors)
add_executable(${OSIMADDAPP_NAME} ${OSIMADDAPP_NAME}.cpp
${OSIMADDAPP_SOURCES})
target_link_libraries(${OSIMADDAPP_NAME} osimTools)
Expand Down
29 changes: 5 additions & 24 deletions cmake/SampleCMakeLists.txt
Expand Up @@ -4,41 +4,22 @@
# You will most likely want to copy some of these lines into your own
# CMakeLists.txt rather than use this one verbatim.

cmake_minimum_required(VERSION 2.8.6)
cmake_minimum_required(VERSION 3.2)
project(myexe)

# List your source and header files here.
set(my_source_files myexe.cpp)
set(my_header_files myexe.h)

# OpenSim uses C++11 language features.
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Using C++11 on OSX requires using libc++ instead of libstd++.
# libc++ is an implementation of the C++ standard library for OSX.
if(APPLE)
if(XCODE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# This depends on OpenSimConfig.cmake being located somewhere predictable
# on your machine. If you have installed it somewhere that CMake won't be
# able to guess, you'll need to tell find_package where to look (with the PATHS
or HINTS parameters), or # specify the installation directory in the
CMAKE_PREFIX_PATH variable.
# or HINTS parameters), or specify the installation directory in the
# CMAKE_PREFIX_PATH variable.
find_package(OpenSim REQUIRED)

include_directories(${OpenSim_INCLUDE_DIRS})

add_executable(myexe ${my_source_files} ${my_header_files})
target_link_libraries(myexe ${OpenSim_LIBRARIES})

0 comments on commit a3c133f

Please sign in to comment.