2015-03-02 2 views
0

Я хочу скомпилировать jsoncpp с -fPIC через cmake.Как скомпилировать jsoncpp с -fPIC через cmake

На веб-сайте jsoncpp объясняется, как обычно компилироваться, как показано ниже.

mkdir -p build/debug 
cd build/debug 
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../.. 
make 

Как я могу скомпилировать с -fPIC флагом на этом этапе?

--------------------------------------------- ------------Редактировать------------------------------------- ----------------------

Я предполагаю, что мне нужно поставить некоторую строку в makefile для -fPIC.

Итак, я добавляю содержимое makefile с помощью cmake.

Как я могу изменить этот файл для -fPIC?

# CMAKE generated file: DO NOT EDIT! 
# Generated by "Unix Makefiles" Generator, CMake Version 2.8 

# Default target executed when no arguments are given to make. 
default_target: all 
.PHONY : default_target 

#============================================================================= 
# Special targets provided by cmake. 

# Disable implicit rules so canonical targets will work. 
.SUFFIXES: 

# Remove some rules from gmake that .SUFFIXES does not remove. 
SUFFIXES = 

.SUFFIXES: .hpux_make_needs_suffix_list 

# Suppress display of executed commands. 
$(VERBOSE).SILENT: 

# A target that is always out of date. 
cmake_force: 
.PHONY : cmake_force 

#============================================================================= 
# Set environment variables for the build. 

# The shell in which to execute make rules. 
SHELL = /bin/sh 

# The CMake executable. 
CMAKE_COMMAND = /usr/bin/cmake 

# The command to remove a file. 
RM = /usr/bin/cmake -E remove -f 

# The program to use to edit the cache. 
CMAKE_EDIT_COMMAND = /usr/bin/cmake-gui 

# The top-level source directory on which CMake was run. 
CMAKE_SOURCE_DIR = /home/kim/jsoncpp-pre-C-11 

# The top-level build directory on which CMake was run. 
CMAKE_BINARY_DIR = /home/kim/jsoncpp-pre-C-11/build/debug 

#============================================================================= 
# Targets provided globally by CMake. 

# Special rule for the target edit_cache 
edit_cache: 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." 
    /usr/bin/cmake-gui -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 
.PHONY : edit_cache 

# Special rule for the target edit_cache 
edit_cache/fast: edit_cache 
.PHONY : edit_cache/fast 

# Special rule for the target install 
install: preinstall 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." 
    /usr/bin/cmake -P cmake_install.cmake 
.PHONY : install 

# Special rule for the target install 
install/fast: preinstall/fast 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." 
    /usr/bin/cmake -P cmake_install.cmake 
.PHONY : install/fast 

# Special rule for the target install/local 
install/local: preinstall 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." 
    /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake 
.PHONY : install/local 

# Special rule for the target install/local 
install/local/fast: install/local 
.PHONY : install/local/fast 

# Special rule for the target install/strip 
install/strip: preinstall 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." 
    /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake 
.PHONY : install/strip 

# Special rule for the target install/strip 
install/strip/fast: install/strip 
.PHONY : install/strip/fast 

# Special rule for the target list_install_components 
list_install_components: 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" 
.PHONY : list_install_components 

# Special rule for the target list_install_components 
list_install_components/fast: list_install_components 
.PHONY : list_install_components/fast 

# Special rule for the target rebuild_cache 
rebuild_cache: 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." 
    /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 
.PHONY : rebuild_cache 

# Special rule for the target rebuild_cache 
rebuild_cache/fast: rebuild_cache 
.PHONY : rebuild_cache/fast 

# Special rule for the target test 
test: 
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..." 
    /usr/bin/ctest --force-new-ctest-process $(ARGS) 
.PHONY : test 

# Special rule for the target test 
test/fast: test 
.PHONY : test/fast 

# The main all target 
all: cmake_check_build_system 
    $(CMAKE_COMMAND) -E cmake_progress_start /home/kim/jsoncpp-pre-C-11/build/debug/CMakeFiles /home/kim/jsoncpp-pre-C-11/build/debug/CMakeFiles/progress.marks 
    $(MAKE) -f CMakeFiles/Makefile2 all 
    $(CMAKE_COMMAND) -E cmake_progress_start /home/kim/jsoncpp-pre-C-11/build/debug/CMakeFiles 0 
.PHONY : all 

# The main clean target 
clean: 
    $(MAKE) -f CMakeFiles/Makefile2 clean 
.PHONY : clean 

# The main clean target 
clean/fast: clean 
.PHONY : clean/fast 

# Prepare targets for installation. 
preinstall: all 
    $(MAKE) -f CMakeFiles/Makefile2 preinstall 
.PHONY : preinstall 

# Prepare targets for installation. 
preinstall/fast: 
    $(MAKE) -f CMakeFiles/Makefile2 preinstall 
.PHONY : preinstall/fast 

# clear depends 
depend: 
    $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 
.PHONY : depend 

#============================================================================= 
# Target rules for targets named jsoncpp_lib 

# Build rule for target. 
jsoncpp_lib: cmake_check_build_system 
    $(MAKE) -f CMakeFiles/Makefile2 jsoncpp_lib 
.PHONY : jsoncpp_lib 

# fast build rule for target. 
jsoncpp_lib/fast: 
    $(MAKE) -f src/lib_json/CMakeFiles/jsoncpp_lib.dir/build.make src/lib_json/CMakeFiles/jsoncpp_lib.dir/build 
.PHONY : jsoncpp_lib/fast 

#============================================================================= 
# Target rules for targets named jsoncpp_check 

# Build rule for target. 
jsoncpp_check: cmake_check_build_system 
    $(MAKE) -f CMakeFiles/Makefile2 jsoncpp_check 
.PHONY : jsoncpp_check 

# fast build rule for target. 
jsoncpp_check/fast: 
    $(MAKE) -f src/jsontestrunner/CMakeFiles/jsoncpp_check.dir/build.make src/jsontestrunner/CMakeFiles/jsoncpp_check.dir/build 
.PHONY : jsoncpp_check/fast 

#============================================================================= 
# Target rules for targets named jsoncpp_readerwriter_tests 

# Build rule for target. 
jsoncpp_readerwriter_tests: cmake_check_build_system 
    $(MAKE) -f CMakeFiles/Makefile2 jsoncpp_readerwriter_tests 
.PHONY : jsoncpp_readerwriter_tests 

# fast build rule for target. 
jsoncpp_readerwriter_tests/fast: 
    $(MAKE) -f src/jsontestrunner/CMakeFiles/jsoncpp_readerwriter_tests.dir/build.make src/jsontestrunner/CMakeFiles/jsoncpp_readerwriter_tests.dir/build 
.PHONY : jsoncpp_readerwriter_tests/fast 

#============================================================================= 
# Target rules for targets named jsontestrunner_exe 

# Build rule for target. 
jsontestrunner_exe: cmake_check_build_system 
    $(MAKE) -f CMakeFiles/Makefile2 jsontestrunner_exe 
.PHONY : jsontestrunner_exe 

# fast build rule for target. 
jsontestrunner_exe/fast: 
    $(MAKE) -f src/jsontestrunner/CMakeFiles/jsontestrunner_exe.dir/build.make src/jsontestrunner/CMakeFiles/jsontestrunner_exe.dir/build 
.PHONY : jsontestrunner_exe/fast 

#============================================================================= 
# Target rules for targets named jsoncpp_test 

# Build rule for target. 
jsoncpp_test: cmake_check_build_system 
    $(MAKE) -f CMakeFiles/Makefile2 jsoncpp_test 
.PHONY : jsoncpp_test 

# fast build rule for target. 
jsoncpp_test/fast: 
    $(MAKE) -f src/test_lib_json/CMakeFiles/jsoncpp_test.dir/build.make src/test_lib_json/CMakeFiles/jsoncpp_test.dir/build 
.PHONY : jsoncpp_test/fast 

# Help Target 
help: 
    @echo "The following are some of the valid targets for this Makefile:" 
    @echo "... all (the default if no target is provided)" 
    @echo "... clean" 
    @echo "... depend" 
    @echo "... edit_cache" 
    @echo "... install" 
    @echo "... install/local" 
    @echo "... install/strip" 
    @echo "... list_install_components" 
    @echo "... rebuild_cache" 
    @echo "... test" 
    @echo "... jsoncpp_lib" 
    @echo "... jsoncpp_check" 
    @echo "... jsoncpp_readerwriter_tests" 
    @echo "... jsontestrunner_exe" 
    @echo "... jsoncpp_test" 
.PHONY : help 



#============================================================================= 
# Special targets to cleanup operation of make. 

# Special rule to run CMake to check the build system integrity. 
# No rule that depends on this can have commands that come from listfiles 
# because they might be regenerated. 
cmake_check_build_system: 
    $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 
.PHONY : cmake_check_build_system 
+0

Возможный дубликат http://stackoverflow.com/questions/18604301 – quimnuss

ответ

1

Вы должны изменить CMAKE_CXX_FLAGS и переменную CMAKE_CXX_FLAGS. Вы можете сделать это через ccmake или cmake-gui (вы должны переключить продвинутый) или вы можете предоставить его, как вы делали:

cmake -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../.. 

Не беспокоить изменяя Makefile, так как она будет перезаписана следующая время, которое вы запустили cmake.

В CMake 2.8.9 вы можете установить POSITION_INDEPENDENT_CODE объект на цель, чтобы сделать все следующие цели позициями независимыми. Или вы можете установить глобальную переменную внутри CMakeLists.txt

set(CMAKE_POSITION_INDEPENDENT_CODE ON) 

или

cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. 
Смежные вопросы